problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p00439
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <deque> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, n) for (int i = 1; i <= n; i++) int ini[10001]; int main() { while (1) { int n, m; scanf("%d%d", &n, &m); if (n == 0) break; rep(i, n) { scanf("%d", &ini[i]); } int sum = 0; rep(i, m) { sum += ini[i]; } int maxi = sum; for (int i = m; i < n; i++) { sum -= ini[i - m]; sum += ini[i]; maxi = max(maxi, sum); } printf("%d\n", maxi); } }
#include <algorithm> #include <cstdio> #include <deque> #include <queue> #include <sstream> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, n) for (int i = 1; i <= n; i++) int ini[100001]; int main() { while (1) { int n, m; scanf("%d%d", &n, &m); if (n == 0) break; rep(i, n) { scanf("%d", &ini[i]); } int sum = 0; rep(i, m) { sum += ini[i]; } int maxi = sum; for (int i = m; i < n; i++) { sum -= ini[i - m]; sum += ini[i]; maxi = max(maxi, sum); } printf("%d\n", maxi); } }
replace
13
14
13
14
0
p00439
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { for (;;) { int a, b, c[100000] = {0}, d = 0, e = 0, max = 0; cin >> a >> b; if (a == 0 && b == 0) break; for (int A = 0; A < a; A++) { cin >> c[A]; if (A >= b) { for (int B = 0; B < b; B++) { d = d + c[A + e]; e--; } if (max < d) max = d; d = 0; } } cout << max << endl; } return 0; }
#include <iostream> using namespace std; int main(void) { for (;;) { int a, b, c[100000] = {0}, d = 0, e = 0, max = 0; cin >> a >> b; if (a == 0 && b == 0) break; for (int A = 0; A < a; A++) { cin >> c[A]; if (A >= b) { for (int B = 0; B < b; B++) { d = d + c[A + e]; e--; } if (max < d) max = d; d = 0; e = 0; } } cout << max << endl; } return 0; }
insert
18
18
18
19
0
p00439
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> using namespace std; int main() { while (true) { int n, k; cin >> n >> k; int sum = 0; int ans = 0; queue<int> q; for (int i = 0; i < n; ++i) { int num; scanf("%d", &num); sum += num; if (i == k - 1) ans = sum; if (i >= k) { sum -= q.front(); q.pop(); ans = max(ans, sum); } q.push(num); } cout << ans << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> using namespace std; int main() { while (true) { int n, k; cin >> n >> k; if (!n && !k) break; int sum = 0; int ans = 0; queue<int> q; for (int i = 0; i < n; ++i) { int num; scanf("%d", &num); sum += num; if (i == k - 1) ans = sum; if (i >= k) { sum -= q.front(); q.pop(); ans = max(ans, sum); } q.push(num); } cout << ans << endl; } return 0; }
insert
11
11
11
14
TLE
p00439
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { int n, m, a; while (cin >> n >> m, n | m) { int d[10001] = {}; cin >> d[0]; for (int i = 1; i < n; i++) { cin >> a; d[i] += d[i - 1] + a; } int MAX = 0; for (int i = 0; i < n - m; i++) { if (d[i + m] - d[i] > MAX) MAX = d[i + m] - d[i]; } cout << MAX << endl; } return 0; }
#include <iostream> using namespace std; int main(void) { int n, m, a; while (cin >> n >> m, n | m) { int d[100001] = {}; cin >> d[0]; for (int i = 1; i < n; i++) { cin >> a; d[i] += d[i - 1] + a; } int MAX = 0; for (int i = 0; i < n - m; i++) { if (d[i + m] - d[i] > MAX) MAX = d[i + m] - d[i]; } cout << MAX << endl; } return 0; }
replace
7
8
7
8
0
p00439
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define PB push_back #define INF (1 << 29) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CLR(a) memset(a, 0, sizeof(a)) const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0}; typedef long long int ll; using namespace std; int main() { while (true) { int n, k; cin >> n >> k; if (n == 0 && k == 0) break; ll a[10001]; REP(i, n) { cin >> a[i]; } REP(i, n - 1) { a[i + 1] += a[i]; } ll ans = -1000000000000000; FOR(i, k, n) { ans = max(ans, a[i] - a[i - k]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define PB push_back #define INF (1 << 29) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CLR(a) memset(a, 0, sizeof(a)) const int dx[] = {-1, 0, 0, 1}, dy[] = {0, 1, -1, 0}; typedef long long int ll; using namespace std; int main() { while (true) { int n, k; cin >> n >> k; if (n == 0 && k == 0) break; ll a[100001]; REP(i, n) { cin >> a[i]; } REP(i, n - 1) { a[i + 1] += a[i]; } ll ans = -1000000000000000; FOR(i, k, n) { ans = max(ans, a[i] - a[i - k]); } cout << ans << endl; } return 0; }
replace
23
24
23
24
0
p00439
C++
Runtime Error
#include <cstdio> using namespace std; int main() { int n, k; int s = 0; int a[10000] = {0}; for (;;) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int x = 0; for (int i = 0; i < k; i++) { x += a[i]; } s = x; for (int i = 0; i < (n - k); i++) { x -= a[i]; x += a[i + k]; if (s < x) s = x; } printf("%d\n", s); } return 0; }
#include <cstdio> using namespace std; int main() { int n, k; int s = 0; int a[100000] = {0}; for (;;) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } int x = 0; for (int i = 0; i < k; i++) { x += a[i]; } s = x; for (int i = 0; i < (n - k); i++) { x -= a[i]; x += a[i + k]; if (s < x) s = x; } printf("%d\n", s); } return 0; }
replace
5
6
5
6
0
p00439
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> using namespace std; typedef long long int ll; int main() { int n, k; while (1) { scanf("%d %d", &n, &k); if (n == 0) return 0; int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); ; ll bgs = 0; for (int i = 0; i <= n - k; i++) { ll temp = 0; for (int j = 0; j < k; j++) temp += a[i + j]; bgs = max(bgs, temp); } printf("%lld\n", bgs); } }
#include <algorithm> #include <cstdio> using namespace std; typedef long long int ll; int main() { int n, k; while (1) { scanf("%d %d", &n, &k); if (n == 0) return 0; int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); ll bgs = 0, temp = 0; for (int i = 0; i < k; i++) temp += a[i]; bgs = temp; for (int i = 1; i <= n - k; i++) { temp = temp - a[i - 1] + a[i + k - 1]; bgs = max(bgs, temp); } printf("%lld\n", bgs); } }
replace
13
19
13
19
TLE
p00440
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } /* <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0517> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ ll n, k; ll solve() { ll res = 0; bool hakusi = false; vector<ll> card; for (int i = 0; i < k; i++) { ll c; cin >> c; if (c == 0) hakusi = true; else card.push_back(c); } sort(card.begin(), card.end()); vector<pll> sec; ll l = card[0], r = card[0]; for (int i = 1; i < card.size(); i++) { if (card[i] == card[i - 1] + 1) { r = card[i]; } else { sec.push_back({l, r}); l = r = card[i]; } } sec.push_back({l, r}); cerr << sec << endl; for (int i = 0; i < sec.size(); i++) { res = max(res, sec[i].second - sec[i].first + 1); if (sec[i].first != 1 || sec[i].second != n) { res = max(res, sec[i].second - sec[i].first + 1 + hakusi); } } if (hakusi) { for (int i = 1; i < sec.size(); i++) { if (sec[i - 1].second + 2 == sec[i].first) { res = max(res, sec[i].second - sec[i - 1].first + 1); } } } return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); while (cin >> n >> k, n) { cout << solve() << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &o) { out << "(" << o.first << "," << o.second << ")"; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> V) { for (int i = 0; i < V.size(); i++) { out << V[i]; if (i != V.size() - 1) out << " "; } return out; } template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> Mat) { for (int i = 0; i < Mat.size(); i++) { if (i != 0) out << endl; out << Mat[i]; } return out; } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> mp) { out << "{ "; for (auto it = mp.begin(); it != mp.end(); it++) { out << it->first << ":" << it->second; if (mp.size() - 1 != distance(mp.begin(), it)) out << ", "; } out << " }"; return out; } /* <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0517> 問題文============================================================ ================================================================= 解説============================================================= ================================================================ */ ll n, k; ll solve() { ll res = 0; bool hakusi = false; vector<ll> card; for (int i = 0; i < k; i++) { ll c; cin >> c; if (c == 0) hakusi = true; else card.push_back(c); } sort(card.begin(), card.end()); vector<pll> sec; ll l = card[0], r = card[0]; for (int i = 1; i < card.size(); i++) { if (card[i] == card[i - 1] + 1) { r = card[i]; } else { sec.push_back({l, r}); l = r = card[i]; } } sec.push_back({l, r}); for (int i = 0; i < sec.size(); i++) { res = max(res, sec[i].second - sec[i].first + 1); if (sec[i].first != 1 || sec[i].second != n) { res = max(res, sec[i].second - sec[i].first + 1 + hakusi); } } if (hakusi) { for (int i = 1; i < sec.size(); i++) { if (sec[i - 1].second + 2 == sec[i].first) { res = max(res, sec[i].second - sec[i - 1].first + 1); } } } return res; } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); while (cin >> n >> k, n) { cout << solve() << endl; } return 0; }
delete
76
77
76
76
0
(1,2) (4,4) (6,7) (2,2) (4,4) (6,7)
p00440
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #define _3_ true using namespace std; int main() { int n, k, index, ini; int in[100005]; bool ZeroE; while (_3_) { scanf("%d %d", &n, &k); if (!(n | k)) break; ZeroE = false; index = 0; for (int i = 0; i < k; i++) { scanf("%d", &ini); if (ini == 0) ZeroE = true; else { in[index] = ini; index++; } } sort(in, in + index); int ans = 0; int count = 1; bool used = false; for (int i = 1; i < index; i++) { // cout << "i = " << i << ", cout = " << count << ", in[i] = " << in[i]<< // endl; if (in[i] == in[i - 1] + 1) count++; else { if (ZeroE && !used && in[i] == in[i - 1] + 2) { count += 2; used = true; } else if (ZeroE && used && in[i] == in[i - 1] + 2) { ans = max(ans, count); count = 3; } else { ans = max(ans, count); count = 1; used = false; } } if (in[i] == in[i - 1] + 1 && i == index - 1 && !used && ZeroE) count++; } if (index == 1 && ZeroE) count = 2; ans = max(ans, count); cout << ans << endl; } return 434; }
#include <algorithm> #include <cstdio> #include <iostream> #define _3_ true using namespace std; int main() { int n, k, index, ini; int in[100005]; bool ZeroE; while (_3_) { scanf("%d %d", &n, &k); if (!(n | k)) break; ZeroE = false; index = 0; for (int i = 0; i < k; i++) { scanf("%d", &ini); if (ini == 0) ZeroE = true; else { in[index] = ini; index++; } } sort(in, in + index); int ans = 0; int count = 1; bool used = false; for (int i = 1; i < index; i++) { // cout << "i = " << i << ", cout = " << count << ", in[i] = " << in[i]<< // endl; if (in[i] == in[i - 1] + 1) count++; else { if (ZeroE && !used && in[i] == in[i - 1] + 2) { count += 2; used = true; } else if (ZeroE && used && in[i] == in[i - 1] + 2) { ans = max(ans, count); count = 3; } else { ans = max(ans, count); count = 1; used = false; } } if (in[i] == in[i - 1] + 1 && i == index - 1 && !used && ZeroE) count++; } if (index == 1 && ZeroE) count = 2; ans = max(ans, count); cout << ans << endl; } return 0; }
replace
61
62
61
62
178
p00440
C++
Runtime Error
/* {{{ Shinobu kawaii */ /* ______ __ _ __ .' ____ \ [ | (_) [ | | (___ \_| | |--. __ _ .--. .--. | |.--. __ _ _.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | | | \____) | | | | | | | | | | || \__. || \__/ | | \_/ |, \______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/ */ // clang-format off /* }}} */ #include <bits/stdc++.h> using namespace std; // #define int long long struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast; /* cpp template {{{ */ /* short */ #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define ALL(v) (v).begin(), (v).end() #define X real() #define Y imag() /* REPmacro */ #define REPS(i, a, n) for (auto i = (a); i < (n); ++i) #define REP(i, n) REPS(i, 0, n) #define RREP(i, n) REPS(i, 1, n + 1) #define DEPS(i, a, n) for (auto i = (a); i >= n; --i) #define DEP(i, n) DEPS(i, n, 0) /* debug */ #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; /* alias */ using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; using D = double; using P = complex<D>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; /* const */ const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; const D EPS = 1e-9; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; /* func */ inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;} inline int in() {int x; cin >> x; return x;} inline ll IN() {ll x; cin >> x; return x;} template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;} template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;} template <typename T> inline void print(const T& x) {cout << x << '\n';} template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << '\n';} template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) { REP(i, v.size()) print(v[i]); } template <typename T> inline void print(const vector<T>& v, string s = " ") { REP(i, v.size()) { if (i != 0) cout << s; cout << v[i]; } cout << '\n'; } // clang-format on /* }}} */ signed main() { int n, k; while (cin >> n >> k, n || k) { int ans = -INF; bool white = false; vi v, shinobu(n + 5, 0); REP(i, k) { int t = in(); if (t == 0) { white = true; continue; } v.eb(t); } sort(ALL(v)); shinobu[v[0]] = 1; RREP(i, v.size() - 1) { if (v[i] - v[i - 1] == 1) { shinobu[v[i]] = shinobu[v[i - 1]] + 1; } else { shinobu[v[i]] = 1; } chmax(ans, shinobu[v[i]]); } debug(ans); if (white) { RREP(i, n + 1) { if (shinobu[i]) continue; int t = 0; if (shinobu[i - 1]) { chmax(ans, shinobu[i - 1] + 1); t = 1; } if (shinobu[i + 1]) { int idx = i - 1; ++i; for (; shinobu[i] > 0; ++i) ; chmax(ans, shinobu[idx] + shinobu[i - 1] + t); --i; } } } print(ans); } return 0; }
/* {{{ Shinobu kawaii */ /* ______ __ _ __ .' ____ \ [ | (_) [ | | (___ \_| | |--. __ _ .--. .--. | |.--. __ _ _.____`. | .-. | [ | [ `.-. |/ .'`\ \| '/'`\ \[ | | | | \____) | | | | | | | | | | || \__. || \__/ | | \_/ |, \______.'[___]|__][___][___||__]'.__.'[__;.__.' '.__.'_/ */ // clang-format off /* }}} */ #include <bits/stdc++.h> using namespace std; // #define int long long struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast; /* cpp template {{{ */ /* short */ #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define ALL(v) (v).begin(), (v).end() #define X real() #define Y imag() /* REPmacro */ #define REPS(i, a, n) for (auto i = (a); i < (n); ++i) #define REP(i, n) REPS(i, 0, n) #define RREP(i, n) REPS(i, 1, n + 1) #define DEPS(i, a, n) for (auto i = (a); i >= n; --i) #define DEP(i, n) DEPS(i, n, 0) /* debug */ #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; /* alias */ using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; using D = double; using P = complex<D>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; /* const */ const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; const D EPS = 1e-9; const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; /* func */ inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;} inline int in() {int x; cin >> x; return x;} inline ll IN() {ll x; cin >> x; return x;} template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;} template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;} template <typename T> inline void print(const T& x) {cout << x << '\n';} template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << '\n';} template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) { REP(i, v.size()) print(v[i]); } template <typename T> inline void print(const vector<T>& v, string s = " ") { REP(i, v.size()) { if (i != 0) cout << s; cout << v[i]; } cout << '\n'; } // clang-format on /* }}} */ signed main() { int n, k; while (cin >> n >> k, n || k) { int ans = -INF; bool white = false; vi v, shinobu(n + 5, 0); REP(i, k) { int t = in(); if (t == 0) { white = true; continue; } v.eb(t); } sort(ALL(v)); shinobu[v[0]] = 1; RREP(i, v.size() - 1) { if (v[i] - v[i - 1] == 1) { shinobu[v[i]] = shinobu[v[i - 1]] + 1; } else { shinobu[v[i]] = 1; } chmax(ans, shinobu[v[i]]); } if (white) { RREP(i, n + 1) { if (shinobu[i]) continue; int t = 0; if (shinobu[i - 1]) { chmax(ans, shinobu[i - 1] + 1); t = 1; } if (shinobu[i + 1]) { int idx = i - 1; ++i; for (; shinobu[i] > 0; ++i) ; chmax(ans, shinobu[idx] + shinobu[i - 1] + t); --i; } } } print(ans); } return 0; }
delete
105
106
105
105
0
2 (L:106) 2 (L:106)
p00440
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (!n && !m) break; bool card[10001] = {false}; for (int i = 0; i < m; i++) { int a; cin >> a; card[a] = true; } int ma = 1; for (int i = 1; i <= n; i++) { int sum = 0; bool flag = card[0]; int j = i; while (j <= n) { if (card[j] == true || flag) { sum++; if (card[j] == false && flag == true) flag = false; j++; } else break; } ma = max(ma, sum); } cout << ma << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (!n && !m) break; bool card[100001] = {false}; for (int i = 0; i < m; i++) { int a; cin >> a; card[a] = true; } int ma = 1; for (int i = 1; i <= n; i++) { int sum = 0; bool flag = card[0]; int j = i; while (j <= n) { if (card[j] == true || flag) { sum++; if (card[j] == false && flag == true) flag = false; j++; } else break; } ma = max(ma, sum); } cout << ma << endl; } return 0; }
replace
8
9
8
9
0
p00440
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; while (1) { cin >> n >> k; int data[1003]; for (int i = 0; i < n + 3; i++) { data[i] = 0; } int all = 0, ans = 0; if (n == 0 && k == 0) break; for (int i = 0; i < k; i++) { int card; cin >> card; if (card == 0) all++; else data[card] = 1; } for (int i = 1; i <= n; i++) { int tmp = all; int cnt = 0; for (int j = i; j <= n; j++) { if (data[j] == 1) cnt++; else if (tmp != 0) { cnt++; tmp--; } else break; } ans = max(ans, cnt); } cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; while (1) { cin >> n >> k; int data[100300]; for (int i = 0; i < n + 3; i++) { data[i] = 0; } int all = 0, ans = 0; if (n == 0 && k == 0) break; for (int i = 0; i < k; i++) { int card; cin >> card; if (card == 0) all++; else data[card] = 1; } for (int i = 1; i <= n; i++) { int tmp = all; int cnt = 0; for (int j = i; j <= n; j++) { if (data[j] == 1) cnt++; else if (tmp != 0) { cnt++; tmp--; } else break; } ans = max(ans, cnt); } cout << ans << endl; } }
replace
8
9
8
9
0
p00440
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int n = 0, k = 0, a[200000] = {}, sam, b[100000] = {}, roop = 0, save[100000] = {0}, ans[100000] = {}, w = 0; int main(void) { while (1) { int n = 0, k = 0, a[100000] = {}, sam, b[1000] = {}, roop = 0, save[1000] = {0}, ans[1000] = {}, w = 0; cin >> n >> k; if (n == 0 || k == 0) return 0; for (int i = 0; i < k; i++) { cin >> a[i]; } sort(a, a + k); for (int i = 0; i < k; i++) { if (a[i + 1] - a[i] == 1) { sam++; } else if (a[i + 1] - a[i] != 1) { b[roop] = sam + 1; if (a[0] == 0) { if (a[i + 1] - a[i] == 2) { save[w] = roop; w++; } } sam = 0; roop++; } } for (int i = 0; i <= roop; i++) { if (save[i] != 0) { ans[i] = b[save[i]]; ans[i] += b[save[i] + 1] + 1; } } sort(b, b + roop + 1); sort(ans, ans + roop + 1); if (ans[roop] > b[roop]) cout << ans[roop] << endl; if (ans[roop] <= b[roop]) { if (a[0] == 0) { cout << b[roop] + 1 << endl; } else { cout << b[roop] << endl; } } } return 0; }
#include <algorithm> #include <iostream> using namespace std; int n = 0, k = 0, a[200000] = {}, sam, b[100000] = {}, roop = 0, save[100000] = {0}, ans[100000] = {}, w = 0; int main(void) { while (1) { // int n=0, k=0, a[100000] = {}, sam, b[1000] = {}, roop = 0, save[1000] = // {0}, ans[1000] = {}, w = 0; cin >> n >> k; if (n == 0 || k == 0) return 0; for (int i = 0; i < k; i++) { cin >> a[i]; } sort(a, a + k); for (int i = 0; i < k; i++) { if (a[i + 1] - a[i] == 1) { sam++; } else if (a[i + 1] - a[i] != 1) { b[roop] = sam + 1; if (a[0] == 0) { if (a[i + 1] - a[i] == 2) { save[w] = roop; w++; } } sam = 0; roop++; } } for (int i = 0; i <= roop; i++) { if (save[i] != 0) { ans[i] = b[save[i]]; ans[i] += b[save[i] + 1] + 1; } } sort(b, b + roop + 1); sort(ans, ans + roop + 1); if (ans[roop] > b[roop]) cout << ans[roop] << endl; if (ans[roop] <= b[roop]) { if (a[0] == 0) { cout << b[roop] + 1 << endl; } else { cout << b[roop] << endl; } } } return 0; }
replace
7
9
7
9
0
p00440
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <math.h> using namespace std; int card[100000]; bool shiro = false; int main() { while (1) { int n, m; cin >> n >> m; if (n == 0 and m == 0) { break; } shiro = false; for (int i = 0; i < 100000; i++) { card[i] = 0; } for (int i = 0; i < n; i++) { int u; cin >> u; if (u != 0) { card[u - 1]++; } else { shiro = true; } } if (shiro == false) { int ans = 0; int poyo = 0; for (int i = 0; i < n; i++) { if (card[i] == 1) { poyo++; } else { ans = max(ans, poyo); poyo = 0; } } cout << ans << endl; } else { int ans = 0; int poyo = 0; int piyo = 0; for (int i = 0; i < n; i++) { if (card[i] == 1) { poyo++; } else { ans = max(ans, poyo + piyo + 1); piyo = poyo; poyo = 0; } } cout << ans << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <math.h> using namespace std; int card[100000]; bool shiro = false; int main() { while (1) { int n, m; cin >> n >> m; if (n == 0 and m == 0) { break; } shiro = false; for (int i = 0; i < 100000; i++) { card[i] = 0; } for (int i = 0; i < m; i++) { int u; cin >> u; if (u != 0) { card[u - 1]++; } else { shiro = true; } } if (shiro == false) { int ans = 0; int poyo = 0; for (int i = 0; i < n; i++) { if (card[i] == 1) { poyo++; } else { ans = max(ans, poyo); poyo = 0; } } cout << ans << endl; } else { int ans = 0; int poyo = 0; int piyo = 0; for (int i = 0; i < n; i++) { if (card[i] == 1) { poyo++; } else { ans = max(ans, poyo + piyo + 1); piyo = poyo; poyo = 0; } } cout << ans << endl; } } return 0; }
replace
17
18
17
18
TLE
p00440
C++
Time Limit Exceeded
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; int main() { while (1) { int N, K; cin >> N >> K; vector<int> oks(N + 1); bool flag = false; for (int i = 0; i < K; ++i) { int a; cin >> a; oks[a] = true; if (!a) flag = true; } int a = 0; int b = 0; int ans = 0; for (int i = 1; i <= N; ++i) { if (oks[i]) { a++; b++; ans = max(ans, a); if (flag) ans = max(ans, b); } else { b = a + 1; a = 0; } } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; int main() { while (1) { int N, K; cin >> N >> K; if (!N) break; vector<int> oks(N + 1); bool flag = false; for (int i = 0; i < K; ++i) { int a; cin >> a; oks[a] = true; if (!a) flag = true; } int a = 0; int b = 0; int ans = 0; for (int i = 1; i <= N; ++i) { if (oks[i]) { a++; b++; ans = max(ans, a); if (flag) ans = max(ans, b); } else { b = a + 1; a = 0; } } cout << ans << endl; } return 0; }
insert
13
13
13
15
TLE
p00440
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; while (cin >> n >> k, n || k) { int C[10002] = {0}; int dp[10002] = {0}; for (int i = 0; i < k; i++) { int j; cin >> j; C[j] = 1; } if (C[1] == 1) { dp[1] = 1; } for (int i = 2; i <= n; i++) { if (C[i] == 1) { if (dp[i - 1] > 0) { dp[i] = dp[i - 1] + 1; } else { dp[i] = 1; } } } for (int i = n; i > 0; i--) { if (C[i] == 1) { if (dp[i + 1] > 0) { dp[i] = dp[i + 1]; } } } int ans = 0; if (C[0] == 1) { for (int i = 2; i <= n; i++) { ans = max(ans, dp[i]); if (C[i] == 0) { ans = max(ans, dp[i - 1] + dp[i + 1] + 1); } } } else { for (int i = 1; i <= n; i++) { ans = max(ans, dp[i]); } } cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; while (cin >> n >> k, n || k) { int C[100002] = {0}; int dp[100002] = {0}; for (int i = 0; i < k; i++) { int j; cin >> j; C[j] = 1; } if (C[1] == 1) { dp[1] = 1; } for (int i = 2; i <= n; i++) { if (C[i] == 1) { if (dp[i - 1] > 0) { dp[i] = dp[i - 1] + 1; } else { dp[i] = 1; } } } for (int i = n; i > 0; i--) { if (C[i] == 1) { if (dp[i + 1] > 0) { dp[i] = dp[i + 1]; } } } int ans = 0; if (C[0] == 1) { for (int i = 2; i <= n; i++) { ans = max(ans, dp[i]); if (C[i] == 0) { ans = max(ans, dp[i - 1] + dp[i + 1] + 1); } } } else { for (int i = 1; i <= n; i++) { ans = max(ans, dp[i]); } } cout << ans << endl; } }
replace
8
10
8
10
0
p00440
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> using namespace std; int n, k; bool used[100001] = {}; int num[100001]; int main() { while (1) { fill(used, used + 100001, false); scanf("%d %d", &n, &k); for (int i = 0; i < k; i++) { scanf("%d", &num[i]); used[num[i]] = true; } sort(num, num + k); int s = 0, e = 0, sum = 0, res = 0; if (used[0]) { for (;;) { while (e <= n && sum <= 1) { if (!used[e]) { sum++; e++; } else { e++; } } if (sum <= 1) { res = max(res, e - s); break; } res = max(res, e - s); if (!used[s]) { sum--; } s++; } } else { e = 1; s = 1; for (;;) { while (e <= n && sum <= 0) { if (!used[e]) { sum++; e++; } else { e++; } } if (sum <= 0) { break; } res = max(res, e - s); if (!used[s]) { sum--; } s++; } } printf("%d\n", res - 1); } }
#include <algorithm> #include <cstdio> using namespace std; int n, k; bool used[100001] = {}; int num[100001]; int main() { while (1) { fill(used, used + 100001, false); scanf("%d %d", &n, &k); if (!n) break; for (int i = 0; i < k; i++) { scanf("%d", &num[i]); used[num[i]] = true; } sort(num, num + k); int s = 0, e = 0, sum = 0, res = 0; if (used[0]) { for (;;) { while (e <= n && sum <= 1) { if (!used[e]) { sum++; e++; } else { e++; } } if (sum <= 1) { res = max(res, e - s); break; } res = max(res, e - s); if (!used[s]) { sum--; } s++; } } else { e = 1; s = 1; for (;;) { while (e <= n && sum <= 0) { if (!used[e]) { sum++; e++; } else { e++; } } if (sum <= 0) { break; } res = max(res, e - s); if (!used[s]) { sum--; } s++; } } printf("%d\n", res - 1); } }
insert
10
10
10
12
TLE
p00441
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; int exist[5001][5001]; inline bool check(int x, int y) { if (x < 0 || y < 0 || x > 5000 || y > 5000) return false; return exist[x][y]; } int main() { int n; while (cin >> n, n) { memset(exist, 0, sizeof(exist)); vector<int> x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; exist[x[i]][y[i]] = 1; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int dx = x[i] - x[j], dy = y[i] - y[j]; if (check(x[i] + dy, y[i] - dx) && check(x[j] + dy, y[j] - dx)) { ans = max(ans, dx * dx + dy * dy); } if (check(x[i] - dy, y[i] + dx) && check(x[j] - dy, y[j] + dx)) { ans = max(ans, dx * dx + dy * dy); } } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; bool exist[5001][5001]; inline bool check(int x, int y) { if (x < 0 || y < 0 || x > 5000 || y > 5000) return false; return exist[x][y]; } int main() { int n; while (cin >> n, n) { memset(exist, 0, sizeof(exist)); vector<int> x(n), y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; exist[x[i]][y[i]] = 1; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int dx = x[i] - x[j], dy = y[i] - y[j]; if (check(x[i] + dy, y[i] - dx) && check(x[j] + dy, y[j] - dx)) { ans = max(ans, dx * dx + dy * dy); } if (check(x[i] - dy, y[i] + dx) && check(x[j] - dy, y[j] + dx)) { ans = max(ans, dx * dx + dy * dy); } } } cout << ans << endl; } }
replace
2
3
2
3
MLE
p00441
C++
Runtime Error
// Bokan ga bokka--nn!! // Daily Lunch Special Tanoshii !! // これは、頭が悪く競プロが世界で一番できないHIR180が // IOI2014日本代表になるまでのN日間の記録である。 #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; typedef long long ll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 #define f first #define s second #define rep(i, x) for (int i = 0; i < x; i++) P za[3005]; int main() { srand((unsigned int)time(NULL)); while (1) { int n; scanf("%d", &n); if (!n) return 0; static bool in[5005][5005] = {}; for (int i = 1; i <= n; i++) { scanf("%d %d", &za[i].f, &za[i].s); in[za[i].f][za[i].s] = true; } int ret = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int xa = za[i].f; int xb = za[j].f; int ya = za[i].s; int yb = za[j].s; if (xa + xb - yb + ya < 0 || ya + yb + xb - xa < 0 || xa + xb + yb - ya < 0 || ya + yb - xb + xa < 0) continue; if (in[(xa + xb - yb + ya) / 2][(ya + yb + xb - xa) / 2] && in[(xa + xb + yb - ya) / 2][(ya + yb - xb + xa) / 2]) ret = max(ret, (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); } } printf("%d\n", ret / 2); } }
// Bokan ga bokka--nn!! // Daily Lunch Special Tanoshii !! // これは、頭が悪く競プロが世界で一番できないHIR180が // IOI2014日本代表になるまでのN日間の記録である。 #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; typedef long long ll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 #define f first #define s second #define rep(i, x) for (int i = 0; i < x; i++) P za[3005]; int main() { srand((unsigned int)time(NULL)); while (1) { int n; scanf("%d", &n); if (!n) return 0; static bool in[5005][5005] = {}; for (int i = 1; i <= n; i++) { scanf("%d %d", &za[i].f, &za[i].s); in[za[i].f][za[i].s] = true; } int ret = 0; for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int xa = za[i].f; int xb = za[j].f; int ya = za[i].s; int yb = za[j].s; if (xa + xb - yb + ya < 0 || ya + yb + xb - xa < 0 || xa + xb + yb - ya < 0 || ya + yb - xb + xa < 0) continue; if (xa + xb - yb + ya > 10000 || ya + yb + xb - xa > 10000 || xa + xb + yb - ya > 10000 || ya + yb - xb + xa > 10000) continue; if (in[(xa + xb - yb + ya) / 2][(ya + yb + xb - xa) / 2] && in[(xa + xb + yb - ya) / 2][(ya + yb - xb + xa) / 2]) ret = max(ret, (xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); } } printf("%d\n", ret / 2); } }
insert
55
55
55
58
0
p00441
C++
Memory Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <memory> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, m, n) for (int i = m; i < n; i++) using namespace std; typedef complex<double> xy_t; typedef pair<xy_t, xy_t> line; typedef long long ll; typedef pair<int, int> P; typedef pair<double, double> Pd; typedef pair<int, P> PP; typedef pair<int, PP> PPP; const int INF = 1 << 29; const double EPS = 1E-10; #define rep(i, n) for (int i = 0; i < n; i++) map<P, bool> mp; P pos[5000]; int main() { int n; while (cin >> n && n) { int res = 0; mp.clear(); rep(i, n) { cin >> pos[i].first >> pos[i].second; mp[pos[i]] = true; } rep(i, n) rep(j, n) { if (i == j) continue; int dx = pos[i].first - pos[j].first; int dy = pos[i].second - pos[j].second; int x2 = pos[j].first + dy; int y2 = pos[j].second - dx; int x3 = x2 + dx; int y3 = y2 + dy; if (mp[P(x2, y2)] && mp[P(x3, y3)]) { res = max(res, dx * dx + dy * dy); } } cout << res << endl; } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <memory> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define rep2(i, m, n) for (int i = m; i < n; i++) using namespace std; typedef complex<double> xy_t; typedef pair<xy_t, xy_t> line; typedef long long ll; typedef pair<int, int> P; typedef pair<double, double> Pd; typedef pair<int, P> PP; typedef pair<int, PP> PPP; const int INF = 1 << 29; const double EPS = 1E-10; #define rep(i, n) for (int i = 0; i < n; i++) map<P, bool> mp; P pos[5000]; int main() { int n; while (cin >> n && n) { int res = 0; mp.clear(); rep(i, n) { cin >> pos[i].first >> pos[i].second; mp[pos[i]] = true; } rep(i, n) rep(j, n) { if (i == j) continue; int dx = pos[i].first - pos[j].first; int dy = pos[i].second - pos[j].second; int x2 = pos[j].first + dy; int y2 = pos[j].second - dx; int x3 = x2 + dx; int y3 = y2 + dy; if (mp.find(P(x2, y2)) != mp.end() && mp.find(P(x3, y3)) != mp.end()) { res = max(res, dx * dx + dy * dy); } } cout << res << endl; } return 0; }
replace
62
63
62
63
MLE
p00441
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dx[] = {1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define mp make_pair #define ft first #define sc second int n; int x[4000], y[4000]; bool s[5010][5010]; bool input() { REP(i, 5010) REP(j, 5010) s[i][j] = false; scanf("%d", &n); REP(i, n) { scanf("%d%d", x + i, y + i); s[x[i]][y[i]] = true; } return n != 0; } typedef pair<int, int> P; typedef pair<P, P> L; #define EPS (1e-10) void solve() { int maxi = -1, maxj = -1; REP(i, n) { FOR(j, i + 1, n) { int a = x[i] + x[j]; int b = x[i] - x[j]; int c = y[i] + y[j]; int d = y[j] - y[i]; if (((a + d) % 2) * ((b + c) % 2)) continue; if (s[(a + d) / 2][(b + c) / 2] && s[(a - d) / 2][(-b + c) / 2]) { if (maxi == -1 || (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) > (x[maxi] - x[maxj]) * (x[maxi] - x[maxj]) + (y[maxi] - y[maxj]) * (y[maxi] - y[maxj])) { maxi = i; maxj = j; } } } } if (maxi == -1) printf("0\n"); else printf("%d\n", ((x[maxi] - x[maxj]) * (x[maxi] - x[maxj]) + (y[maxi] - y[maxj]) * (y[maxi] - y[maxj])) / 2); } int main() { while (input()) solve(); return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dx[] = {1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define mp make_pair #define ft first #define sc second int n; int x[4000], y[4000]; bool s[5010][5010]; bool input() { REP(i, 5010) REP(j, 5010) s[i][j] = false; scanf("%d", &n); REP(i, n) { scanf("%d%d", x + i, y + i); s[x[i]][y[i]] = true; } return n != 0; } typedef pair<int, int> P; typedef pair<P, P> L; #define EPS (1e-10) void solve() { int maxi = -1, maxj = -1; REP(i, n) { FOR(j, i + 1, n) { int a = x[i] + x[j]; int b = x[i] - x[j]; int c = y[i] + y[j]; int d = y[j] - y[i]; if (((a + d) % 2) * ((b + c) % 2)) continue; if (!(0 <= (a + d) / 2 && (a + d) / 2 < 5001 && 0 <= (b + c) / 2 && (b + c) / 2 < 5001)) { continue; } if (!(0 <= (a - d) / 2 && (a - d) / 2 < 5001 && 0 <= (-b + c) / 2 && (-b + c) / 2 < 5001)) { continue; } if (s[(a + d) / 2][(b + c) / 2] && s[(a - d) / 2][(-b + c) / 2]) { if (maxi == -1 || (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) > (x[maxi] - x[maxj]) * (x[maxi] - x[maxj]) + (y[maxi] - y[maxj]) * (y[maxi] - y[maxj])) { maxi = i; maxj = j; } } } } if (maxi == -1) printf("0\n"); else printf("%d\n", ((x[maxi] - x[maxj]) * (x[maxi] - x[maxj]) + (y[maxi] - y[maxj]) * (y[maxi] - y[maxj])) / 2); } int main() { while (input()) solve(); return 0; }
insert
47
47
47
55
0
p00441
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; const int MAX_N = 3000; const int MAX_XY = 5000; int n; int a[MAX_N][2]; bool b[MAX_XY][MAX_XY]; int main() { while (1) { scanf("%d", &n); if (n == 0) break; for (int i = 0; i < MAX_N; i++) for (int j = 0; j < 2; j++) a[i][j] = 0; for (int i = 0; i < MAX_XY; i++) for (int j = 0; j < MAX_XY; j++) b[i][j] = false; for (int i = 0; i < n; i++) { scanf("%d %d", &a[i][0], &a[i][1]); b[a[i][0]][a[i][1]] = true; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int dx, dy; dx = a[j][0] - a[i][0]; dy = a[j][1] - a[i][1]; for (int k = 0; k < 2; k++) { int nx, ny; nx = a[i][0] + (2 * k - 1) * dy; ny = a[i][1] - (2 * k - 1) * dx; if (0 <= nx && nx <= MAX_XY && 0 <= ny && ny <= MAX_XY) { if (b[nx][ny] == true && b[nx + dx][ny + dy] == true) { ans = max(ans, dx * dx + dy * dy); } } } } } printf("%d\n", ans); } return 0; }
#include <algorithm> #include <cstdio> using namespace std; const int MAX_N = 3000; const int MAX_XY = 5000; int n; int a[MAX_N][2]; bool b[MAX_XY][MAX_XY]; int main() { while (1) { scanf("%d", &n); if (n == 0) break; for (int i = 0; i < MAX_N; i++) for (int j = 0; j < 2; j++) a[i][j] = 0; for (int i = 0; i < MAX_XY; i++) for (int j = 0; j < MAX_XY; j++) b[i][j] = false; for (int i = 0; i < n; i++) { scanf("%d %d", &a[i][0], &a[i][1]); b[a[i][0]][a[i][1]] = true; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int dx, dy; dx = a[j][0] - a[i][0]; dy = a[j][1] - a[i][1]; for (int k = 0; k < 2; k++) { int nx, ny; nx = a[i][0] + (2 * k - 1) * dy; ny = a[i][1] - (2 * k - 1) * dx; if (0 <= nx && nx <= MAX_XY && 0 <= ny && ny <= MAX_XY) { if (0 <= nx + dx && nx + dx <= MAX_XY && 0 <= ny + dy && ny + dy <= MAX_XY) { if (b[nx][ny] == true && b[nx + dx][ny + dy] == true) { ans = max(ans, dx * dx + dy * dy); } } } } } } printf("%d\n", ans); } return 0; }
replace
39
41
39
44
0
p00441
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; bool p[5001][5001]; int x[3000], y[3000], n, maxn; int main() { while (true) { cin >> n; maxn = 0; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; p[x[i]][y[i]] = true; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; int X1 = x[j] - x[i], Y1 = y[j] - y[i]; int X2 = -Y1, Y2 = X1; int X3 = X1 - Y1, Y3 = X1 + Y1; if (p[X2 + x[i]][Y2 + y[i]] == true && p[X3 + x[i]][Y3 + y[i]] == true) { maxn = max(maxn, X1 * X1 + Y1 * Y1); } } } cout << maxn << endl; for (int i = 0; i < n; i++) { p[x[i]][y[i]] = true; } } return 0; }
#include <algorithm> #include <iostream> using namespace std; bool p[5001][5001]; int x[3000], y[3000], n, maxn; int main() { while (true) { cin >> n; maxn = 0; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; p[x[i]][y[i]] = true; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; int X1 = x[j] - x[i], Y1 = y[j] - y[i]; int X2 = -Y1, Y2 = X1; int X3 = X1 - Y1, Y3 = X1 + Y1; int X4 = X2 + x[i], Y4 = Y2 + y[i]; int X5 = X3 + x[i], Y5 = Y3 + y[i]; if (X4 < 0 || X4 > 5000 || Y4 < 0 || Y4 > 5000 || X5 < 0 || X5 > 5000 || Y5 < 0 || Y5 > 5000) continue; if (p[X4][Y4] == true && p[X5][Y5] == true) { maxn = max(maxn, X1 * X1 + Y1 * Y1); } } } cout << maxn << endl; for (int i = 0; i < n; i++) { p[x[i]][y[i]] = true; } } return 0; }
replace
22
24
22
28
-11
p00441
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #pragma warning(disable : 4996) using namespace std; int n, x[3009], y[3009]; bool ok[5009][5009]; int main() { while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); ok[x[i]][y[i]] = true; } int ret = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int va = x[j] - x[i], vb = y[j] - y[i]; int ex = x[i] + vb, ey = y[i] - va; int fx = x[j] + vb, fy = y[j] - va; if (0 <= ex && ex <= 5000 && 0 <= fy && fy <= 5000 && ok[ex][ey] && ok[fx][fy]) { ret = max(ret, va * va + vb * vb); } } } printf("%d\n", ret); for (int i = 0; i < n; i++) ok[x[i]][y[i]] = false; } return 0; }
#include <algorithm> #include <iostream> #include <vector> #pragma warning(disable : 4996) using namespace std; int n, x[3009], y[3009]; bool ok[5009][5009]; int main() { while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) { scanf("%d%d", &x[i], &y[i]); ok[x[i]][y[i]] = true; } int ret = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int va = x[j] - x[i], vb = y[j] - y[i]; int ex = x[i] + vb, ey = y[i] - va; int fx = x[j] + vb, fy = y[j] - va; if (0 <= ex && ex <= 5000 && 0 <= ey && ey <= 5000 && 0 <= fx && fx <= 5000 && 0 <= fy && fy <= 5000 && ok[ex][ey] && ok[fx][fy]) { ret = max(ret, va * va + vb * vb); } } } printf("%d\n", ret); for (int i = 0; i < n; i++) ok[x[i]][y[i]] = false; } return 0; }
replace
19
21
19
21
0
p00441
C++
Runtime Error
#include <iostream> using namespace std; int n; bool p[5001][5001]; bool c(int a) { return 0 <= a && a <= 5000; } int main() { while (cin >> n && n) { int x[5001], y[5001], an = 0; for (int i = 0; i < n; i++) cin >> x[i] >> y[i], p[x[i]][y[i]] = 1; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { int dx = x[i] - x[j]; int dy = y[i] - y[j]; int x1 = x[i] - dy; int x2 = x[j] - dy; int y1 = y[i] + dx; int y2 = y[j] + dx; int x3 = x[i] - dy, y3 = y[i] + dx, x4 = x[j] + dy, y4 = y[j] - dx; if (c(x1) && c(y1) && p[x1][y1] && c(x2) && c(y2) && p[x2][y2]) an = max(an, dx * dx + dy * dy); if (p[x3][y3] && p[x4][y4] && c(x3) && c(y3) && c(x4) && c(y4)) an = max(an, dx * dx + dy * dy); } cout << an << endl; } return 0; }
#include <iostream> using namespace std; int n; bool p[5001][5001]; bool c(int a) { return 0 <= a && a <= 5000; } int main() { while (cin >> n && n) { int x[5001], y[5001], an = 0; for (int i = 0; i < n; i++) cin >> x[i] >> y[i], p[x[i]][y[i]] = 1; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) { int dx = x[i] - x[j]; int dy = y[i] - y[j]; int x1 = x[i] - dy; int x2 = x[j] - dy; int y1 = y[i] + dx; int y2 = y[j] + dx; int x3 = x[i] - dy, y3 = y[i] + dx, x4 = x[j] + dy, y4 = y[j] - dx; if (c(x1) && c(y1) && p[x1][y1] && c(x2) && c(y2) && p[x2][y2]) an = max(an, dx * dx + dy * dy); if (c(x3) && c(y3) && p[x3][y3] && c(x4) && c(y4) && p[x4][y4]) an = max(an, dx * dx + dy * dy); } cout << an << endl; } return 0; }
replace
21
22
21
22
-11
p00441
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef complex<double> P; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define sz(x) ((int)(x).size()) #define fi first #define sec second #define X real() #define Y imag() #define EQ(a, b) (abs((a) - (b)) < EPS) short f[5000][5000]; int n; int ans = 0; vector<P> v; int main() { while (1) { ans = 0; memset(f, 0, sizeof(f)); cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { int p, q; cin >> p >> q; f[p][q]++; v.pb(P(p, q)); } for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { P k = v[i] - v[j]; P n = k * P(0, 1); P c = v[i] + n; P d = v[j] + n; if (c.X - (int)c.X != 0 || c.Y - (int)c.Y != 0 || d.X - (int)d.X != 0 || d.Y - (int)d.Y != 0 || c.X < 0 || c.Y < 0 || c.X > 5000 || c.Y > 5000 || d.X < 0 || d.Y < 0 || d.X > 5000 || d.Y > 5000) { continue; } if (f[(int)c.X][(int)c.Y] && f[(int)d.X][(int)d.Y]) { P e = d - v[j]; int sq = ((int)k.X) * ((int)e.Y) - ((int)k.Y) * ((int)e.X); if (sq < 0) sq = -sq; ans = max(ans, sq); } } } cout << ans << endl; } return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef complex<double> P; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 #define sz(x) ((int)(x).size()) #define fi first #define sec second #define X real() #define Y imag() #define EQ(a, b) (abs((a) - (b)) < EPS) short f[5001][5001]; int n; int ans = 0; vector<P> v; int main() { while (1) { ans = 0; memset(f, 0, sizeof(f)); cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { int p, q; cin >> p >> q; f[p][q]++; v.pb(P(p, q)); } for (int i = 0; i < v.size() - 1; i++) { for (int j = i + 1; j < v.size(); j++) { P k = v[i] - v[j]; P n = k * P(0, 1); P c = v[i] + n; P d = v[j] + n; if (c.X - (int)c.X != 0 || c.Y - (int)c.Y != 0 || d.X - (int)d.X != 0 || d.Y - (int)d.Y != 0 || c.X < 0 || c.Y < 0 || c.X > 5000 || c.Y > 5000 || d.X < 0 || d.Y < 0 || d.X > 5000 || d.Y > 5000) { continue; } if (f[(int)c.X][(int)c.Y] && f[(int)d.X][(int)d.Y]) { P e = d - v[j]; int sq = ((int)k.X) * ((int)e.Y) - ((int)k.Y) * ((int)e.X); if (sq < 0) sq = -sq; ans = max(ans, sq); } } } cout << ans << endl; } return 0; }
replace
30
31
30
31
0
p00441
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; long long int mod = 1e9 + 7; template <class T> void inputV(vector<T> &x, int n) { for (int i = 0; i < n; i++) cin >> x[i]; } bool mp[5001][5001]; int func(pair<int, int> a, pair<int, int> b) { pair<int, int> c = {0, 0}; c.first = a.first + abs(b.second - a.second); c.second = a.second + abs(b.first - a.first); pair<int, int> d = {0, 0}; d.first = b.first + abs(b.second - a.second); d.second = b.second + abs(b.first - a.first); if (c.first < 0 || c.first > 5000 || c.second < 0 || c.second > 5000) return 0; if (d.first < 0 || d.first > 5000 || d.second < 0 || d.second > 5000) return 0; if (mp[c.first][c.second] && mp[d.first][d.second]) { cerr << (a.first - b.first) << " " << (a.second - b.second) << endl; return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } return 0; } int main() { int n; while (cin >> n) { if (n == 0) break; for (int i = 0; i <= 5000; i++) for (int j = 0; j <= 5000; j++) mp[i][j] = false; vector<pair<int, int>> p(n); for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; mp[p[i].first][p[i].second] = true; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; ans = max(ans, func(p[i], p[j])); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; long long int mod = 1e9 + 7; template <class T> void inputV(vector<T> &x, int n) { for (int i = 0; i < n; i++) cin >> x[i]; } bool mp[5001][5001]; int func(pair<int, int> a, pair<int, int> b) { pair<int, int> c = {0, 0}; c.first = a.first + abs(b.second - a.second); c.second = a.second + abs(b.first - a.first); pair<int, int> d = {0, 0}; d.first = b.first + abs(b.second - a.second); d.second = b.second + abs(b.first - a.first); if (c.first < 0 || c.first > 5000 || c.second < 0 || c.second > 5000) return 0; if (d.first < 0 || d.first > 5000 || d.second < 0 || d.second > 5000) return 0; if (mp[c.first][c.second] && mp[d.first][d.second]) { // cerr << (a.first-b.first) << " " << (a.second-b.second) << endl; return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } return 0; } int main() { int n; while (cin >> n) { if (n == 0) break; for (int i = 0; i <= 5000; i++) for (int j = 0; j <= 5000; j++) mp[i][j] = false; vector<pair<int, int>> p(n); for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; mp[p[i].first][p[i].second] = true; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; ans = max(ans, func(p[i], p[j])); } } cout << ans << endl; } return 0; }
replace
36
37
36
37
0
0 1 -3 1 0 -1 -1 0 3 -1 1 0 0 1 -3 1 0 -1 -1 0 3 -1 1 0
p00441
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <map> #include <set> using namespace std; typedef pair<int, int> P; int n; P st[3000]; int main() { while (scanf("%d", &n)) { if (!n) break; set<P> stat; for (int i = 0; i < n; i++) { scanf("%d%d", &st[i].first, &st[i].second); stat.insert(st[i]); } int res = 0; for (int i = 0; i < n; i++) { P a = st[i]; for (int j = 0; j < n; j++) { P b = st[j]; int dist1 = b.first - a.first, dist2 = a.second - b.second; // printf("%d %d %d %d:%d %d:%d %d %d // %d\n",a.first,a.second,b.first,b.second,dist1,dist2,a.first-dist2,a.second-dist1,b.first-dist2,b.second-dist1); int r1 = stat.count(P(b.first - dist2, b.second - dist1)); int r2 = stat.count(P(a.first - dist2, a.second - dist1)); // printf("%d %d\n",r1,r2); if (r1 && r2) { res = max(res, dist1 * dist1 + dist2 * dist2); } } } printf("%d\n", res); } }
#include <algorithm> #include <cstdio> #include <map> #include <set> using namespace std; typedef pair<int, int> P; int n; P st[3000]; int main() { while (scanf("%d", &n)) { if (!n) break; set<P> stat; for (int i = 0; i < n; i++) { scanf("%d%d", &st[i].first, &st[i].second); stat.insert(st[i]); } int res = 0; for (int i = 0; i < n; i++) { P a = st[i]; for (int j = 0; j < n; j++) { P b = st[j]; int dist1 = b.first - a.first, dist2 = a.second - b.second; if (stat.find(P(b.first - dist2, b.second - dist1)) != stat.end() && stat.find(P(a.first - dist2, a.second - dist1)) != stat.end()) { res = max(res, dist1 * dist1 + dist2 * dist2); } } } printf("%d\n", res); } }
replace
23
29
23
25
TLE
p00441
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define PB push_back typedef pair<int, int> pii; static const int INF = 1LL << 61; inline bool isRange(pii &p1) { return 0 <= p1.first && p1.second <= 5000; } inline double dis(pii &p1, pii &p2) { double a = abs(p1.first - p2.first), b = abs(p1.second - p2.second); return sqrt(a * a + b * b); } bool exist[5005][5005] = {false}; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; while (cin >> n, n) { pii ps[3005]; fill(exist[0], exist[5005], false); for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; ps[i] = pii(x, y); exist[x][y] = true; } sort(ps, ps + n); int res = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (i == j) continue; for (int k = -1; k < 2; k += 2) { int dx = k * abs(ps[i].second - ps[j].second), dy = k * abs(ps[i].first - ps[j].first); pii temp[2] = {pii(ps[i].first + dx, ps[i].second + dy), pii(ps[j].first + dx, ps[j].second + dy)}; if (!isRange(temp[0]) || !isRange(temp[1]) || !exist[temp[0].first][temp[0].second] || !exist[temp[1].first][temp[1].second]) continue; double seg = dis(ps[i], ps[j]); res = max(res, (long long)(seg * seg + 0.00000001)); } } } cout << res << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define PB push_back typedef pair<int, int> pii; static const int INF = 1LL << 61; inline bool isRange(pii &p1) { return 0 <= p1.first && p1.first <= 5000 && 0 <= p1.second && p1.second <= 5000; } inline double dis(pii &p1, pii &p2) { double a = abs(p1.first - p2.first), b = abs(p1.second - p2.second); return sqrt(a * a + b * b); } bool exist[5005][5005] = {false}; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; while (cin >> n, n) { pii ps[3005]; fill(exist[0], exist[5005], false); for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; ps[i] = pii(x, y); exist[x][y] = true; } sort(ps, ps + n); int res = 0; for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { if (i == j) continue; for (int k = -1; k < 2; k += 2) { int dx = k * abs(ps[i].second - ps[j].second), dy = k * abs(ps[i].first - ps[j].first); pii temp[2] = {pii(ps[i].first + dx, ps[i].second + dy), pii(ps[j].first + dx, ps[j].second + dy)}; if (!isRange(temp[0]) || !isRange(temp[1]) || !exist[temp[0].first][temp[0].second] || !exist[temp[1].first][temp[1].second]) continue; double seg = dis(ps[i], ps[j]); res = max(res, (long long)(seg * seg + 0.00000001)); } } } cout << res << endl; } return 0; }
replace
9
10
9
13
0
p00441
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #define sint(i) scanf("%d", &i); #define sintt(i, j) scanf("%d%d", &i, &j); #define sinttt(i, j, k) scanf("%d%d%d", &i, &j, &k); #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; char masu[5001][5001]; int main() { while (1) { int n; sint(n); // if(n==0)break; rep(i, 5001) { rep(j, 5001) { masu[i][j] = -1; } } int nx[3001]; int ny[3001]; rep(i, n) { sintt(nx[i], ny[i]); masu[nx[i]][ny[i]] = 1; } /* rep(i,10){ rep(j,10){ printf("%2d",masu[j][9-(i)]); }puts(""); }*/ int maxi = 0; rep(i, n) { rep(j, n - i) { if (i == j + i) { continue; } int dx = nx[i] - nx[j + i]; int dy = ny[i] - ny[j + i]; int a[8]; a[0] = nx[i] + dy * -1; a[1] = ny[i] + dx; a[2] = nx[j + i] + dy * -1; a[3] = ny[j + i] + dx; a[4] = nx[i] + dy; a[5] = ny[i] + dx * -1; a[6] = nx[j + i] + dy; a[7] = ny[j + i] + dx * -1; int flg1 = 0, flg2 = 0; rep(k, 4) { if (a[k] < 0 || a[k] > 5000) { flg1 = 1; } } rep(k, 4) { if (a[k + 4] < 0 || a[k + 4] > 5000) { flg2 = 1; } } /* rep(k,8){ printf("%6d",a[k]); } printf(" 1==%d 2==%d\n",flg1,flg2); */ if ((flg1 == 0 && masu[nx[i] + dy * -1][ny[i] + dx] == 1 && masu[nx[j + i] + dy * -1][ny[j + i] + dx] == 1) || (flg2 == 0 && masu[nx[i] + dy][ny[i] + dx * -1] == 1 && masu[nx[j + i] + dy][ny[j + i] + dx * -1] == 1)) { maxi = max(maxi, dx * dx + dy * dy); } } } printf("%d\n", maxi); } } /* 4 0 5000 5000 0 0 0 5000 5000 */
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #define sint(i) scanf("%d", &i); #define sintt(i, j) scanf("%d%d", &i, &j); #define sinttt(i, j, k) scanf("%d%d%d", &i, &j, &k); #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; char masu[5001][5001]; int main() { while (1) { int n; sint(n); if (n == 0) break; rep(i, 5001) { rep(j, 5001) { masu[i][j] = -1; } } int nx[3001]; int ny[3001]; rep(i, n) { sintt(nx[i], ny[i]); masu[nx[i]][ny[i]] = 1; } /* rep(i,10){ rep(j,10){ printf("%2d",masu[j][9-(i)]); }puts(""); }*/ int maxi = 0; rep(i, n) { rep(j, n - i) { if (i == j + i) { continue; } int dx = nx[i] - nx[j + i]; int dy = ny[i] - ny[j + i]; int a[8]; a[0] = nx[i] + dy * -1; a[1] = ny[i] + dx; a[2] = nx[j + i] + dy * -1; a[3] = ny[j + i] + dx; a[4] = nx[i] + dy; a[5] = ny[i] + dx * -1; a[6] = nx[j + i] + dy; a[7] = ny[j + i] + dx * -1; int flg1 = 0, flg2 = 0; rep(k, 4) { if (a[k] < 0 || a[k] > 5000) { flg1 = 1; } } rep(k, 4) { if (a[k + 4] < 0 || a[k + 4] > 5000) { flg2 = 1; } } /* rep(k,8){ printf("%6d",a[k]); } printf(" 1==%d 2==%d\n",flg1,flg2); */ if ((flg1 == 0 && masu[nx[i] + dy * -1][ny[i] + dx] == 1 && masu[nx[j + i] + dy * -1][ny[j + i] + dx] == 1) || (flg2 == 0 && masu[nx[i] + dy][ny[i] + dx * -1] == 1 && masu[nx[j + i] + dy][ny[j + i] + dx * -1] == 1)) { maxi = max(maxi, dx * dx + dy * dy); } } } printf("%d\n", maxi); } } /* 4 0 5000 5000 0 0 0 5000 5000 */
replace
17
18
17
19
TLE
p00441
C++
Memory Limit Exceeded
#include <iostream> #define REP(i, a, n) for (int i = a; i < n; i++) using namespace std; int n; int x[3000], y[3000]; int mp[5001][5001]; int m, dx, dy, s; int exists(int x, int y) { return 0 <= x && x <= 5000 && 0 <= y && y <= 5000 && mp[x][y] == 1; } int main(void) { while (cin >> n, n != 0) { REP(i, 0, 5001) { REP(j, 0, 5001) { mp[i][j] = 0; } } REP(i, 0, n) { cin >> x[i] >> y[i]; mp[x[i]][y[i]] = 1; } m = 0; REP(i, 0, n) { REP(j, i + 1, n) { dx = x[i] - x[j]; dy = y[i] - y[j]; if (exists(x[i] + dy, y[i] - dx) && exists(x[j] + dy, y[j] - dx)) { s = dx * dx + dy * dy; if (m < s) m = s; } if (exists(x[i] - dy, y[i] + dx) && exists(x[j] - dy, y[j] + dx)) { s = dx * dx + dy * dy; if (m < s) m = s; } } } cout << m << endl; } return 0; }
#include <iostream> #define REP(i, a, n) for (int i = a; i < n; i++) using namespace std; int n; int x[3000], y[3000]; bool mp[5001][5001]; int m, dx, dy, s; int exists(int x, int y) { return 0 <= x && x <= 5000 && 0 <= y && y <= 5000 && mp[x][y] == 1; } int main(void) { while (cin >> n, n != 0) { REP(i, 0, 5001) { REP(j, 0, 5001) { mp[i][j] = 0; } } REP(i, 0, n) { cin >> x[i] >> y[i]; mp[x[i]][y[i]] = 1; } m = 0; REP(i, 0, n) { REP(j, i + 1, n) { dx = x[i] - x[j]; dy = y[i] - y[j]; if (exists(x[i] + dy, y[i] - dx) && exists(x[j] + dy, y[j] - dx)) { s = dx * dx + dy * dy; if (m < s) m = s; } if (exists(x[i] - dy, y[i] + dx) && exists(x[j] - dy, y[j] + dx)) { s = dx * dx + dy * dy; if (m < s) m = s; } } } cout << m << endl; } return 0; }
replace
6
7
6
7
MLE
p00441
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int x[3000], y[3000]; bool f[5001][5001]; int main() { int n; while (scanf("%d", &n), n) { memset(x, 0, sizeof(x)); memset(y, 0, sizeof(y)); memset(f, 0, sizeof(f)); for (int i = 0; i < n; i++) { scanf("%d %d", &x[i], &y[i]); f[x[i]][y[i]] = true; } int maxi = 0; for (int i = 0; i < n; i++) { for (int j = 1; j < n; j++) { const int X = abs(x[i] - x[j]); const int Y = abs(y[i] - y[j]); if (f[x[i] + Y][y[i] + X] && f[x[j] + Y][y[j] + X]) { maxi = max(maxi, X * X + Y * Y); } } } printf("%d\n", maxi); } return 0; }
#include <bits/stdc++.h> using namespace std; int x[3000], y[3000]; bool f[5001][5001]; int main() { int n; while (scanf("%d", &n), n) { memset(x, 0, sizeof(x)); memset(y, 0, sizeof(y)); memset(f, 0, sizeof(f)); for (int i = 0; i < n; i++) { scanf("%d %d", &x[i], &y[i]); f[x[i]][y[i]] = true; } int maxi = 0; for (int i = 0; i < n; i++) { for (int j = 1; j < n; j++) { const int X = abs(x[i] - x[j]); const int Y = abs(y[i] - y[j]); if (x[i] + Y <= 5000 && y[i] + X <= 5000 && x[j] + Y <= 5000 && y[j] + X <= 5000) { if (f[x[i] + Y][y[i] + X] && f[x[j] + Y][y[j] + X]) { maxi = max(maxi, X * X + Y * Y); } } } } printf("%d\n", maxi); } return 0; }
replace
24
26
24
29
0
p00441
C++
Memory Limit Exceeded
#include <iostream> #define N 3000 #define S 5001 int px[N], py[N]; int n; int pillar[S][S]; void init() { int i, j; for (i = 0; i < S; i++) { for (j = 0; j < S; j++) { pillar[i][j] = 0; } } return; } int input() { int i, x, y; init(); std::cin >> n; for (i = 0; i < n; i++) { std::cin >> x >> y; pillar[x][y] = 1; px[i] = x; py[i] = y; } return n; } int func() { int area = 0, i, j, dx, dy, p3x, p3y, p4x, p4y; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i == j) { continue; } // std::cout << i << "," << j << std::endl; dx = px[i] - px[j]; dy = py[i] - py[j]; p3x = px[j] + dy; p3y = py[j] - dx; p4x = px[i] + dy; p4y = py[i] - dx; // std::cout << px[i] << "," << py[i] << ":" << px[j] << "," << py[j] << // ":"; std::cout << p3x << "," << p3y << ":" << p4x << "," << p4y << // std::endl; if (p3x < 0 || p3y < 0 || p4x < 0 || p4y < 0) { continue; } if (p3x >= S || p3y >= S || p4x >= S || p4y >= S) { continue; } if (pillar[p3x][p3y] == 1 && pillar[p4x][p4y] == 1) { int s = dx * dx + dy * dy; area = (s > area ? s : area); } } } return area; } int main() { while (input() > 0) { std::cout << func() << std::endl; } return 0; }
#include <iostream> #define N 3000 #define S 5001 int px[N], py[N]; int n; char pillar[S][S]; void init() { int i, j; for (i = 0; i < S; i++) { for (j = 0; j < S; j++) { pillar[i][j] = 0; } } return; } int input() { int i, x, y; init(); std::cin >> n; for (i = 0; i < n; i++) { std::cin >> x >> y; pillar[x][y] = 1; px[i] = x; py[i] = y; } return n; } int func() { int area = 0, i, j, dx, dy, p3x, p3y, p4x, p4y; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (i == j) { continue; } // std::cout << i << "," << j << std::endl; dx = px[i] - px[j]; dy = py[i] - py[j]; p3x = px[j] + dy; p3y = py[j] - dx; p4x = px[i] + dy; p4y = py[i] - dx; // std::cout << px[i] << "," << py[i] << ":" << px[j] << "," << py[j] << // ":"; std::cout << p3x << "," << p3y << ":" << p4x << "," << p4y << // std::endl; if (p3x < 0 || p3y < 0 || p4x < 0 || p4y < 0) { continue; } if (p3x >= S || p3y >= S || p4x >= S || p4y >= S) { continue; } if (pillar[p3x][p3y] == 1 && pillar[p4x][p4y] == 1) { int s = dx * dx + dy * dy; area = (s > area ? s : area); } } } return area; } int main() { while (input() > 0) { std::cout << func() << std::endl; } return 0; }
replace
6
7
6
7
MLE
p00441
C++
Memory Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) using namespace std; // kaewasuretyuui typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef pair<int, pii> pip; typedef vector<pip> vip; const double PI = acos(-1); const double EPS = 1e-8; const int inf = 1 << 30; vp in; pii p1, p2; int fil[5010][5010]; bool f(pii w) { int a = w.first, b = w.second; if (a < 0 || b < 0 || a >= 5010 || b >= 5010) return false; return true; } int main() { int n; while (cin >> n, n) { rep(i, 5010) rep(j, 5010) fil[i][j] = 0; in = vp(n); rep(i, n) { int a, b; cin >> a >> b; fil[a][b] = 1; in[i] = pii(a, b); } int out = 0; rep(i, n) { // if(i%100==0)cout<<i<<endl; rep(j, n) if (i != j) { int a = in[i].first - in[j].first, b = in[i].second - in[j].second; p1 = pii(in[i].first - b, in[i].second + a); p2 = pii(in[j].first - b, in[j].second + a); if (f(p1) == 0 || f(p2) == 0) continue; if (fil[p1.first][p1.second] && fil[p2.first][p2.second]) out = max(out, a * a + b * b); } } cout << out << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) using namespace std; // kaewasuretyuui typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<vp> vvp; typedef pair<int, pii> pip; typedef vector<pip> vip; const double PI = acos(-1); const double EPS = 1e-8; const int inf = 1 << 30; vp in; pii p1, p2; bool fil[5010][5010]; bool f(pii w) { int a = w.first, b = w.second; if (a < 0 || b < 0 || a >= 5010 || b >= 5010) return false; return true; } int main() { int n; while (cin >> n, n) { rep(i, 5010) rep(j, 5010) fil[i][j] = 0; in = vp(n); rep(i, n) { int a, b; cin >> a >> b; fil[a][b] = 1; in[i] = pii(a, b); } int out = 0; rep(i, n) { // if(i%100==0)cout<<i<<endl; rep(j, n) if (i != j) { int a = in[i].first - in[j].first, b = in[i].second - in[j].second; p1 = pii(in[i].first - b, in[i].second + a); p2 = pii(in[j].first - b, in[j].second + a); if (f(p1) == 0 || f(p2) == 0) continue; if (fil[p1.first][p1.second] && fil[p2.first][p2.second]) out = max(out, a * a + b * b); } } cout << out << endl; } }
replace
34
35
34
35
MLE
p00441
C++
Runtime Error
// // main.cpp #include <iostream> #include <vector> using namespace std; int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<pair<int, int>> hashira; bool check[5001][5001]; for (int i = 0; i < 5001; i++) { for (int j = 0; j < 5001; j++) { check[i][j] = false; } } for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; check[a][b] = true; hashira.push_back(make_pair(a, b)); } int answer = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int x = hashira[j].first - hashira[i].first; int y = hashira[j].second - hashira[i].second; if (check[hashira[i].first - y][hashira[i].second + x] && check[hashira[i].first - y + x][hashira[i].second + y + x]) { answer = max(answer, x * x + y * y); } } } cout << answer << endl; } return 0; }
// // main.cpp #include <iostream> #include <vector> using namespace std; int main() { while (1) { int n; cin >> n; if (n == 0) break; vector<pair<int, int>> hashira; bool check[5001][5001]; for (int i = 0; i < 5001; i++) { for (int j = 0; j < 5001; j++) { check[i][j] = false; } } for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; check[a][b] = true; hashira.push_back(make_pair(a, b)); } int answer = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int x = hashira[j].first - hashira[i].first; int y = hashira[j].second - hashira[i].second; if (hashira[i].first - y > 5000 || hashira[i].second + x > 5000 || hashira[i].first - y + x > 5000 || hashira[i].second + y + x > 5000 || hashira[i].first - y < 0 || hashira[i].second + x < 0 || hashira[i].first - y + x < 0 || hashira[i].second + y + x < 0) { continue; } if (check[hashira[i].first - y][hashira[i].second + x] && check[hashira[i].first - y + x][hashira[i].second + y + x]) { answer = max(answer, x * x + y * y); } } } cout << answer << endl; } return 0; }
insert
31
31
31
39
-11
p00442
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef pair<int, int> P; int lose[1005] = {0}; bool match[5005][5005]; int main() { int n; cin >> n; int m; cin >> m; int tf = 0; int no_1 = -1; for (int i = 0; i < 5005; i++) { for (int j = 0; j < 5005; j++) match[i][j] = false; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; lose[b]++; match[b][a] = true; } for (int i = 1; i <= n; i++) { if (lose[i] == 0) { if (no_1 != -1) tf = 1; no_1 = i; } } int ans[5005] = {0}; bool used[5005]; for (int i = 0; i < 5005; i++) used[i] = false; for (int i = 1; i <= n; i++) { ans[i] = no_1; used[no_1] = true; for (int j = 1; j <= n; j++) { if (match[j][no_1]) lose[j]--; } no_1 = -1; for (int j = 1; j <= n; j++) { if (lose[j] == 0 && !used[j]) { if (no_1 != -1) tf = 1; no_1 = j; } } } for (int i = 1; i <= n; i++) cout << ans[i] << endl; cout << tf << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef pair<int, int> P; int lose[5005] = {0}; bool match[5005][5005]; int main() { int n; cin >> n; int m; cin >> m; int tf = 0; int no_1 = -1; for (int i = 0; i < 5005; i++) { for (int j = 0; j < 5005; j++) match[i][j] = false; } for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; lose[b]++; match[b][a] = true; } for (int i = 1; i <= n; i++) { if (lose[i] == 0) { if (no_1 != -1) tf = 1; no_1 = i; } } int ans[5005] = {0}; bool used[5005]; for (int i = 0; i < 5005; i++) used[i] = false; for (int i = 1; i <= n; i++) { ans[i] = no_1; used[no_1] = true; for (int j = 1; j <= n; j++) { if (match[j][no_1]) lose[j]--; } no_1 = -1; for (int j = 1; j <= n; j++) { if (lose[j] == 0 && !used[j]) { if (no_1 != -1) tf = 1; no_1 = j; } } } for (int i = 1; i <= n; i++) cout << ans[i] << endl; cout << tf << endl; return 0; }
replace
5
6
5
6
0
p00442
C++
Runtime Error
#include <queue> #include <stdio.h> #include <vector> using namespace std; #define PB push_back const int N = 3e3 + 10; int main() { int n, m, l, r, d[N], nxt; vector<int> graph[N]; queue<int> q; bool y = false; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) d[i] = 0; while (m--) { scanf("%d%d", &l, &r); graph[l].PB(r); d[r]++; } for (int i = 1; i <= n; i++) if (d[i] == 0) q.push(i); while (!q.empty()) { nxt = q.front(); q.pop(); printf("%d\n", nxt); y |= !q.empty(); for (int i : graph[nxt]) { d[i]--; if (d[i] == 0) q.push(i); } } printf("%d\n", y ? 1 : 0); }
#include <queue> #include <stdio.h> #include <vector> using namespace std; #define PB push_back const int N = 5e3 + 10; int main() { int n, m, l, r, d[N], nxt; vector<int> graph[N]; queue<int> q; bool y = false; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) d[i] = 0; while (m--) { scanf("%d%d", &l, &r); graph[l].PB(r); d[r]++; } for (int i = 1; i <= n; i++) if (d[i] == 0) q.push(i); while (!q.empty()) { nxt = q.front(); q.pop(); printf("%d\n", nxt); y |= !q.empty(); for (int i : graph[nxt]) { d[i]--; if (d[i] == 0) q.push(i); } } printf("%d\n", y ? 1 : 0); }
replace
5
6
5
6
0
p00442
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <vector> using namespace std; struct team { int num, dep; }; #define MAX_N 5000 #define MAX_M 100000 int n, m; vector<int> beat[MAX_N + 1]; team dat[MAX_N + 1]; team win[MAX_N + 1]; bool used[MAX_N + 1]; bool point[MAX_N + 1]; bool exi[MAX_N + 1] = {false}; bool check[MAX_N + 1]; bool comp(const team &t1, const team &t2) { return t1.dep < t2.dep; } bool comp2(const team &t1, const team &t2) { return t1.dep > t2.dep; } int dfs(int x) { for (int i = 0; i < beat[x].size(); i++) { dat[x].dep = max(dat[x].dep, dfs(beat[x][i]) + 1); used[beat[x][i]] = true; } return dat[x].dep + 1; } int main() { int w, l; for (int i = 1; i <= MAX_N; i++) { win[i].num = i; dat[i].num = i; } scanf("%d", &n); scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d%d", &w, &l); beat[w].push_back(l); win[w].dep++; exi[w] = true; exi[l] = true; } for (int i = 1; i <= n; i++) { if (!used[i] && !beat[i].empty()) { dat[i].dep = dfs(i) + 1; used[i] = true; } } sort(dat + 1, dat + n + 1, comp); for (int i = 1; i <= n; i++) { int id = dat[i].num; for (int j = 0; j < beat[id].size(); j++) { win[id].dep = max(win[id].dep, win[beat[id][j]].dep + 1); } point[win[id].dep] = true; } sort(win + 1, win + n + 1, comp2); // 順位の出力 int pt1 = 1, pt2 = 1; for (int i = n - 1; i >= 0; i--) { if (point[i]) { while (win[pt1].dep == i && pt1 <= n) { printf("%d\n", win[pt1].num); pt1++; } } else { while (exi[pt2] && pt2 <= n) { pt2++; } if (pt2 <= n) printf("%d\n", pt2); pt2++; } } for (int i = 1; i <= n; i++) { if (!check[win[i].dep]) check[win[i].dep] = true; else { printf("1\n"); return 0; } } printf("0\n"); return 0; }
#include <algorithm> #include <cstdio> #include <vector> using namespace std; struct team { int num, dep; }; #define MAX_N 5000 #define MAX_M 100000 int n, m; vector<int> beat[MAX_N + 1]; team dat[MAX_N + 1]; team win[MAX_N + 1]; bool used[MAX_N + 1]; bool point[MAX_N + 1]; bool exi[MAX_N + 1] = {false}; bool check[MAX_N + 1]; bool comp(const team &t1, const team &t2) { return t1.dep < t2.dep; } bool comp2(const team &t1, const team &t2) { return t1.dep > t2.dep; } int dfs(int x) { if (used[x]) return dat[x].dep; for (int i = 0; i < beat[x].size(); i++) { dat[x].dep = max(dat[x].dep, dfs(beat[x][i]) + 1); used[beat[x][i]] = true; } return dat[x].dep + 1; } int main() { int w, l; for (int i = 1; i <= MAX_N; i++) { win[i].num = i; dat[i].num = i; } scanf("%d", &n); scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%d%d", &w, &l); beat[w].push_back(l); win[w].dep++; exi[w] = true; exi[l] = true; } for (int i = 1; i <= n; i++) { if (!used[i] && !beat[i].empty()) { dat[i].dep = dfs(i) + 1; used[i] = true; } } sort(dat + 1, dat + n + 1, comp); for (int i = 1; i <= n; i++) { int id = dat[i].num; for (int j = 0; j < beat[id].size(); j++) { win[id].dep = max(win[id].dep, win[beat[id][j]].dep + 1); } point[win[id].dep] = true; } sort(win + 1, win + n + 1, comp2); // 順位の出力 int pt1 = 1, pt2 = 1; for (int i = n - 1; i >= 0; i--) { if (point[i]) { while (win[pt1].dep == i && pt1 <= n) { printf("%d\n", win[pt1].num); pt1++; } } else { while (exi[pt2] && pt2 <= n) { pt2++; } if (pt2 <= n) printf("%d\n", pt2); pt2++; } } for (int i = 1; i <= n; i++) { if (!check[win[i].dep]) check[win[i].dep] = true; else { printf("1\n"); return 0; } } printf("0\n"); return 0; }
insert
23
23
23
25
TLE
p00442
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define FOR(i, a) for (i = 0; i < (a); i++) #define FORM(i, a) for (i = (a)i >= 0; i--) using namespace std; vector<int> E[1010]; int indeg[1010]; queue<int> q; void bfs(int s) { int i, j; FOR(i, E[s].size()) { indeg[E[s][i]]--; if (indeg[E[s][i]] == 0) { q.push(E[s][i]); } } } void ranking(int N) { int i, j, k, l, flag = 0; FOR(i, N) { if (indeg[i + 1] == 0) { q.push(i + 1); indeg[i + 1]--; } } if (q.size() > 1) flag = 1; while (q.size() != 0) { cout << q.front() << endl; bfs(q.front()); q.pop(); if (q.size() > 1) { flag = 1; } } cout << flag << endl; } int main() { int i, j, N, K, m, n; cin >> n >> m; FOR(K, m) { cin >> i >> j; E[i].push_back(j); indeg[j]++; } ranking(n); return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <vector> #define FOR(i, a) for (i = 0; i < (a); i++) #define FORM(i, a) for (i = (a)i >= 0; i--) using namespace std; vector<int> E[5050]; int indeg[5050]; queue<int> q; void bfs(int s) { int i, j; FOR(i, E[s].size()) { indeg[E[s][i]]--; if (indeg[E[s][i]] == 0) { q.push(E[s][i]); } } } void ranking(int N) { int i, j, k, l, flag = 0; FOR(i, N) { if (indeg[i + 1] == 0) { q.push(i + 1); indeg[i + 1]--; } } if (q.size() > 1) flag = 1; while (q.size() != 0) { cout << q.front() << endl; bfs(q.front()); q.pop(); if (q.size() > 1) { flag = 1; } } cout << flag << endl; } int main() { int i, j, N, K, m, n; cin >> n >> m; FOR(K, m) { cin >> i >> j; E[i].push_back(j); indeg[j]++; } ranking(n); return 0; }
replace
15
17
15
17
0
p00442
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF 100000005 #define MAX 5001 using namespace std; queue<int> s; stack<int> a[MAX]; bool check[MAX][MAX]; int b[MAX]; int main() { int n, m, t1, t2; scanf("%d %d", &n, &m); fill(b, b + MAX, 0); fill((int *)check, (int *)(check + MAX), 0); for (int i = 0; i < m; i++) { scanf("%d %d", &t1, &t2); check[t1][t2] = 1; a[t1].push(t2); b[t2]++; } int ans[MAX], c = 0; for (int i = 1; i <= n; i++) if (!b[i]) s.push(i); while (!s.empty()) { int t = s.front(); ans[c++] = s.front(); while (!a[t].empty()) { if (--b[a[t].top()] == 0) s.push(a[t].top()); a[t].pop(); } s.pop(); } int f = 0; for (int i = 0; i < n - 1; i++) { if (check[ans[i]][ans[i + 1]] != 1) f = 1; } for (int i = 0; i < n; i++) printf("%d\n", ans[i]); printf("%d\n", f); return 0; }
#include <bits/stdc++.h> #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define INF 100000005 #define MAX 5001 using namespace std; queue<int> s; stack<int> a[MAX]; bool check[MAX][MAX]; int b[MAX]; int main() { int n, m, t1, t2; scanf("%d %d", &n, &m); fill(b, b + MAX, 0); rep(i, MAX) rep(j, MAX) check[i][j] = false; // fill((int*)check, (int*)(check+MAX), false); for (int i = 0; i < m; i++) { scanf("%d %d", &t1, &t2); check[t1][t2] = 1; a[t1].push(t2); b[t2]++; } int ans[MAX], c = 0; for (int i = 1; i <= n; i++) if (!b[i]) s.push(i); while (!s.empty()) { int t = s.front(); ans[c++] = s.front(); while (!a[t].empty()) { if (--b[a[t].top()] == 0) s.push(a[t].top()); a[t].pop(); } s.pop(); } int f = 0; for (int i = 0; i < n - 1; i++) { if (check[ans[i]][ans[i + 1]] != 1) f = 1; } for (int i = 0; i < n; i++) printf("%d\n", ans[i]); printf("%d\n", f); return 0; }
replace
15
16
15
17
-11
p00442
C++
Memory Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int N, M; int X[5000][5000]; int W[5000], L[5000]; pair<int, int> P[5000]; bool F = true; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) { int A, B; scanf("%d%d", &A, &B); X[A - 1][B - 1] = 1; W[A - 1]++; L[B - 1]++; } for (int LC = 0; LC < N; LC++) { int cou = 0; int LCi; for (int i = 0; i < N; i++) { if (L[i] == LC) { cou++; LCi = i; } } if (cou >= 2) { F = false; break; } else if (cou == 1) { for (int i = 0; i < N; i++) { if (i == LCi) continue; if (!X[LCi][i] && !X[i][LCi]) { X[LCi][i] = 1; W[LCi]++; L[i]++; } } } } for (int WC = 0; WC < N; WC++) { int cou = 0; int WCi; for (int i = 0; i < N; i++) { if (W[i] == WC) { cou++; WCi = i; } } if (cou >= 2) { F = false; break; } else if (cou == 1) { for (int i = 0; i < N; i++) { if (i == WCi) continue; if (!X[WCi][i] && !X[i][WCi]) { X[WCi][i] = 1; W[WCi]++; L[i]++; } } } } if (!F) { for (int LC = 0; LC < N; LC++) { int LCi = -1; for (int i = 0; i < N; i++) { if (L[i] == LC) { LCi = i; for (int j = 0; j < N; j++) { if (j == i) continue; if (!X[LCi][j] && !X[j][LCi]) { X[LCi][j] = 1; W[LCi]++; L[j]++; } } } } } } for (int i = 0; i < N; i++) { P[i] = make_pair(L[i], i); } sort(P, P + N); for (int i = 0; i < N; i++) printf("%d\n", P[i].second + 1); if (F) printf("0\n"); else printf("1\n"); return 0; }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int N, M; bool X[5000][5000]; int W[5000], L[5000]; pair<int, int> P[5000]; bool F = true; int main() { scanf("%d%d", &N, &M); for (int i = 0; i < M; i++) { int A, B; scanf("%d%d", &A, &B); X[A - 1][B - 1] = 1; W[A - 1]++; L[B - 1]++; } for (int LC = 0; LC < N; LC++) { int cou = 0; int LCi; for (int i = 0; i < N; i++) { if (L[i] == LC) { cou++; LCi = i; } } if (cou >= 2) { F = false; break; } else if (cou == 1) { for (int i = 0; i < N; i++) { if (i == LCi) continue; if (!X[LCi][i] && !X[i][LCi]) { X[LCi][i] = 1; W[LCi]++; L[i]++; } } } } for (int WC = 0; WC < N; WC++) { int cou = 0; int WCi; for (int i = 0; i < N; i++) { if (W[i] == WC) { cou++; WCi = i; } } if (cou >= 2) { F = false; break; } else if (cou == 1) { for (int i = 0; i < N; i++) { if (i == WCi) continue; if (!X[WCi][i] && !X[i][WCi]) { X[WCi][i] = 1; W[WCi]++; L[i]++; } } } } if (!F) { for (int LC = 0; LC < N; LC++) { int LCi = -1; for (int i = 0; i < N; i++) { if (L[i] == LC) { LCi = i; for (int j = 0; j < N; j++) { if (j == i) continue; if (!X[LCi][j] && !X[j][LCi]) { X[LCi][j] = 1; W[LCi]++; L[j]++; } } } } } } for (int i = 0; i < N; i++) { P[i] = make_pair(L[i], i); } sort(P, P + N); for (int i = 0; i < N; i++) printf("%d\n", P[i].second + 1); if (F) printf("0\n"); else printf("1\n"); return 0; }
replace
5
6
5
6
MLE
p00442
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define pb push_back #define all(c) c.begin(), c.end() const int MAX_N = 5000; // win[i]にjが含まれるならiはjに勝った // win[i]にjが含まれるならiはjに負けた vector<int> win[MAX_N + 1]; vector<int> lose[MAX_N + 1]; vector<int> ord; int used[MAX_N + 1] = {0}; // vがordに追加される時点で, // vから到達可能な全ての頂点,すなわち,vより順位が低いチームは,必ずordに追加されている void tsort(int v) { used[v] = true; for (int i = 0; i < lose[v].size(); i++) { if (!used[lose[v][i]]) tsort(win[v][i]); } ord.pb(v); } int main() { int n, m; cin >> n >> m; while (m--) { // 頂点w(winner), l(loser)を入力 int w, l; cin >> w >> l; // win[w]にlを含める // lose[l]にwを含める win[w].pb(l); lose[l].pb(w); } // この時点では誰が1位か分からないので, // 誰かに勝っていれば,自分を1位としてトポロジカルソートを行う for (int i = 1; i <= n; i++) if (!win[i].size()) tsort(i); // "他のソート結果が存在する"フラグ bool exi = 0; for (int i = 1; i < n; i++) { // "i位のチームにi+1位のチームが勝った"という情報が与えられているか? bool ok = find(all(lose[ord[i]]), ord[i - 1]) == lose[ord[i]].end(); exi |= ok; } // 順位を出力 for (int i = 0; i < ord.size(); i++) { cout << ord[i] << endl; } // 存在するかどうかを出力 cout << exi << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define pb push_back #define all(c) c.begin(), c.end() const int MAX_N = 5000; // win[i]にjが含まれるならiはjに勝った // win[i]にjが含まれるならiはjに負けた vector<int> win[MAX_N + 1]; vector<int> lose[MAX_N + 1]; vector<int> ord; int used[MAX_N + 1] = {0}; // vがordに追加される時点で, // vから到達可能な全ての頂点,すなわち,vより順位が低いチームは,必ずordに追加されている void tsort(int v) { used[v] = true; for (int i = 0; i < lose[v].size(); i++) { if (!used[lose[v][i]]) tsort(lose[v][i]); } ord.pb(v); } int main() { int n, m; cin >> n >> m; while (m--) { // 頂点w(winner), l(loser)を入力 int w, l; cin >> w >> l; // win[w]にlを含める // lose[l]にwを含める win[w].pb(l); lose[l].pb(w); } // この時点では誰が1位か分からないので, // 誰かに勝っていれば,自分を1位としてトポロジカルソートを行う for (int i = 1; i <= n; i++) if (!win[i].size()) tsort(i); // "他のソート結果が存在する"フラグ bool exi = 0; for (int i = 1; i < n; i++) { // "i位のチームにi+1位のチームが勝った"という情報が与えられているか? bool ok = find(all(lose[ord[i]]), ord[i - 1]) == lose[ord[i]].end(); exi |= ok; } // 順位を出力 for (int i = 0; i < ord.size(); i++) { cout << ord[i] << endl; } // 存在するかどうかを出力 cout << exi << endl; }
replace
23
24
23
24
-11
p00442
C++
Memory Limit Exceeded
// 0519-Worst Sportwriter #include <bits/stdc++.h> using namespace std; int data[5000][5000]; vector<int> win(5000); vector<int> unknown(5000); int main() { int n, m; cin >> n >> m; for (int t = 0; t < m; t++) { int i, j; cin >> i >> j; i--; j--; data[i][j] = 1; data[j][i] = -1; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (data[i][j] == 1) win[i]++; else if (data[i][j] == 0) unknown[i]++; } } vector<int> rank(n, 0); int another = 0; for (int i = 1; i <= n; i++) { int next = -1; int nwin = 0; for (int j = 0; j < n; j++) { if (win[j] == (n - i) && unknown[j] == 0) { rank[j] = i; cout << j + 1 << endl; next = -1; break; } else if (win[j] + unknown[j] == (n - i)) { if (rank[j] != 0) continue; if (next == -1) { next = j; nwin = win[j]; } else if (nwin < win[j]) { next = j; nwin = win[j]; another = 1; } else another = 1; } } if (next != -1) { rank[next] = i; cout << next + 1 << endl; for (int j = 0; j < n; j++) { if (next == j) continue; if (data[next][j] == 0) { data[next][j] = 1; data[j][next] = -1; unknown[j]--; } } win[next] += unknown[next]; unknown[next] = 0; } } cout << another << endl; return 0; }
// 0519-Worst Sportwriter #include <bits/stdc++.h> using namespace std; short data[5000][5000]; vector<int> win(5000); vector<int> unknown(5000); int main() { int n, m; cin >> n >> m; for (int t = 0; t < m; t++) { int i, j; cin >> i >> j; i--; j--; data[i][j] = 1; data[j][i] = -1; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (data[i][j] == 1) win[i]++; else if (data[i][j] == 0) unknown[i]++; } } vector<int> rank(n, 0); int another = 0; for (int i = 1; i <= n; i++) { int next = -1; int nwin = 0; for (int j = 0; j < n; j++) { if (win[j] == (n - i) && unknown[j] == 0) { rank[j] = i; cout << j + 1 << endl; next = -1; break; } else if (win[j] + unknown[j] == (n - i)) { if (rank[j] != 0) continue; if (next == -1) { next = j; nwin = win[j]; } else if (nwin < win[j]) { next = j; nwin = win[j]; another = 1; } else another = 1; } } if (next != -1) { rank[next] = i; cout << next + 1 << endl; for (int j = 0; j < n; j++) { if (next == j) continue; if (data[next][j] == 0) { data[next][j] = 1; data[j][next] = -1; unknown[j]--; } } win[next] += unknown[next]; unknown[next] = 0; } } cout << another << endl; return 0; }
replace
3
4
3
4
MLE
p00442
C++
Memory Limit Exceeded
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <vector> using namespace std; short table[5010][5010]; vector<int> e[5010], e2[5010]; int done[5010]; vector<int> tpr; void dfs(int x, int s) { if (done[x]) return; else done[x] = true; if (s != x) { table[x][s] = 1; table[s][x] = 2; } for (int i = 0; i < e[x].size(); i++) { dfs(e[x][i], s); } } void dfs2(int x) { if (done[x]) return; else done[x] = true; for (int i = 0; i < e2[x].size(); i++) { dfs2(e2[x][i]); } tpr.push_back(x); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; e[b].push_back(a); e2[a].push_back(b); table[a][b] = 1; table[b][a] = 2; } for (int i = 0; i < n; i++) { dfs(i, i); memset(done, 0, sizeof(done)); } for (int i = 0; i < n; i++) dfs2(i); int f = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { if (table[i][j] == 0) { f |= 1; } } } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int a = tpr[j]; int b = tpr[i]; table[a][b] = 1; table[b][a] = 2; } } vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < n; j++) if (table[i][j] == 1) cnt++; v.push_back(make_pair(cnt, i)); } sort(v.rbegin(), v.rend()); for (int i = 0; i < n; i++) cout << v[i].second + 1 << endl; cout << f << endl; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <vector> using namespace std; char table[5010][5010]; vector<int> e[5010], e2[5010]; int done[5010]; vector<int> tpr; void dfs(int x, int s) { if (done[x]) return; else done[x] = true; if (s != x) { table[x][s] = 1; table[s][x] = 2; } for (int i = 0; i < e[x].size(); i++) { dfs(e[x][i], s); } } void dfs2(int x) { if (done[x]) return; else done[x] = true; for (int i = 0; i < e2[x].size(); i++) { dfs2(e2[x][i]); } tpr.push_back(x); } int main() { int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--, b--; e[b].push_back(a); e2[a].push_back(b); table[a][b] = 1; table[b][a] = 2; } for (int i = 0; i < n; i++) { dfs(i, i); memset(done, 0, sizeof(done)); } for (int i = 0; i < n; i++) dfs2(i); int f = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) { if (table[i][j] == 0) { f |= 1; } } } } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int a = tpr[j]; int b = tpr[i]; table[a][b] = 1; table[b][a] = 2; } } vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < n; j++) if (table[i][j] == 1) cnt++; v.push_back(make_pair(cnt, i)); } sort(v.rbegin(), v.rend()); for (int i = 0; i < n; i++) cout << v[i].second + 1 << endl; cout << f << endl; }
replace
8
9
8
9
MLE
p00443
C++
Runtime Error
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual ///Studio 2015\Projects\programing_contest_c++\Debug\b.txt" long long int gcd(long long int l, long long int r) { assert(l > 0 && r > 0); if (l > r) return gcd(r, l); else { const long long int num = r % l; if (num) { return gcd(l, num); } else { return l; } } } long long int lca(long long int l, long long int r) { return l / gcd(l, r) * r; } struct mobi { long long int a; long long int b; int lid; int rid; }; long long int getans(const int id, const vector<mobi> &ms) { long long int lw = 0, rw = 0; if (ms[id].lid != -1) { lw = getans(ms[id].lid, ms); } else { lw = 1; } if (ms[id].rid != -1) { rw = getans(ms[id].rid, ms); } else { rw = 1; } long long int al = lw * ms[id].b; long long int ar = rw * ms[id].a; long long int alca = lca(al, ar); return alca / al * lw + alca / ar * rw; } int main() { while (1) { int N; cin >> N; if (!N) break; vector<mobi> ms; vector<int> pas(N); for (int i = 0; i < N; ++i) { long long int a, b; int lid, rid; cin >> a >> b >> lid >> rid; lid--; rid--; if (lid != -1) pas[lid] = true; if (rid != -1) pas[rid] = true; const long long int agcd = gcd(a, b); a /= agcd; b /= agcd; ms.push_back(mobi{a, b, lid, rid}); } int nopa = find(pas.begin(), pas.end(), 0) - pas.begin(); long long int ans = getans(nopa, ms); cout << ans << endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual ///Studio 2015\Projects\programing_contest_c++\Debug\b.txt" long long int gcd(long long int l, long long int r) { assert(l > 0 && r > 0); if (l > r) return gcd(r, l); else { const long long int num = r % l; if (num) { return gcd(l, num); } else { return l; } } } long long int lca(long long int l, long long int r) { return l / gcd(l, r) * r; } struct mobi { long long int a; long long int b; int lid; int rid; }; long long int getans(const int id, const vector<mobi> &ms) { long long int lw = 0, rw = 0; if (ms[id].lid != -1) { lw = getans(ms[id].lid, ms); } else { lw = 1; } if (ms[id].rid != -1) { rw = getans(ms[id].rid, ms); } else { rw = 1; } long long int al = lw * ms[id].a; long long int ar = rw * ms[id].b; long long int alca = lca(al, ar); return alca / al * lw + alca / ar * rw; } int main() { while (1) { int N; cin >> N; if (!N) break; vector<mobi> ms; vector<int> pas(N); for (int i = 0; i < N; ++i) { long long int a, b; int lid, rid; cin >> a >> b >> lid >> rid; lid--; rid--; if (lid != -1) pas[lid] = true; if (rid != -1) pas[rid] = true; const long long int agcd = gcd(a, b); a /= agcd; b /= agcd; ms.push_back(mobi{a, b, lid, rid}); } int nopa = find(pas.begin(), pas.end(), 0) - pas.begin(); long long int ans = getans(nopa, ms); cout << ans << endl; } return 0; }
replace
48
50
48
50
0
p00443
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; #define int long long #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, x, ...) x #define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal) #define REP2(i, s, n) REP1(i, s, < signed(n), ++) #define REP3(i, n) REP2(i, 0, n) #define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__) #define rrep(i, s) rep(i, s, >= 0, --) #define all(c) begin(c), end(c) template <typename T> bool maxup(T &a, const T &&b) { if (a < b) { a = b; return true; }; } template <typename T> bool maxup(T &a, const T &b) { if (a < b) { a = b; return true; }; } template <typename T> bool minup(T &a, const T &&b) { if (a > b) { a = b; return true; }; } template <typename T> bool minup(T &a, const T &b) { if (a > b) { a = b; return true; }; } #define X first #define Y second using VV = vector<vector<int>>; using V = vector<int>; using P = pair<int, int>; using IP = pair<int, P>; template <typename T> inline void input(vector<T> &v) { for (auto &x : v) cin >> x; } VV g; vector<P> len; int dfs(int now) { int a = g[now][0] >= 0 ? dfs(g[now][0]) : 1; int b = g[now][1] >= 0 ? dfs(g[now][1]) : 1; int p, q; tie(p, q) = len[now]; int gcd = __gcd(a * p, b * q); int x = b * q / gcd; int y = a * p / gcd; return a * x + b * y; } signed main() { int n; while (cin >> n && n) { g.clear(); g.resize(n); len.clear(); len.resize(n); V root(n, true); rep(i, n) { int p, q, r, b; cin >> p >> q >> r >> b; r--; b--; int gcd = __gcd(p, q); p = p / gcd; q = q / gcd; if (~r) root[r] = false; if (~b) root[b] = false; g[i].push_back(r); g[i].push_back(b); len[i] = P(p, q); } int idx = find(all(root), true) - root.begin(); cout << dfs(idx) << endl; } system("pause"); }
#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" using namespace std; #define int long long #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, x, ...) x #define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal) #define REP2(i, s, n) REP1(i, s, < signed(n), ++) #define REP3(i, n) REP2(i, 0, n) #define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__) #define rrep(i, s) rep(i, s, >= 0, --) #define all(c) begin(c), end(c) template <typename T> bool maxup(T &a, const T &&b) { if (a < b) { a = b; return true; }; } template <typename T> bool maxup(T &a, const T &b) { if (a < b) { a = b; return true; }; } template <typename T> bool minup(T &a, const T &&b) { if (a > b) { a = b; return true; }; } template <typename T> bool minup(T &a, const T &b) { if (a > b) { a = b; return true; }; } #define X first #define Y second using VV = vector<vector<int>>; using V = vector<int>; using P = pair<int, int>; using IP = pair<int, P>; template <typename T> inline void input(vector<T> &v) { for (auto &x : v) cin >> x; } VV g; vector<P> len; int dfs(int now) { int a = g[now][0] >= 0 ? dfs(g[now][0]) : 1; int b = g[now][1] >= 0 ? dfs(g[now][1]) : 1; int p, q; tie(p, q) = len[now]; int gcd = __gcd(a * p, b * q); int x = b * q / gcd; int y = a * p / gcd; return a * x + b * y; } signed main() { int n; while (cin >> n && n) { g.clear(); g.resize(n); len.clear(); len.resize(n); V root(n, true); rep(i, n) { int p, q, r, b; cin >> p >> q >> r >> b; r--; b--; int gcd = __gcd(p, q); p = p / gcd; q = q / gcd; if (~r) root[r] = false; if (~b) root[b] = false; g[i].push_back(r); g[i].push_back(b); len[i] = P(p, q); } int idx = find(all(root), true) - root.begin(); cout << dfs(idx) << endl; } // system("pause"); }
replace
95
96
95
96
0
sh: 1: pause: not found
p00444
C++
Time Limit Exceeded
//============================================================================ // Name : 0521.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> using namespace std; int main() { int x; int c[6] = {500, 100, 50, 10, 5, 1}; while (1) { int ans = 0; cin >> x; x = 1000 - x; if (x == 0) { break; } for (int i = 0; i < 6; i++) { ans = x / c[i] + ans; x = x % c[i]; } cout << ans << endl; } return 0; }
//============================================================================ // Name : 0521.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> using namespace std; int main() { int x; int c[6] = {500, 100, 50, 10, 5, 1}; while (1) { int ans = 0; cin >> x; x = 1000 - x; if (x == 1000) { break; } for (int i = 0; i < 6; i++) { ans = x / c[i] + ans; x = x % c[i]; } cout << ans << endl; } return 0; }
replace
18
19
18
19
TLE
p00444
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n, b; while (true) { cin >> b; n = 1000 - b; ; if (n == 0) { break; } cout << n / 500 + (n / 100) % 5 + (n / 50) % 2 + (n / 10) % 5 + (n / 5) % 2 + n % 5 << endl; } }
#include <iostream> using namespace std; int main() { int n, b; while (true) { cin >> b; n = 1000 - b; ; if (b == 0) { break; } cout << n / 500 + (n / 100) % 5 + (n / 50) % 2 + (n / 10) % 5 + (n / 5) % 2 + n % 5 << endl; } }
replace
8
9
8
9
TLE
p00444
C++
Time Limit Exceeded
#include <cstdio> using namespace std; int main() { int x, y; while (scanf("%d", &x) != 0) { x = 1000 - x; y = 0; while (x >= 500) { x -= 500; y++; } while (x >= 100) { x -= 100; y++; } while (x >= 50) { x -= 50; y++; } while (x >= 10) { x -= 10; y++; } while (x >= 5) { x -= 5; y++; } while (x >= 1) { x -= 1; y++; } printf("%d\n", y); } return 0; }
#include <cstdio> using namespace std; int main() { int x, y; while (scanf("%d", &x)) { if (x == 0) { break; } x = 1000 - x; y = 0; while (x >= 500) { x -= 500; y++; } while (x >= 100) { x -= 100; y++; } while (x >= 50) { x -= 50; y++; } while (x >= 10) { x -= 10; y++; } while (x >= 5) { x -= 5; y++; } while (x >= 1) { x -= 1; y++; } printf("%d\n", y); } return 0; }
replace
5
6
5
9
TLE
p00444
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int total; int change; int count = 0; while (true) { cin >> total; if (total == 0) { break; } change = 1000 - total; while (true) { if (change >= 500) { change -= 500; count++; } else if (change >= 100) { change -= 100; count++; } else if (change >= 50) { change -= 50; count++; } else if (change >= 10) { change -= 10; count++; } else if (change >= 5) { change -= 5; count++; } else { change--; count++; } } cout << count << "\n"; count = 0; } return 0; }
#include <iostream> using namespace std; int main() { int total; int change; int count = 0; while (true) { cin >> total; if (total == 0) { break; } change = 1000 - total; while (true) { if (change >= 500) { change -= 500; count++; } else if (change >= 100) { change -= 100; count++; } else if (change >= 50) { change -= 50; count++; } else if (change >= 10) { change -= 10; count++; } else if (change >= 5) { change -= 5; count++; } else { change--; count++; } if (change == 0) { break; } } cout << count << "\n"; count = 0; } return 0; }
insert
33
33
33
36
TLE
p00444
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int a, b, c, d, e, f, g; while (1) { cin >> a; if (a = 0) break; b = (1000 - a) / 500; c = (1000 - (a + 500 * b)) / 100; d = (1000 - (a + 500 * b + 100 * c)) / 50; e = (1000 - (a + 500 * b + 100 * c + 50 * d)) / 10; f = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e)) / 5; g = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e + 5 * f)) / 1; cout << b + c + d + e + f + g << endl; } return 0; }
#include <iostream> using namespace std; int main() { int a, b, c, d, e, f, g; while (1) { cin >> a; if (a == 0) break; b = (1000 - a) / 500; c = (1000 - (a + 500 * b)) / 100; d = (1000 - (a + 500 * b + 100 * c)) / 50; e = (1000 - (a + 500 * b + 100 * c + 50 * d)) / 10; f = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e)) / 5; g = (1000 - (a + 500 * b + 100 * c + 50 * d + 10 * e + 5 * f)) / 1; cout << b + c + d + e + f + g << endl; } return 0; }
replace
6
7
6
7
TLE
p00444
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) break; n = 1000 - n; int ans = 0, i; int w[6] = {500, 100, 50, 10, 5, 1}; for (i = 0; i <= 6; i++) { ans = ans + n / w[i]; n = n - n / w[i] * w[i]; } cout << ans << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) break; n = 1000 - n; int ans = 0, i; int w[6] = {500, 100, 50, 10, 5, 1}; for (i = 0; i <= 5; i++) { ans = ans + n / w[i]; n = n - n / w[i] * w[i]; } cout << ans << endl; } return 0; }
replace
12
13
12
13
0
p00445
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { char x[10005]; while (scanf("%s", &x)) { int k = 0, JOI = 0, IOI = 0; while (x[k + 2] != '\0') { if (x[k + 1] == 'O' && x[k + 2] == 'I') { if (x[k] == 'J') JOI++; if (x[k] == 'I') IOI++; } k++; } printf("%d\n%d\n", JOI, IOI); for (int i = 0; i < 10005; i++) x[i] = '\0'; } }
#include <iostream> using namespace std; int main() { char x[10005]; while (scanf("%s", &x) != EOF) { int k = 0, JOI = 0, IOI = 0; while (x[k + 2] != '\0') { if (x[k + 1] == 'O' && x[k + 2] == 'I') { if (x[k] == 'J') JOI++; if (x[k] == 'I') IOI++; } k++; } printf("%d\n%d\n", JOI, IOI); for (int i = 0; i < 10005; i++) x[i] = '\0'; } }
replace
5
6
5
6
TLE
p00445
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { char s[10010] = {0}; while (cin >> s) { int J = 0; int I = 0; int len = 0; while (1) { if (s[len] == 0) { break; } } for (int i = 0; i < len - 2; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') { J++; i++; } else if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') { I++; i++; } } cout << J << endl << I << endl; for (int i = 0; i < 10010; i++) { s[i] = 0; } } return 0; }
#include <iostream> using namespace std; int main() { char s[10010] = {0}; while (cin >> s) { int J = 0; int I = 0; int len = 0; while (1) { if (s[len] == 0) { break; } len++; } for (int i = 0; i < len - 2; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') { J++; i++; } else if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') { I++; i++; } } cout << J << endl << I << endl; for (int i = 0; i < 10010; i++) { s[i] = 0; } } return 0; }
insert
12
12
12
13
TLE
p00445
C++
Runtime Error
#include <iostream> using namespace std; int main() { while (true) { string s; cin >> s; // if(cin.eof()==false)break; int a = 0, b = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') { a += 1; } if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') { b += 1; } } cout << a << endl << b << endl; } return 0; }
#include <iostream> using namespace std; int main() { string s; while (cin >> s) { int a = 0, b = 0; for (int i = 0; i < s.size() - 1; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') { a += 1; } if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') { b += 1; } } cout << a << endl << b << endl; } return 0; }
replace
3
7
3
5
-11
p00445
C++
Time Limit Exceeded
#include <cstring> #include <iostream> using namespace std; char ary[10010]; int main() { int cnt, cnj, cni; while (true) { cin >> ary; if (ary[0] == (-1)) break; cnj = cni = 0; cnt = strlen(ary); for (int i = 2; i < cnt; i++) { if (ary[i] == 'I' && ary[i - 1] == 'O') { if (ary[i - 2] == 'J') cnj++; else if (ary[i - 2] == 'I') cni++; } } cout << cnj << endl << cni << endl; } return 0; }
#include <cstring> #include <iostream> using namespace std; char ary[10010]; int main() { int cnt, cnj, cni; while (true) { cin >> ary; if (cin.eof()) break; cnj = cni = 0; cnt = strlen(ary); for (int i = 2; i < cnt; i++) { if (ary[i] == 'I' && ary[i - 1] == 'O') { if (ary[i - 2] == 'J') cnj++; else if (ary[i - 2] == 'I') cni++; } } cout << cnj << endl << cni << endl; } return 0; }
replace
9
10
9
10
TLE
p00445
C++
Time Limit Exceeded
#include <cstdio> #include <cstring> using namespace std; char s[10002]; int J, I; int main() { while (1) { scanf("%s", s); if (s[0] == 0xff) return 0; J = 0; I = 0; for (int i = 0; i < strlen(s) - 2; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') J++; if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') I++; } printf("%d\n%d\n", J, I); } }
#include <cstdio> #include <cstring> using namespace std; char s[10002]; int J, I; int main() { while (scanf("%s", s) != EOF) { J = 0; I = 0; for (int i = 0; i < strlen(s) - 2; i++) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') J++; if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') I++; } printf("%d\n%d\n", J, I); } }
replace
6
10
6
7
TLE
p00445
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { for (;;) { char str[1000]; int joi = 0, ioi = 0, temp; if (scanf("%s", str) == EOF) { break; } // JOIツ板サツ津ィ for (int i = 2; str[i] != '\0'; i++) { if (str[i - 2] == 'J' && str[i - 1] == 'O' && str[i] == 'I') { joi++; } } for (int i = 0; str[i] != '\0'; i++) { if (str[i - 2] == 'I' && str[i - 1] == 'O' && str[i] == 'I') { ioi++; } } cout << joi << endl; cout << ioi << endl; } }
#include <iostream> #include <string> using namespace std; int main() { for (;;) { char str[10001]; int joi = 0, ioi = 0, temp; if (scanf("%s", str) == EOF) { break; } // JOIツ板サツ津ィ for (int i = 2; str[i] != '\0'; i++) { if (str[i - 2] == 'J' && str[i - 1] == 'O' && str[i] == 'I') { joi++; } } for (int i = 0; str[i] != '\0'; i++) { if (str[i - 2] == 'I' && str[i - 1] == 'O' && str[i] == 'I') { ioi++; } } cout << joi << endl; cout << ioi << endl; } }
replace
7
8
7
8
0
p00445
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, s, e) for (int i = int(s); i <= int(e); i++) #define rep(i, n) for (int i = 0; i < int(n); i++) int main() { while (true) { string s; cin >> s; if (s == "EOF") break; int n = s.size(); int a = 0; int b = 0; rep(i, n - 2) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') a++; if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') b++; } cout << a << endl; cout << b << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, s, e) for (int i = int(s); i <= int(e); i++) #define rep(i, n) for (int i = 0; i < int(n); i++) int main() { string s; while (cin >> s) { int n = s.size(); int a = 0; int b = 0; rep(i, n - 2) { if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') a++; if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') b++; } cout << a << endl; cout << b << endl; } return 0; }
replace
25
31
25
27
TLE
p00445
C++
Time Limit Exceeded
// https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0522?year=2008 #include <bits/stdc++.h> using namespace std; int main() { string s; while (true) { cin >> s; if (s.empty()) return 0; int joi = 0, ioi = 0; for (int i = 0; i < s.size() - 2; ++i) { if (s[i + 1] == 'O' and s[i + 2] == 'I') { if (s[i] == 'J') { joi++; } else if (s[i] == 'I') { ioi++; } } } cout << joi << endl; cout << ioi << endl; } } /* * substrでJOI,IOIをそれぞれ探したらTLEだったので * OIが共通なことを利用した。 * */
// https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0522?year=2008 #include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { int joi = 0, ioi = 0; for (int i = 0; i < s.size() - 2; ++i) { if (s[i + 1] == 'O' and s[i + 2] == 'I') { if (s[i] == 'J') { joi++; } else if (s[i] == 'I') { ioi++; } } } cout << joi << endl; cout << ioi << endl; } } /* * substrでJOI,IOIをそれぞれ探したらTLEだったので * OIが共通なことを利用した。 * */
replace
9
14
9
10
TLE
p00445
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> int i; int ioi = 0, joi = 0; std::string s; #define I if (s[i] == 'I') #define J if (s[i] == 'J') int main() { while (true) { std::cin >> s; if (s == "EOF" || s == "eof") break; for (i = 0; i < s.size(); i++) { I { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { ioi++; } } } J { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { joi++; } } } } std::cout << joi << std::endl; std::cout << ioi << std::endl; ioi = 0, joi = 0; } }
#include <algorithm> #include <iostream> #include <string> int i; int ioi = 0, joi = 0; std::string s; #define I if (s[i] == 'I') #define J if (s[i] == 'J') int main() { while (std::cin >> s) { for (i = 0; i < s.size(); i++) { I { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { ioi++; } } } J { if (s[i + 1] == 'O') { if (s[i + 2] == 'I') { joi++; } } } } std::cout << joi << std::endl; std::cout << ioi << std::endl; ioi = 0, joi = 0; } }
replace
9
13
9
10
TLE
p00445
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <queue> #include <vector> using namespace std; typedef long long ll; int main() { int I = 0, J = 0; char d[10000]; while (scanf("%s", d) && d[0]) { for (int i = 0; i < 10000; i++) if (d[i + 2] == 0) break; else { if (d[i + 1] == 'O' && d[i + 2] == 'I') { if (d[i] == 'J') J++; if (d[i] == 'I') I++; } } printf("%d\n%d\n", J, I); I = 0, J = 0; } }
#include <algorithm> #include <bits/stdc++.h> #include <queue> #include <vector> using namespace std; typedef long long ll; int main() { int I = 0, J = 0; char d[10000]; while (cin >> d) { for (int i = 0; i < 10000; i++) if (d[i + 2] == 0) break; else { if (d[i + 1] == 'O' && d[i + 2] == 'I') { if (d[i] == 'J') J++; if (d[i] == 'I') I++; } } printf("%d\n%d\n", J, I); I = 0, J = 0; } }
replace
10
11
10
11
TLE
p00445
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { while (true) { string line; cin >> line; if (line[0] == 'EOF') { break; } int joi = 0, ioi = 0; for (int i = 0; i < line.size() - 2; i++) { if (line[i + 1] == 'O' && line[i + 2] == 'I') { if (line[i] == 'J') { joi++; } else if (line[i] == 'I') { ioi++; } } } cout << joi << endl << ioi << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { while (true) { string line; cin >> line; if (!line.size()) { break; } int joi = 0, ioi = 0; for (int i = 0; i < line.size() - 2; i++) { if (line[i + 1] == 'O' && line[i + 2] == 'I') { if (line[i] == 'J') { joi++; } else if (line[i] == 'I') { ioi++; } } } cout << joi << endl << ioi << endl; } return 0; }
replace
8
9
8
9
-11
p00446
C++
Time Limit Exceeded
#include <algorithm> #include <stdio.h> using namespace std; int main(void) { int n, i, a[10], e[201], c, x, y, flg; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 1; i <= n * 2; i++) e[i] = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { e[a[i]] = 1; } x = n; y = n; flg = 0; while (1) { for (i = 1; i <= n * 2; i++) { if (flg == 0 && e[i] == 1) { x--; e[i] = 2; flg = 1; } else if (flg == 1 && e[i] == 0) { y--; e[i] = 2; flg = 0; } if (x == 0 || y == 0) break; } if (flg == 0) flg = 1; else flg = 0; if (x == 0 || y == 0) break; } printf("%d\n", y); printf("%d\n", x); } return 0; }
#include <algorithm> #include <stdio.h> using namespace std; int main(void) { int n, i, a[101], e[201], c, x, y, flg; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 1; i <= n * 2; i++) e[i] = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); } for (i = 0; i < n; i++) { e[a[i]] = 1; } x = n; y = n; flg = 0; while (1) { for (i = 1; i <= n * 2; i++) { if (flg == 0 && e[i] == 1) { x--; e[i] = 2; flg = 1; } else if (flg == 1 && e[i] == 0) { y--; e[i] = 2; flg = 0; } if (x == 0 || y == 0) break; } if (flg == 0) flg = 1; else flg = 0; if (x == 0 || y == 0) break; } printf("%d\n", y); printf("%d\n", x); } return 0; }
replace
4
5
4
5
TLE
p00446
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, ba, d, c1, c2; int tc, hc, flag; int taro[100], hana[100]; while (1) { int F[101] = {0}; ba = 0; cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) { cin >> d; F[d] = 1; } c1 = 0; c2 = 0; for (int i = 1; i <= N * 2; i++) { if (F[i] == 1) { taro[c1] = i; c1++; } else if (F[i] == 0) { hana[c2] = i; c2++; } } ///////////////////////////////////////////// tc = N; hc = N; flag = 0; while (1) { for (int i = 0; i < N; i++) { if (ba < taro[i]) { ba = taro[i]; flag = 1; taro[i] = 0; tc--; break; } } if (tc == 0) break; if (flag == 0) ba = 0; flag = 0; for (int i = 0; i < N; i++) { if (ba < hana[i]) { ba = hana[i]; flag = 1; hana[i] = 0; hc--; break; } } if (hc == 0) break; if (flag == 0) ba = 0; flag = 0; } cout << hc << endl << tc << endl; } return 0; }
#include <iostream> using namespace std; int main() { int N, ba, d, c1, c2; int tc, hc, flag; int taro[100], hana[100]; while (1) { int F[201] = {0}; ba = 0; cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) { cin >> d; F[d] = 1; } c1 = 0; c2 = 0; for (int i = 1; i <= N * 2; i++) { if (F[i] == 1) { taro[c1] = i; c1++; } else if (F[i] == 0) { hana[c2] = i; c2++; } } ///////////////////////////////////////////// tc = N; hc = N; flag = 0; while (1) { for (int i = 0; i < N; i++) { if (ba < taro[i]) { ba = taro[i]; flag = 1; taro[i] = 0; tc--; break; } } if (tc == 0) break; if (flag == 0) ba = 0; flag = 0; for (int i = 0; i < N; i++) { if (ba < hana[i]) { ba = hana[i]; flag = 1; hana[i] = 0; hc--; break; } } if (hc == 0) break; if (flag == 0) ba = 0; flag = 0; } cout << hc << endl << tc << endl; } return 0; }
replace
7
8
7
8
0
p00446
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <functional> using namespace std; int main() { while (1) { int n, x; int i, j; int tarou[110] = {0}, hanako[110] = {0}; int field = 0; int flg1 = 0, flg2 = 0; scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { scanf("%d", &x); tarou[x - 1] = x; } for (i = 0; i < n * 2; i++) { if (tarou[i] == 0) hanako[i] = i + 1; } sort(tarou, tarou + n * 2, greater<int>()); sort(hanako, hanako + n * 2, greater<int>()); sort(tarou, tarou + n); sort(hanako, hanako + n); while (1) { // 太郎の番 for (j = 0; j < n; j++) { if (field < tarou[j]) { field = tarou[j]; tarou[j] = -1; flg1++; goto next; } } field = 0; next: if (flg1 == n || flg2 == n) break; for (j = 0; j < n; j++) { if (field < hanako[j]) { field = hanako[j]; hanako[j] = -1; flg2++; goto next2; } } field = 0; next2: if (flg1 == n || flg2 == n) break; } printf("%d\n%d\n", n - flg2, n - flg1); } return 0; }
#include <algorithm> #include <cstdio> #include <functional> using namespace std; int main() { while (1) { int n, x; int i, j; int tarou[300] = {0}, hanako[300] = {0}; int field = 0; int flg1 = 0, flg2 = 0; scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { scanf("%d", &x); tarou[x - 1] = x; } for (i = 0; i < n * 2; i++) { if (tarou[i] == 0) hanako[i] = i + 1; } sort(tarou, tarou + n * 2, greater<int>()); sort(hanako, hanako + n * 2, greater<int>()); sort(tarou, tarou + n); sort(hanako, hanako + n); while (1) { // 太郎の番 for (j = 0; j < n; j++) { if (field < tarou[j]) { field = tarou[j]; tarou[j] = -1; flg1++; goto next; } } field = 0; next: if (flg1 == n || flg2 == n) break; for (j = 0; j < n; j++) { if (field < hanako[j]) { field = hanako[j]; hanako[j] = -1; flg2++; goto next2; } } field = 0; next2: if (flg1 == n || flg2 == n) break; } printf("%d\n%d\n", n - flg2, n - flg1); } return 0; }
replace
8
9
8
9
0
p00446
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int N; while (cin >> N, N) { vector<int> card[2]; int ba = -1, in; bool latte[101] = {}, turn = 0; for (int i = 0; i < N; i++) { cin >> in; latte[in] = true; } for (int i = 1; i <= 2 * N; i++) { card[!latte[i]].push_back(i); } sort(card[0].begin(), card[0].end()); sort(card[1].begin(), card[1].end()); while (card[0].size() && card[1].size()) { vector<int>::iterator itr = upper_bound(card[turn].begin(), card[turn].end(), ba); if (itr == card[turn].end()) ba = -1; else { ba = *itr; card[turn].erase(itr); } turn = !turn; } printf("%d\n%d\n", card[1].size(), card[0].size()); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int N; while (cin >> N, N) { vector<int> card[2]; int ba = -1, in; bool latte[201] = {}, turn = 0; for (int i = 0; i < N; i++) { cin >> in; latte[in] = true; } for (int i = 1; i <= 2 * N; i++) { card[!latte[i]].push_back(i); } sort(card[0].begin(), card[0].end()); sort(card[1].begin(), card[1].end()); while (card[0].size() && card[1].size()) { vector<int>::iterator itr = upper_bound(card[turn].begin(), card[turn].end(), ba); if (itr == card[turn].end()) ba = -1; else { ba = *itr; card[turn].erase(itr); } turn = !turn; } printf("%d\n%d\n", card[1].size(), card[0].size()); } return 0; }
replace
13
14
13
14
0
p00446
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define pb push_back #define x first #define y second int main() { int n; while (cin >> n) { if (n == 0) break; vi taro; rep(i, n) { int a; cin >> a; taro.pb(a); } vi hanako; for (int i = 1; i <= 10; i++) { bool flag = true; rep(j, n) { if (taro[j] == i) flag = false; } if (flag) hanako.pb(i); } sort(all(taro)); sort(all(hanako)); reverse(all(taro)); reverse(all(hanako)); int fie = -1; bool flag; bool pass = false; while (1) { flag = true; for (int i = n - 1; i >= 0; i--) { if (taro[i] > fie) { fie = taro[i]; taro[i] = -1; flag = false; pass = false; break; } } if (flag) { if (pass) break; fie = -1; pass = true; } flag = true; for (int i = n - 1; i >= 0; i--) { if (hanako[i] > fie) { fie = hanako[i]; hanako[i] = -1; flag = false; pass = false; break; } } if (flag) { if (pass) break; fie = -1; pass = true; } } sort(all(taro)); sort(all(hanako)); reverse(all(taro)); reverse(all(hanako)); for (int i = n - 1; i >= 0; i--) { if (taro.back() == -1) taro.pop_back(); else break; } for (int i = n - 1; i >= 0; i--) { if (hanako.back() == -1) hanako.pop_back(); else break; } cout << hanako.size() << endl; cout << taro.size() << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; typedef long long ll; #define dump(x) cerr << #x << " = " << (x) << endl #define rep(i, n) for (int i = 0; i < (n); i++) #define all(a) (a).begin(), (a).end() #define pb push_back #define x first #define y second int main() { int n; while (cin >> n) { if (n == 0) break; vi taro; rep(i, n) { int a; cin >> a; taro.pb(a); } vi hanako; for (int i = 1; i <= 2 * n; i++) { bool flag = true; rep(j, n) { if (taro[j] == i) flag = false; } if (flag) hanako.pb(i); } sort(all(taro)); sort(all(hanako)); reverse(all(taro)); reverse(all(hanako)); int fie = -1; bool flag; bool pass = false; while (1) { flag = true; for (int i = n - 1; i >= 0; i--) { if (taro[i] > fie) { fie = taro[i]; taro[i] = -1; flag = false; pass = false; break; } } if (flag) { if (pass) break; fie = -1; pass = true; } flag = true; for (int i = n - 1; i >= 0; i--) { if (hanako[i] > fie) { fie = hanako[i]; hanako[i] = -1; flag = false; pass = false; break; } } if (flag) { if (pass) break; fie = -1; pass = true; } } sort(all(taro)); sort(all(hanako)); reverse(all(taro)); reverse(all(hanako)); for (int i = n - 1; i >= 0; i--) { if (taro.back() == -1) taro.pop_back(); else break; } for (int i = n - 1; i >= 0; i--) { if (hanako.back() == -1) hanako.pop_back(); else break; } cout << hanako.size() << endl; cout << taro.size() << endl; } return 0; }
replace
48
49
48
49
0
p00446
C++
Runtime Error
#include <stdio.h> int main() { int c[101] = {0}, ba = 0, n, i, a, t = 0, o; while (1) { scanf("%d", &n); if (n == 0) { break; } for (i = 1; i <= n * 2; i++) { c[i] = 0; } ba = 0; t = 0; for (i = 0; i < n; i++) { scanf("%d", &a); c[a] = 1; } while (1) { if (ba == 0) { for (i = 1; i <= n * 2; i++) { if (c[i] == (t + 1) % 2) { ba = i; c[i] = 2; break; } } } else { o = 0; for (i = 1; i <= n * 2; i++) { if (c[i] == (t + 1) % 2 && ba < i) { o = 1; ba = i; c[i] = 2; break; } } if (o == 0) { ba = 0; } } o = 0; for (i = 1; i <= n * 2; i++) { if (c[i] == 1) { o = 2; } } if (o == 0) { break; } o = 1; for (i = 1; i <= n * 2; i++) { if (c[i] == 0) { o = 2; } } if (o == 1) { break; } t++; } int cnt = 0; if (o == 0) { for (i = 1; i <= n * 2; i++) { if (c[i] == o) { cnt++; } } printf("%d\n", cnt); printf("0\n"); } else { for (i = 1; i <= n * 2; i++) { if (c[i] == o) { cnt++; } } printf("0\n"); printf("%d\n", cnt); } } return 0; }
#include <stdio.h> int main() { int c[201] = {0}, ba = 0, n, i, a, t = 0, o; while (1) { scanf("%d", &n); if (n == 0) { break; } for (i = 1; i <= n * 2; i++) { c[i] = 0; } ba = 0; t = 0; for (i = 0; i < n; i++) { scanf("%d", &a); c[a] = 1; } while (1) { if (ba == 0) { for (i = 1; i <= n * 2; i++) { if (c[i] == (t + 1) % 2) { ba = i; c[i] = 2; break; } } } else { o = 0; for (i = 1; i <= n * 2; i++) { if (c[i] == (t + 1) % 2 && ba < i) { o = 1; ba = i; c[i] = 2; break; } } if (o == 0) { ba = 0; } } o = 0; for (i = 1; i <= n * 2; i++) { if (c[i] == 1) { o = 2; } } if (o == 0) { break; } o = 1; for (i = 1; i <= n * 2; i++) { if (c[i] == 0) { o = 2; } } if (o == 1) { break; } t++; } int cnt = 0; if (o == 0) { for (i = 1; i <= n * 2; i++) { if (c[i] == o) { cnt++; } } printf("%d\n", cnt); printf("0\n"); } else { for (i = 1; i <= n * 2; i++) { if (c[i] == o) { cnt++; } } printf("0\n"); printf("%d\n", cnt); } } return 0; }
replace
2
3
2
3
0
p00446
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; #define INF 1.1e9 #define LINF 1.1e18 #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define pf push_front #define fi first #define se second #define BIT(x, n) bitset<n>(x) typedef long long ll; typedef pair<int, int> P; typedef pair<P, int> PP; struct edge { int to, cost; edge(int t, int c) : to(t), cost(c) {} }; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; int ddx[] = {1, 1, 1, 0, -1, -1, -1, 0}, ddy[] = {1, 0, -1, -1, -1, 0, 1, 1}; ll mypow(ll x, ll n, ll m) { // xのn乗をmで割った余り if (n == 0) return 1; if (n % 2 == 0) return mypow(x * x % m, n / 2, m); else return x * mypow(x, n - 1, m) % m; } //----------------------------------------------------------------------------- int n; vector<int> ta, ha; set<int> st; bool used[201]; int ct, ch; void dfs(int now, int turn) { if (ct == 0) { cout << ch << endl << 0 << endl; return; } if (ch == 0) { cout << 0 << endl << ct << endl; return; } if (turn == 0) { bool flg = false; REP(i, ta.size()) { if (used[ta[i]]) continue; if (ta[i] > now) { used[ta[i]] = true; flg = true; ct--; dfs(ta[i], 1); break; } } if (!flg) { dfs(0, 1); } } else { bool flg = false; REP(i, ha.size()) { if (used[ha[i]]) continue; if (ha[i] > now) { used[ha[i]] = true; flg = true; ch--; dfs(ha[i], 0); break; } } if (!flg) { dfs(0, 0); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { cin >> n; if (n == 0) break; REP(i, n) { int vv; cin >> vv; st.insert(vv); } FOR(i, 1, 2 * n + 1) { if (st.find(i) == st.end()) ha.pb(i); else ta.pb(i); } ct = n, ch = n; dfs(0, 0); } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <math.h> #include <stdio.h> using namespace std; #define INF 1.1e9 #define LINF 1.1e18 #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define pf push_front #define fi first #define se second #define BIT(x, n) bitset<n>(x) typedef long long ll; typedef pair<int, int> P; typedef pair<P, int> PP; struct edge { int to, cost; edge(int t, int c) : to(t), cost(c) {} }; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; int ddx[] = {1, 1, 1, 0, -1, -1, -1, 0}, ddy[] = {1, 0, -1, -1, -1, 0, 1, 1}; ll mypow(ll x, ll n, ll m) { // xのn乗をmで割った余り if (n == 0) return 1; if (n % 2 == 0) return mypow(x * x % m, n / 2, m); else return x * mypow(x, n - 1, m) % m; } //----------------------------------------------------------------------------- int n; vector<int> ta, ha; set<int> st; bool used[201]; int ct, ch; void dfs(int now, int turn) { if (ct == 0) { cout << ch << endl << 0 << endl; return; } if (ch == 0) { cout << 0 << endl << ct << endl; return; } if (turn == 0) { bool flg = false; REP(i, ta.size()) { if (used[ta[i]]) continue; if (ta[i] > now) { used[ta[i]] = true; flg = true; ct--; dfs(ta[i], 1); break; } } if (!flg) { dfs(0, 1); } } else { bool flg = false; REP(i, ha.size()) { if (used[ha[i]]) continue; if (ha[i] > now) { used[ha[i]] = true; flg = true; ch--; dfs(ha[i], 0); break; } } if (!flg) { dfs(0, 0); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { cin >> n; ta.clear(), ha.clear(); st.clear(); REP(i, 201) used[i] = false; ct = 0, ch = 0; if (n == 0) break; REP(i, n) { int vv; cin >> vv; st.insert(vv); } FOR(i, 1, 2 * n + 1) { if (st.find(i) == st.end()) ha.pb(i); else ta.pb(i); } ct = n, ch = n; dfs(0, 0); } return 0; }
insert
96
96
96
100
TLE
p00446
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { int a; cin >> a; while (a != 0) { int b[100] = {0}, c[100] = {0}, d, e = 0, f[101] = {0}, g = 0, h = 0, i, k = 0, n = 0; h = 2 * a; for (i = 1; i <= a; i++) { cin >> d; f[d] = 1; } for (i = 1; i <= h; i++) { if (f[i] == 1) { b[e] = i; e++; } else { c[g] = i; g++; } } k = 0; g = 0; e = 0; int count = 0, j = 0, o = 0, p = 0, s = 0, l = 0, x = 0, z = 0; x = a; z = a; while (1) { if (k == 0) { for (i = 0; i < a; i++) { if (n < b[i]) { n = b[i]; b[i] = 0; l = 1; x--; break; } } if (l == 0) { n = 0; } l = 0; } if (x == 0) { break; } k = 1; if (k == 1) { for (g = 0; g < a; g++) { if (n < c[g]) { n = c[g]; c[g] = 0; s = 1; z--; break; } } if (s == 0) { n = 0; } s = 0; } k = 0; if (z == 0) { break; } } cout << z << endl << x << endl; cin >> a; } }
#include <iostream> using namespace std; int main(void) { int a; cin >> a; while (a != 0) { int b[10000] = {0}, c[10000] = {0}, d, e = 0, f[10000] = {0}, g = 0, h = 0, i, k = 0, n = 0; h = 2 * a; for (i = 1; i <= a; i++) { cin >> d; f[d] = 1; } for (i = 1; i <= h; i++) { if (f[i] == 1) { b[e] = i; e++; } else { c[g] = i; g++; } } k = 0; g = 0; e = 0; int count = 0, j = 0, o = 0, p = 0, s = 0, l = 0, x = 0, z = 0; x = a; z = a; while (1) { if (k == 0) { for (i = 0; i < a; i++) { if (n < b[i]) { n = b[i]; b[i] = 0; l = 1; x--; break; } } if (l == 0) { n = 0; } l = 0; } if (x == 0) { break; } k = 1; if (k == 1) { for (g = 0; g < a; g++) { if (n < c[g]) { n = c[g]; c[g] = 0; s = 1; z--; break; } } if (s == 0) { n = 0; } s = 0; } k = 0; if (z == 0) { break; } } cout << z << endl << x << endl; cin >> a; } }
replace
6
8
6
8
0
p00446
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n; while (cin >> n && n) { vector<int> a, b; bool used[105]; memset(used, 0, sizeof(used)); int x; rep(i, n) { cin >> x; used[x] = true; a.push_back(x); } sort(a.begin(), a.end()); REP(i, 1, 2 * n + 1) { if (used[i]) continue; b.push_back(i); } int res = 0, i = 0; while (true) { if (a.size() == 0 || b.size() == 0) break; if (i % 2 == 0) { vector<int>::iterator ite = upper_bound(a.begin(), a.end(), res); if (ite == a.end()) { res = 0; } else { res = *ite; a.erase(ite); } } else { vector<int>::iterator ite = upper_bound(b.begin(), b.end(), res); if (ite == b.end()) { res = 0; } else { res = *ite; b.erase(ite); } } i++; } cout << b.size() << endl; cout << a.size() << endl; } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n; while (cin >> n && n) { vector<int> a, b; bool used[205]; memset(used, 0, sizeof(used)); int x; rep(i, n) { cin >> x; used[x] = true; a.push_back(x); } sort(a.begin(), a.end()); REP(i, 1, 2 * n + 1) { if (used[i]) continue; b.push_back(i); } int res = 0, i = 0; while (true) { if (a.size() == 0 || b.size() == 0) break; if (i % 2 == 0) { vector<int>::iterator ite = upper_bound(a.begin(), a.end(), res); if (ite == a.end()) { res = 0; } else { res = *ite; a.erase(ite); } } else { vector<int>::iterator ite = upper_bound(b.begin(), b.end(), res); if (ite == b.end()) { res = 0; } else { res = *ite; b.erase(ite); } } i++; } cout << b.size() << endl; cout << a.size() << endl; } return 0; }
replace
23
24
23
24
0
p00446
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; while (true) { cin >> n; vector<int> taro, hanako; for (int i = 0; i < n; i++) { int a; cin >> a; taro.push_back(a); } sort(taro.begin(), taro.end()); for (int j = 1; j < taro[0]; j++) { hanako.push_back(j); } for (int i = 0; i < n - 1; i++) { for (int j = taro[i] + 1; j < taro[i + 1]; j++) { hanako.push_back(j); } } for (int j = taro[n - 1] + 1; j <= 2 * n; j++) { hanako.push_back(j); } int top = 0; vector<int>::iterator min; while (true) { min = lower_bound(taro.begin(), taro.end(), top); if (min == taro.end()) { top = 0; } else { top = *min; taro.erase(min); } if (taro.empty()) break; min = lower_bound(hanako.begin(), hanako.end(), top); if (min == hanako.end()) { top = 0; } else { top = *min; hanako.erase(min); } if (hanako.empty()) break; } cout << hanako.size() << '\n' << taro.size() << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n; while (true) { cin >> n; if (!n) break; vector<int> taro, hanako; for (int i = 0; i < n; i++) { int a; cin >> a; taro.push_back(a); } sort(taro.begin(), taro.end()); for (int j = 1; j < taro[0]; j++) { hanako.push_back(j); } for (int i = 0; i < n - 1; i++) { for (int j = taro[i] + 1; j < taro[i + 1]; j++) { hanako.push_back(j); } } for (int j = taro[n - 1] + 1; j <= 2 * n; j++) { hanako.push_back(j); } int top = 0; vector<int>::iterator min; while (true) { min = lower_bound(taro.begin(), taro.end(), top); if (min == taro.end()) { top = 0; } else { top = *min; taro.erase(min); } if (taro.empty()) break; min = lower_bound(hanako.begin(), hanako.end(), top); if (min == hanako.end()) { top = 0; } else { top = *min; hanako.erase(min); } if (hanako.empty()) break; } cout << hanako.size() << '\n' << taro.size() << endl; } return 0; }
insert
9
9
9
11
-11
p00446
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <vector> using namespace std; int main() { int n; while (scanf("%d", &n) != 0) { vector<int> t, h; for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); t.push_back(tmp); } for (int i = 0; i < 2 * n; i++) { bool find = false; for (int j = 0; j < n; j++) { if (t[j] == i + 1) { find = true; } } if (find == false) { h.push_back(i + 1); } find = false; } sort(t.begin(), t.end()); sort(h.begin(), h.end()); int b = 0; bool td = false; bool hd = false; while (1) { for (int i = 0; i < t.size(); i++) { if (t[i] > b) { b = t[i]; t.erase(t.begin() + i); td = true; break; } } if (td == false) { b = 0; } td = false; if (t.size() == 0) break; for (int i = 0; i < h.size(); i++) { if (h[i] > b) { b = h[i]; h.erase(h.begin() + i); hd = true; break; } } if (hd == false) { b = 0; } hd = false; if (h.size() == 0) break; } int ts = h.size(); int hs = t.size(); printf("%d\n%d\n", ts, hs); } return 0; }
#include <algorithm> #include <cstdio> #include <vector> using namespace std; int main() { int n; while (1) { scanf("%d", &n); if (n == 0) break; vector<int> t, h; for (int i = 0; i < n; i++) { int tmp; scanf("%d", &tmp); t.push_back(tmp); } for (int i = 0; i < 2 * n; i++) { bool find = false; for (int j = 0; j < n; j++) { if (t[j] == i + 1) { find = true; } } if (find == false) { h.push_back(i + 1); } find = false; } sort(t.begin(), t.end()); sort(h.begin(), h.end()); int b = 0; bool td = false; bool hd = false; while (1) { for (int i = 0; i < t.size(); i++) { if (t[i] > b) { b = t[i]; t.erase(t.begin() + i); td = true; break; } } if (td == false) { b = 0; } td = false; if (t.size() == 0) break; for (int i = 0; i < h.size(); i++) { if (h[i] > b) { b = h[i]; h.erase(h.begin() + i); hd = true; break; } } if (hd == false) { b = 0; } hd = false; if (h.size() == 0) break; } int ts = h.size(); int hs = t.size(); printf("%d\n%d\n", ts, hs); } return 0; }
replace
7
8
7
11
TLE
p00446
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int main() { while (1) { int n, a, t[100], h[100], b[101] = {}; int c = 0, d = 0, e = 0, ba = 0, ta = 0, ha = 0; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> a; b[a]++; } for (int i = 1; i <= n * 2; i++) { if (b[i] == 0) { h[c] = i; c++; } else { t[d] = i; d++; } } while (1) { int f = 0; for (int i = 0; i < n; i++) { if (t[i] > ba) { ba = t[i]; t[i] = 0; f++; ta++; break; } } if (f == 0) ba = 0; if (ta == n) break; f = 0; for (int i = 0; i < n; i++) { if (h[i] > ba) { ba = h[i]; h[i] = 0; f++; ha++; break; } } if (f == 0) ba = 0; if (ha == n) break; } printf("%d\n%d\n", n - ha, n - ta); } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { while (1) { int n, a, t[1000], h[1000], b[1000] = {}; int c = 0, d = 0, ba = 0, ta = 0, ha = 0; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> a; b[a]++; } for (int i = 1; i <= n * 2; i++) { if (b[i] == 0) { h[c] = i; c++; } else { t[d] = i; d++; } } while (1) { int f = 0; for (int i = 0; i < n; i++) { if (t[i] > ba) { ba = t[i]; t[i] = 0; f++; ta++; break; } } if (f == 0) ba = 0; if (ta == n) break; f = 0; for (int i = 0; i < n; i++) { if (h[i] > ba) { ba = h[i]; h[i] = 0; f++; ha++; break; } } if (f == 0) ba = 0; if (ha == n) break; } printf("%d\n%d\n", n - ha, n - ta); } return 0; }
replace
5
7
5
7
0
p00446
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define REP(i, n) for (int i = 0; i < n; ++i) using namespace std; // タロー→ハナァコォ const int NONE = -1; int main(void) { while (1) { int n; vector<int> card[2]; cin >> n; if (n == 0) return 0; int field = NONE; // 今場に出ているカード int turn = 0; // 0:太郎,1:花子; bool a[301] = {}; for (int i = 0; i < n; ++i) { int t; cin >> t; card[0].push_back(t); a[t] = true; } for (int i = 1; i <= 2 * n; ++i) { if (a[i] == false) card[1].push_back(i); } sort(card[0].begin(), card[0].end()); sort(card[1].begin(), card[1].end()); while (1) { if (card[0].empty() || card[0].empty()) break; if (field == NONE) { field = card[turn][0]; card[turn].erase(card[turn].begin()); } else { bool outFlag = false; for (int i = 0; i < card[turn].size(); ++i) { if (field < card[turn][i]) // 出せるカードがある { field = card[turn][i]; outFlag = true; card[turn].erase(card[turn].begin() + i); break; } } if (outFlag == false) { field = NONE; } } if (turn == 0) turn = 1; else if (turn == 1) turn = 0; } int tsum = 0; int hsum = 0; for (int i = 0; i < card[0].size(); ++i) { hsum += card[0][i]; } for (int j = 0; j < card[1].size(); ++j) { tsum += card[1][j]; } cout << card[1].size() << endl; cout << card[0].size() << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> #define REP(i, n) for (int i = 0; i < n; ++i) using namespace std; // タロー→ハナァコォ const int NONE = -1; int main(void) { while (1) { int n; vector<int> card[2]; cin >> n; if (n == 0) return 0; int field = NONE; // 今場に出ているカード int turn = 0; // 0:太郎,1:花子; bool a[301] = {}; for (int i = 0; i < n; ++i) { int t; cin >> t; card[0].push_back(t); a[t] = true; } for (int i = 1; i <= 2 * n; ++i) { if (a[i] == false) card[1].push_back(i); } sort(card[0].begin(), card[0].end()); sort(card[1].begin(), card[1].end()); while (1) { if (card[0].empty() || card[1].empty()) break; if (field == NONE) { field = card[turn][0]; card[turn].erase(card[turn].begin()); } else { bool outFlag = false; for (int i = 0; i < card[turn].size(); ++i) { if (field < card[turn][i]) // 出せるカードがある { field = card[turn][i]; outFlag = true; card[turn].erase(card[turn].begin() + i); break; } } if (outFlag == false) { field = NONE; } } if (turn == 0) turn = 1; else if (turn == 1) turn = 0; } int tsum = 0; int hsum = 0; for (int i = 0; i < card[0].size(); ++i) { hsum += card[0][i]; } for (int j = 0; j < card[1].size(); ++j) { tsum += card[1][j]; } cout << card[1].size() << endl; cout << card[0].size() << endl; } return 0; }
replace
40
41
40
41
0
p00447
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; #define FOR(i, a, b) for (int i = (a); i < (int)(b); i++) #define rep(i, n) FOR(i, 0, n) #define ZERO(a) memset(a, 0, sizeof(a)) #define pb push_back #define mp make_pair #define F first #define S second const int M = 1e6 + 10; bool px[M], py[M]; vector<P> tg, stars; // (x,y) void init(void) { ZERO(px); ZERO(py); tg.clear(); stars.clear(); } bool OK(int dx, int dy) { for (auto &t : tg) { if (!px[t.F + dx] or !py[t.S + dy]) return false; } return true; } int main() { int m, n; while (cin >> m && m) { init(); rep(i, m) { int x, y; scanf("%d%d", &x, &y); tg.pb(mp(x, y)); } cin >> n; rep(i, n) { int x, y; scanf("%d%d", &x, &y); stars.pb(mp(x, y)); px[x] = py[y] = true; } for (auto &star : stars) { int diffx = star.F - tg[0].F; int diffy = star.S - tg[0].S; if (OK(diffx, diffy)) { printf("%d %d\n", diffx, diffy); goto out; } } out: m += 0; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; #define FOR(i, a, b) for (int i = (a); i < (int)(b); i++) #define rep(i, n) FOR(i, 0, n) #define ZERO(a) memset(a, 0, sizeof(a)) #define pb push_back #define mp make_pair #define F first #define S second const int M = 1e6 + 10; bool px[M], py[M]; vector<P> tg, stars; // (x,y) void init(void) { ZERO(px); ZERO(py); tg.clear(); stars.clear(); } bool OK(int dx, int dy) { for (auto &t : tg) { if (t.F + dx > 1e6 or t.S + dy > 1e6) return false; if (!px[t.F + dx] or !py[t.S + dy]) return false; } return true; } int main() { int m, n; while (cin >> m && m) { init(); rep(i, m) { int x, y; scanf("%d%d", &x, &y); tg.pb(mp(x, y)); } cin >> n; rep(i, n) { int x, y; scanf("%d%d", &x, &y); stars.pb(mp(x, y)); px[x] = py[y] = true; } for (auto &star : stars) { int diffx = star.F - tg[0].F; int diffy = star.S - tg[0].S; if (OK(diffx, diffy)) { printf("%d %d\n", diffx, diffy); goto out; } } out: m += 0; } return 0; }
insert
25
25
25
27
0
p00447
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #define x first #define y second using namespace std; typedef pair<int, int> P; P hosi[100]; P hosi2[100]; P shift; bool flag; int main() { int m, n; while (1) { cin >> m; if (!m) break; for (int i = 0; i < m; i++) { cin >> hosi[i].x >> hosi[i].y; } cin >> n; for (int i = 0; i < n; i++) { cin >> hosi2[i].x >> hosi2[i].y; } sort(hosi, hosi + m); sort(hosi2, hosi2 + n); for (int i = 0; i < n; i++) { flag = true; shift.x = hosi2[i].x - hosi[0].x; shift.y = hosi2[i].y - hosi[0].y; for (int j = 0; j < m; j++) { if (!binary_search(hosi2, hosi2 + n, P(hosi[j].x + shift.x, hosi[j].y + shift.y))) { flag = false; break; } } if (flag == true) break; } cout << shift.x << " " << shift.y << endl; } }
#include <algorithm> #include <iostream> #include <map> #define x first #define y second using namespace std; typedef pair<int, int> P; P hosi[220]; P hosi2[1010]; P shift; bool flag; int main() { int m, n; while (1) { cin >> m; if (!m) break; for (int i = 0; i < m; i++) { cin >> hosi[i].x >> hosi[i].y; } cin >> n; for (int i = 0; i < n; i++) { cin >> hosi2[i].x >> hosi2[i].y; } sort(hosi, hosi + m); sort(hosi2, hosi2 + n); for (int i = 0; i < n; i++) { flag = true; shift.x = hosi2[i].x - hosi[0].x; shift.y = hosi2[i].y - hosi[0].y; for (int j = 0; j < m; j++) { if (!binary_search(hosi2, hosi2 + n, P(hosi[j].x + shift.x, hosi[j].y + shift.y))) { flag = false; break; } } if (flag == true) break; } cout << shift.x << " " << shift.y << endl; } }
replace
9
11
9
11
0
p00447
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #define sint(i) scanf("%d", &i) #define sintt(i, j) scanf("%d%d", &i, &j) #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int nx[200]; int ny[200]; int mx[200]; int my[200]; while (1) { int n; sint(n); if (n == 0) { break; } rep(i, n) { sintt(nx[i], ny[i]); } int m; sint(m); rep(i, m) { sintt(mx[i], my[i]); } rep(i, m) { rep(j, m) { int temp; if (mx[i] < mx[j]) { temp = mx[i]; mx[i] = mx[j]; mx[j] = temp; temp = my[i]; my[i] = my[j]; my[j] = temp; } } } rep(i, m) { int dx = mx[i] - nx[0]; int dy = my[i] - ny[0]; int flgg = 1; rep(j, n) { int flg = 0; rep(k, m) { if (nx[j] + dx == mx[k] && ny[j] + dy == my[k]) { flg = 1; break; } } if (flg == 0) { flgg = 0; break; } } if (flgg == 1) { printf("%d %d\n", dx, dy); break; } } } } /* 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 2 1 1 2 2 3 1 2 2 3 1 1 */
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #define sint(i) scanf("%d", &i) #define sintt(i, j) scanf("%d%d", &i, &j) #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int nx[200]; int ny[200]; int mx[1000]; int my[1000]; while (1) { int n; sint(n); if (n == 0) { break; } rep(i, n) { sintt(nx[i], ny[i]); } int m; sint(m); rep(i, m) { sintt(mx[i], my[i]); } rep(i, m) { rep(j, m) { int temp; if (mx[i] < mx[j]) { temp = mx[i]; mx[i] = mx[j]; mx[j] = temp; temp = my[i]; my[i] = my[j]; my[j] = temp; } } } rep(i, m) { int dx = mx[i] - nx[0]; int dy = my[i] - ny[0]; int flgg = 1; rep(j, n) { int flg = 0; rep(k, m) { if (nx[j] + dx == mx[k] && ny[j] + dy == my[k]) { flg = 1; break; } } if (flg == 0) { flgg = 0; break; } } if (flgg == 1) { printf("%d %d\n", dx, dy); break; } } } } /* 5 8 5 6 4 4 3 7 10 0 10 10 10 5 2 7 9 7 8 10 10 2 1 2 8 1 6 7 6 0 0 9 2 1 1 2 2 3 1 2 2 3 1 1 */
replace
13
15
13
15
0
p00447
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; typedef pair<int, int> PA; int main() { int m, n; PA seiza[200], hosi[200]; while (scanf("%d", &m), m) { for (int i = 0; i < m; i++) scanf("%d %d", &seiza[i].first, &seiza[i].second); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d", &hosi[i].first, &hosi[i].second); sort(hosi, hosi + n); for (int i = 0; i < n; i++) { int x = hosi[i].first - seiza[0].first; int y = hosi[i].second - seiza[0].second; for (int j = 1; j < m; j++) { if (binary_search(hosi, hosi + n, PA(seiza[j].first + x, seiza[j].second + y))) { if (j == m - 1) printf("%d %d\n", x, y); } else break; } } } return (0); }
#include <algorithm> #include <cstdio> using namespace std; typedef pair<int, int> PA; int main() { int m, n; PA seiza[200], hosi[1001]; while (scanf("%d", &m), m) { for (int i = 0; i < m; i++) scanf("%d %d", &seiza[i].first, &seiza[i].second); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d %d", &hosi[i].first, &hosi[i].second); sort(hosi, hosi + n); for (int i = 0; i < n; i++) { int x = hosi[i].first - seiza[0].first; int y = hosi[i].second - seiza[0].second; for (int j = 1; j < m; j++) { if (binary_search(hosi, hosi + n, PA(seiza[j].first + x, seiza[j].second + y))) { if (j == m - 1) printf("%d %d\n", x, y); } else break; } } } return (0); }
replace
6
7
6
7
0
p00448
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { while (1) { int h, w; cin >> h >> w; if (!h && !w) break; bool mp[11][1001]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> mp[i][j]; int ans = 0; for (int i = 0; i < (1 << h); i++) { int cnt = 0; for (int j = 0; j < w; j++) { int c = 0; for (int k = 0; k < h; k++) c += ((i >> k) & 1) ? !mp[k][j] : mp[k][j]; cnt += max(c, h - c); } ans = max(ans, cnt); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { while (1) { int h, w; cin >> h >> w; if (!h && !w) break; bool mp[11][10001]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> mp[i][j]; int ans = 0; for (int i = 0; i < (1 << h); i++) { int cnt = 0; for (int j = 0; j < w; j++) { int c = 0; for (int k = 0; k < h; k++) c += ((i >> k) & 1) ? !mp[k][j] : mp[k][j]; cnt += max(c, h - c); } ans = max(ans, cnt); } cout << ans << endl; } return 0; }
replace
9
11
9
10
0
p00448
C++
Runtime Error
#include <bitset> #include <cstdio> #include <iostream> using namespace std; #define MaxC 1000 #define MaxR 10 // bitset<MaxC> pan[MaxR]; int pan[MaxR][MaxC]; int R, C; int result = 0; void dfs( int index) { // sum表示已经得到的最大1的数目,dfs搜索当前行是否反转,得到最大的1的数 if (index == R) { int sum = 0; for (int i = 0; i < C; ++i) { // 列 int num = 0; for (int j = 0; j < R; ++j) { // 行 if (pan[j][i] == 1) num++; } sum += max(num, R - num); } result = max(result, sum); } else { dfs(index + 1); for (int i = 0; i < C; ++i) { if (pan[index][i] == 1) pan[index][i] = 0; else pan[index][i] = 1; } dfs(index + 1); } } int main() { while (cin >> R >> C && C != 0 && R != 0) { // cin>>R>>C; for (int i = 0; i < R; ++i) { for (int j = 0; j < C; ++j) { cin >> pan[i][j]; } } dfs(0); cout << result << endl; } return 0; }
#include <bitset> #include <cstdio> #include <iostream> using namespace std; #define MaxC 10000 #define MaxR 10 // bitset<MaxC> pan[MaxR]; int pan[MaxR][MaxC]; int R, C; int result = 0; void dfs( int index) { // sum表示已经得到的最大1的数目,dfs搜索当前行是否反转,得到最大的1的数 if (index == R) { int sum = 0; for (int i = 0; i < C; ++i) { // 列 int num = 0; for (int j = 0; j < R; ++j) { // 行 if (pan[j][i] == 1) num++; } sum += max(num, R - num); } result = max(result, sum); } else { dfs(index + 1); for (int i = 0; i < C; ++i) { if (pan[index][i] == 1) pan[index][i] = 0; else pan[index][i] = 1; } dfs(index + 1); } } int main() { while (cin >> R >> C && C != 0 && R != 0) { // cin>>R>>C; for (int i = 0; i < R; ++i) { for (int j = 0; j < C; ++j) { cin >> pan[i][j]; } } dfs(0); cout << result << endl; } return 0; }
replace
6
7
6
7
0
p00448
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) // #define int long long using namespace std; typedef long long ll; int R, C; int a[10][10000]; signed main() { while (true) { cin >> R >> C; // rep(i,R) rep(j,C) cin >> a[i][j]; rep(i, R) rep(j, C) scanf("%d", &a[i][j]); int ans = 0; for (int i = 0; i < 1 << R; i++) { int temp = 0; rep(j, C) { int one = 0; rep(k, R) { if ((i >> k & 1) && (a[k][j] == 0)) one++; else if (!(i >> k & 1) && (a[k][j] == 1)) one++; } temp += max(one, R - one); } ans = max(ans, temp); } cout << ans << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) // #define int long long using namespace std; typedef long long ll; int R, C; int a[10][10000]; signed main() { while (true) { cin >> R >> C; if (R == 0 && C == 0) break; // rep(i,R) rep(j,C) cin >> a[i][j]; rep(i, R) rep(j, C) scanf("%d", &a[i][j]); int ans = 0; for (int i = 0; i < 1 << R; i++) { int temp = 0; rep(j, C) { int one = 0; rep(k, R) { if ((i >> k & 1) && (a[k][j] == 0)) one++; else if (!(i >> k & 1) && (a[k][j] == 1)) one++; } temp += max(one, R - one); } ans = max(ans, temp); } cout << ans << endl; } }
insert
12
12
12
14
TLE
p00448
C++
Time Limit Exceeded
#include <iostream> using namespace std; int ary[20][10010]; int main() { int R, C, res, tmp, cnt; while (true) { cin >> R >> C; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cin >> ary[i][j]; } } res = 0; for (int i = 0; i < (1 << R); i++) { cnt = 0; for (int j = 0; j < C; j++) { tmp = 0; for (int k = 0; k < R; k++) { tmp += (ary[k][j] ^ ((i >> k) & 1)); } cnt += max(tmp, R - tmp); } res = max(res, cnt); } cout << res << endl; } return 0; }
#include <iostream> using namespace std; int ary[20][10010]; int main() { int R, C, res, tmp, cnt; while (true) { cin >> R >> C; if (R == 0 && C == 0) break; for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { cin >> ary[i][j]; } } res = 0; for (int i = 0; i < (1 << R); i++) { cnt = 0; for (int j = 0; j < C; j++) { tmp = 0; for (int k = 0; k < R; k++) { tmp += (ary[k][j] ^ ((i >> k) & 1)); } cnt += max(tmp, R - tmp); } res = max(res, cnt); } cout << res << endl; } return 0; }
insert
8
8
8
10
TLE
p00448
C++
Runtime Error
#include <algorithm> #include <iostream> #define rep2(i, b, n) for (int i = b; i < n; ++i) #define rep(i, n) rep2(i, 0, n) using namespace std; bool fd[10][10000]; int h, w; int search(int r) { int res = 0; if (r >= w) { rep(x, w) { int t_sum = 0; rep(y, h) { if (!fd[y][x]) ++t_sum; } res += max(t_sum, h - t_sum); } return res; } rep(i, w) { fd[r][i] = !fd[r][i]; } res = max(res, search(r + 1)); rep(i, w) { fd[r][i] = !fd[r][i]; } res = max(res, search(r + 1)); return res; } int main(void) { while (cin >> h >> w, h | w) { rep(y, h) rep(x, w) { cin >> fd[y][x]; } cout << search(0) << endl; } return 0; }
#include <algorithm> #include <iostream> #define rep2(i, b, n) for (int i = b; i < n; ++i) #define rep(i, n) rep2(i, 0, n) using namespace std; bool fd[10][10000]; int h, w; int search(int r) { int res = 0; if (r >= h) { rep(x, w) { int t_sum = 0; rep(y, h) { if (!fd[y][x]) ++t_sum; } res += max(t_sum, h - t_sum); } return res; } rep(i, w) { fd[r][i] = !fd[r][i]; } res = max(res, search(r + 1)); rep(i, w) { fd[r][i] = !fd[r][i]; } res = max(res, search(r + 1)); return res; } int main(void) { while (cin >> h >> w, h | w) { rep(y, h) rep(x, w) { cin >> fd[y][x]; } cout << search(0) << endl; } return 0; }
replace
14
15
14
15
0
p00448
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long #define FOR(i, j, k) for (int i = j; i < (int)k; ++i) #define rep(i, j) FOR(i, 0, j) #define INF (1 << 30) typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<P, int> Pi; const int MOD = 1e9 + 7; const int dy[] = {0, 0, 1, -1}; const int dx[] = {1, -1, 0, 0}; template <class T> void chmin(T &a, const T &b) { a = min(a, b); } template <class T> void chmax(T &a, const T &b) { a = max(a, b); } int r, c; int n[5][10000], ans = 0; bool use[10]; void dfs(int now) { if (now == r) { int res = 0; rep(j, c) { int count = 0; rep(i, r) { if ((use[i] && n[i][j]) || (!use[i] && !n[i][j])) ++count; } res += (r - count < count) ? count : r - count; } chmax(ans, res); return; } use[now] = true; dfs(now + 1); use[now] = false; dfs(now + 1); } signed main() { cin.tie(0); ios::sync_with_stdio(false); while ((cin >> r >> c), r | c) { ans = 0; rep(i, r) rep(j, c) cin >> n[i][j]; dfs(0); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long #define FOR(i, j, k) for (int i = j; i < (int)k; ++i) #define rep(i, j) FOR(i, 0, j) #define INF (1 << 30) typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<P, int> Pi; const int MOD = 1e9 + 7; const int dy[] = {0, 0, 1, -1}; const int dx[] = {1, -1, 0, 0}; template <class T> void chmin(T &a, const T &b) { a = min(a, b); } template <class T> void chmax(T &a, const T &b) { a = max(a, b); } int r, c; int n[10][10000], ans = 0; bool use[10]; void dfs(int now) { if (now == r) { int res = 0; rep(j, c) { int count = 0; rep(i, r) { if ((use[i] && n[i][j]) || (!use[i] && !n[i][j])) ++count; } res += (r - count < count) ? count : r - count; } chmax(ans, res); return; } use[now] = true; dfs(now + 1); use[now] = false; dfs(now + 1); } signed main() { cin.tie(0); ios::sync_with_stdio(false); while ((cin >> r >> c), r | c) { ans = 0; rep(i, r) rep(j, c) cin >> n[i][j]; dfs(0); cout << ans << endl; } return 0; }
replace
21
22
21
22
0
p00448
C++
Runtime Error
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; int R, C; const int MAX = 10000; bool senbei[10][MAX]; int count() { /*cout << "begin" << endl; for(int i = 0;i < R;i++){ for(int j = 0;j < C;j++){ cout << (int)senbei[i][j]; } cout << endl; } */ int ans = 0; for (int i = 0; i < C; i++) { int num = 0; for (int j = 0; j < R; j++) { if (senbei[j][i]) num++; } ans += max(num, R - num); } // cout << ans << endl; // cout << "end" << endl; return ans; } int dfs(int r) { if (r == 0) return count(); int ans = dfs(r - 1); for (int i = 0; i < C; ++i) senbei[r][i] = !senbei[r][i]; ans = max(dfs(r - 1), ans); for (int i = 0; i < C; ++i) senbei[r][i] = !senbei[r][i]; return ans; } int main() { ios::sync_with_stdio(false); while (cin >> R >> C && (R + C) > 0) { for (int r = 0; r < R; ++r) { for (int c = 0; c < C; ++c) { bool b; cin >> b; senbei[r][c] = b > 0 ? true : false; } } cout << dfs(R) << endl; } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; int R, C; const int MAX = 10000; bool senbei[MAX][MAX]; int count() { /*cout << "begin" << endl; for(int i = 0;i < R;i++){ for(int j = 0;j < C;j++){ cout << (int)senbei[i][j]; } cout << endl; } */ int ans = 0; for (int i = 0; i < C; i++) { int num = 0; for (int j = 0; j < R; j++) { if (senbei[j][i]) num++; } ans += max(num, R - num); } // cout << ans << endl; // cout << "end" << endl; return ans; } int dfs(int r) { if (r == 0) return count(); int ans = dfs(r - 1); for (int i = 0; i < C; ++i) senbei[r][i] = !senbei[r][i]; ans = max(dfs(r - 1), ans); for (int i = 0; i < C; ++i) senbei[r][i] = !senbei[r][i]; return ans; } int main() { ios::sync_with_stdio(false); while (cin >> R >> C && (R + C) > 0) { for (int r = 0; r < R; ++r) { for (int c = 0; c < C; ++c) { bool b; cin >> b; senbei[r][c] = b > 0 ? true : false; } } cout << dfs(R) << endl; } return 0; }
replace
18
19
18
19
0
p00448
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int g[11][1001]; int maxn; int r, c; void dfs(int step) { if (step == r) { int num = 0; for (int i = 0; i < c; ++i) { int res = 0; for (int j = 0; j < r; ++j) res += g[j][i]; num += max(res, r - res); } maxn = max(num, maxn); } else { dfs(step + 1); for (int j = 0; j < c; ++j) g[step][j] = !g[step][j]; dfs(step + 1); } } int main() { while (cin >> r >> c && r && c) { for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) cin >> g[i][j]; maxn = 0; dfs(0); cout << maxn << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int g[10][10000]; int maxn; int r, c; void dfs(int step) { if (step == r) { int num = 0; for (int i = 0; i < c; ++i) { int res = 0; for (int j = 0; j < r; ++j) res += g[j][i]; num += max(res, r - res); } maxn = max(num, maxn); } else { dfs(step + 1); for (int j = 0; j < c; ++j) g[step][j] = !g[step][j]; dfs(step + 1); } } int main() { while (cin >> r >> c && r && c) { for (int i = 0; i < r; ++i) for (int j = 0; j < c; ++j) cin >> g[i][j]; maxn = 0; dfs(0); cout << maxn << endl; } return 0; }
replace
3
4
3
4
0
p00448
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; bitset<maxn> cookie[10]; int main() { int R, C; while (cin >> R >> C && (R || C)) { int i, j; for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) { bool upward; cin >> upward; cookie[i][j] = upward; } int r = 1 << R; int res = 0; for (int i = 0; i < r; i++) { for (int j = 0; j < R; j++) { if (i & (1 << j)) cookie[i].flip(); } int ans = 0; for (int j = 0; j < C; j++) { int up = 0; for (int k = 0; k < R; k++) { if (cookie[k][j]) up++; } ans += max(up, R - up); } res = max(ans, res); for (int j = 0; j < R; j++) { if (i & (1 << j)) cookie[j].flip(); } } printf("%d\n", res); } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4 + 10; bitset<maxn> cookie[10]; int main() { int R, C; while (cin >> R >> C && (R || C)) { int i, j; for (int i = 0; i < R; i++) for (int j = 0; j < C; j++) { bool upward; cin >> upward; cookie[i][j] = upward; } int r = 1 << R; int res = 0; for (int i = 0; i < r; i++) { for (int j = 0; j < R; j++) { if (i & (1 << j)) cookie[j].flip(); } int ans = 0; for (int j = 0; j < C; j++) { int up = 0; for (int k = 0; k < R; k++) { if (cookie[k][j]) up++; } ans += max(up, R - up); } res = max(ans, res); for (int j = 0; j < R; j++) { if (i & (1 << j)) cookie[j].flip(); } } printf("%d\n", res); } }
replace
22
23
22
23
0
p00448
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, s, e) for (int i = int(s); i <= int(e); i++) #define rep(i, n) for (int i = 0; i < int(n); i++) int a[10][10000]; int R, C; int m = 0; void fr(int j) { rep(i, R) { if (a[i][j] == 0) a[i][j] = 1; else a[i][j] = 0; } } void fc(int i) { rep(j, C) { if (a[i][j] == 0) a[i][j] = 1; else a[i][j] = 0; } } void g(int k) { if (k == R) { rep(j, C) { int p = 0; rep(i, R) if (a[i][j] == 1) p++; if (p > R - p) fr(j); } int c = 0; rep(i, R) rep(j, C) if (a[i][j] == 0) c++; if (m < c) m = c; return; } g(k + 1); fc(k); g(k + 1); } int main() { while (true) { cin >> R >> C; rep(i, R) rep(j, C) cin >> a[i][j]; g(0); cout << m << endl; rep(i, R) rep(j, C) a[i][j] = 0; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, s, e) for (int i = int(s); i <= int(e); i++) #define rep(i, n) for (int i = 0; i < int(n); i++) int a[10][10000]; int R, C; int m = 0; void fr(int j) { rep(i, R) { if (a[i][j] == 0) a[i][j] = 1; else a[i][j] = 0; } } void fc(int i) { rep(j, C) { if (a[i][j] == 0) a[i][j] = 1; else a[i][j] = 0; } } void g(int k) { if (k == R) { rep(j, C) { int p = 0; rep(i, R) if (a[i][j] == 1) p++; if (p > R - p) fr(j); } int c = 0; rep(i, R) rep(j, C) if (a[i][j] == 0) c++; if (m < c) m = c; return; } g(k + 1); fc(k); g(k + 1); } int main() { while (true) { cin >> R >> C; if (R == 0 && C == 0) break; rep(i, R) rep(j, C) cin >> a[i][j]; g(0); cout << m << endl; rep(i, R) rep(j, C) a[i][j] = 0; } return 0; }
insert
78
78
78
81
TLE
p00448
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) typedef bitset<1000> bs; int R, C; int check(const vector<bs> &s) { int res = 0; rep(j, C) { int cnt = 0; rep(i, R) if (s[i][j]) cnt++; res += max(cnt, R - cnt); } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> R >> C && R) { vector<bs> senbei(R, bs(0)); bool in_; rep(i, R) rep(j, C) { cin >> in_; if (in_) senbei[i][j] = 1; } bs to_rev(0); rep(i, C) to_rev[i] = 1; vector<bs> temp; int ans = 0; rep(S, 1 << R) { temp = senbei; rep(i, R) if ((S >> i) & 1) temp[i] ^= to_rev; ans = max(ans, check(temp)); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) typedef bitset<10000> bs; int R, C; int check(const vector<bs> &s) { int res = 0; rep(j, C) { int cnt = 0; rep(i, R) if (s[i][j]) cnt++; res += max(cnt, R - cnt); } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> R >> C && R) { vector<bs> senbei(R, bs(0)); bool in_; rep(i, R) rep(j, C) { cin >> in_; if (in_) senbei[i][j] = 1; } bs to_rev(0); rep(i, C) to_rev[i] = 1; vector<bs> temp; int ans = 0; rep(S, 1 << R) { temp = senbei; rep(i, R) if ((S >> i) & 1) temp[i] ^= to_rev; ans = max(ans, check(temp)); } cout << ans << endl; } return 0; }
replace
5
6
5
6
0
p00448
C++
Runtime Error
#include <algorithm> #include <stdio.h> using namespace std; int sen[20][10010]; int tate, yoko; int cou(int sum[10010][2], int row) { if (row == tate) { int ans = 0; for (int i = 0; i < yoko; i++) ans = ans + max(sum[i][0], sum[i][1]); return ans; } int sum0[10010][2] = {0}, sum1[10010][2] = {0}, ans0, ans1; for (int i = 0; i < yoko; i++) { sum0[i][0] = sum[i][0]; sum0[i][1] = sum[i][1]; sum1[i][0] = sum[i][0]; sum1[i][1] = sum[i][1]; if (sen[i][row] == 0) { sum0[i][0]++; sum1[i][1]++; } else { sum0[i][1]++; sum1[i][0]++; } } ans0 = cou(sum0, row + 1); ans1 = cou(sum1, row + 1); return max(ans0, ans1); } int main() { while (scanf("%d%d", &tate, &yoko), tate + yoko) { int sam[10010][2] = {0}; for (int i = 0; i < tate; i++) for (int j = 0; j < yoko; j++) scanf("%d", &sen[j][i]); printf("%d\n", cou(sam, 0)); } return 0; }
#include <algorithm> #include <stdio.h> using namespace std; int sen[10010][20]; int tate, yoko; int cou(int sum[10010][2], int row) { if (row == tate) { int ans = 0; for (int i = 0; i < yoko; i++) ans = ans + max(sum[i][0], sum[i][1]); return ans; } int sum0[10010][2] = {0}, sum1[10010][2] = {0}, ans0, ans1; for (int i = 0; i < yoko; i++) { sum0[i][0] = sum[i][0]; sum0[i][1] = sum[i][1]; sum1[i][0] = sum[i][0]; sum1[i][1] = sum[i][1]; if (sen[i][row] == 0) { sum0[i][0]++; sum1[i][1]++; } else { sum0[i][1]++; sum1[i][0]++; } } ans0 = cou(sum0, row + 1); ans1 = cou(sum1, row + 1); return max(ans0, ans1); } int main() { while (scanf("%d%d", &tate, &yoko), tate + yoko) { int sam[10010][2] = {0}; for (int i = 0; i < tate; i++) for (int j = 0; j < yoko; j++) scanf("%d", &sen[j][i]); printf("%d\n", cou(sam, 0)); } return 0; }
replace
3
4
3
4
0
p00448
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <string.h> #include <string> #include <vector> using namespace std; int R, C; const int MAX_R = 12; const int MAX_C = 10020; bool omote[MAX_R][MAX_C]; int avai[MAX_C]; int avai_ori[MAX_C]; // 変化させない int main(int argc, const char *argv[]) { while (true) { scanf("%d %d", &R, &C); if (R == 0 && C == 0) break; int ret = 0; memset(avai_ori, 0, sizeof(avai_ori)); memset(avai, 0, sizeof(avai)); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { int n; scanf("%d", &n); // 表なら1,裏なら0 omote[i][j] = n; if (n == 0) { // 裏の場合 avai[j]++; avai_ori[j]++; } } } for (int i = 0; i < (1 << R); i++) { for (int j = 0; j < C; j++) avai[j] = avai_ori[j]; for (int j = 0; j < R; j++) { if ((i >> j) & 1) { // j行目を裏返す場合 for (int k = 0; k < C; k++) { if (omote[i][j]) { if (omote[j][k]) avai[k]++; else avai[k]--; } } } } int sum = 0; for (int j = 0; j < C; j++) { sum += max(avai[j], R - avai[j]); } ret = max(ret, sum); } printf("%d\n", ret); } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <string.h> #include <string> #include <vector> using namespace std; int R, C; const int MAX_R = 12; const int MAX_C = 10020; bool omote[MAX_R][MAX_C]; int avai[MAX_C]; int avai_ori[MAX_C]; // 変化させない int main(int argc, const char *argv[]) { while (true) { scanf("%d %d", &R, &C); if (R == 0 && C == 0) break; int ret = 0; memset(avai_ori, 0, sizeof(avai_ori)); memset(avai, 0, sizeof(avai)); for (int i = 0; i < R; i++) { for (int j = 0; j < C; j++) { int n; scanf("%d", &n); // 表なら1,裏なら0 omote[i][j] = n; if (n == 0) { // 裏の場合 avai[j]++; avai_ori[j]++; } } } for (int i = 0; i < (1 << R); i++) { for (int j = 0; j < C; j++) avai[j] = avai_ori[j]; for (int j = 0; j < R; j++) { if ((i >> j) & 1) { // j行目を裏返す場合 for (int k = 0; k < C; k++) { if (omote[j][k]) avai[k]++; else avai[k]--; } } } int sum = 0; for (int j = 0; j < C; j++) { sum += max(avai[j], R - avai[j]); } ret = max(ret, sum); } printf("%d\n", ret); } return 0; }
replace
40
46
40
44
0
p00448
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int r, c; vector<vector<int>> field; int search() { int counter; int max_num = 0; counter = 1 << r; for (int i = 0; i < counter; i++) { int num = 0; for (int j = 0; j < r; j++) { if ((i >> j) & 1) { for (int k = 0; k < c; k++) { field[j][k] ^= 1; } } } for (int j = 0; j < c; j++) { int co_num = 0; for (int k = 0; k < r; k++) { co_num += field[k][j]; } if (co_num <= r / 2) { num += r - co_num; } else { num += co_num; /*reverse*/ } } if (max_num < num) { max_num = num; } for (int j = 0; j < r; j++) { if ((i >> j) & 1) { for (int k = 0; k < c; k++) { field[j][k] ^= 1; } } } } return max_num; } int main(int argc, char **argv) { cin >> r >> c; while (r != 0 && c != 0) { for (int i = 0; i < r; i++) { field.push_back(vector<int>(c)); for (int j = 0; j < c; j++) { cin >> field[i][j]; } } cout << search() << endl; cin >> r >> c; } return 0; }
#include <iostream> #include <vector> using namespace std; int r, c; vector<vector<int>> field; int search() { int counter; int max_num = 0; counter = 1 << r; for (int i = 0; i < counter; i++) { int num = 0; for (int j = 0; j < r; j++) { if ((i >> j) & 1) { for (int k = 0; k < c; k++) { field[j][k] ^= 1; } } } for (int j = 0; j < c; j++) { int co_num = 0; for (int k = 0; k < r; k++) { co_num += field[k][j]; } if (co_num <= r / 2) { num += r - co_num; } else { num += co_num; /*reverse*/ } } if (max_num < num) { max_num = num; } for (int j = 0; j < r; j++) { if ((i >> j) & 1) { for (int k = 0; k < c; k++) { field[j][k] ^= 1; } } } } return max_num; } int main(int argc, char **argv) { cin >> r >> c; while (r != 0 && c != 0) { field.clear(); for (int i = 0; i < r; i++) { field.push_back(vector<int>(c)); for (int j = 0; j < c; j++) { cin >> field[i][j]; } } cout << search() << endl; cin >> r >> c; } return 0; }
insert
57
57
57
58
0
p00448
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; int bd[10][1000]; int main() { while (1) { int r, c; scanf(" %d %d", &r, &c); if (r == 0 && c == 0) break; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { scanf(" %d", &bd[i][j]); } } int ans = -1; int up = (1 << r); for (int sl = 0; sl < up; sl++) { int h = sl; for (int i = 0; i < r; i++) { if (h % 2 == 1) { for (int j = 0; j < c; j++) { bd[i][j] = (bd[i][j] == 0) ? 1 : 0; } } h /= 2; } int cnt = 0; for (int j = 0; j < c; j++) { int sm = 0; for (int i = 0; i < r; i++) { sm += bd[i][j]; } cnt += max(r - sm, sm); } ans = max(cnt, ans); h = sl; for (int i = 0; i < r; i++) { if (h % 2 == 1) { for (int j = 0; j < c; j++) { bd[i][j] = (bd[i][j] == 0) ? 1 : 0; } } h /= 2; } } printf("%d\n", ans); } return 0; }
#include <algorithm> #include <cstdio> using namespace std; int bd[10][10000]; int main() { while (1) { int r, c; scanf(" %d %d", &r, &c); if (r == 0 && c == 0) break; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { scanf(" %d", &bd[i][j]); } } int ans = -1; int up = (1 << r); for (int sl = 0; sl < up; sl++) { int h = sl; for (int i = 0; i < r; i++) { if (h % 2 == 1) { for (int j = 0; j < c; j++) { bd[i][j] = (bd[i][j] == 0) ? 1 : 0; } } h /= 2; } int cnt = 0; for (int j = 0; j < c; j++) { int sm = 0; for (int i = 0; i < r; i++) { sm += bd[i][j]; } cnt += max(r - sm, sm); } ans = max(cnt, ans); h = sl; for (int i = 0; i < r; i++) { if (h % 2 == 1) { for (int j = 0; j < c; j++) { bd[i][j] = (bd[i][j] == 0) ? 1 : 0; } } h /= 2; } } printf("%d\n", ans); } return 0; }
replace
5
6
5
6
0
p00448
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int x[10][10000], H, W; int main() { while (true) { cin >> H >> W; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cin >> x[i][j]; } int maxn = 0; for (int i = 0; i < (1 << H); i++) { int cnt = 0; for (int j = 0; j < W; j++) { int r = 0; for (int k = 0; k < H; k++) { int Y = (i / (1 << k)) % 2; r += (x[k][j] + Y) % 2; } cnt += max(r, H - r); } maxn = max(maxn, cnt); } cout << maxn << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int x[10][10000], H, W; int main() { while (true) { cin >> H >> W; if (H + W == 0) break; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) cin >> x[i][j]; } int maxn = 0; for (int i = 0; i < (1 << H); i++) { int cnt = 0; for (int j = 0; j < W; j++) { int r = 0; for (int k = 0; k < H; k++) { int Y = (i / (1 << k)) % 2; r += (x[k][j] + Y) % 2; } cnt += max(r, H - r); } maxn = max(maxn, cnt); } cout << maxn << endl; } return 0; }
insert
7
7
7
9
TLE
p00449
C++
Runtime Error
#include <iostream> #include <map> #include <queue> #include <vector> using namespace std; typedef pair<int, int> Pi; struct edge { int to, cost; }; typedef vector<vector<edge>> Graph; int Dijkstr(Graph &info, int s, int g) { // if(info.size() <= 0) return -1; vector<int> min_cost; // その場の最小値 priority_queue<Pi, vector<Pi>, greater<Pi>> que; min_cost.resize(info.size(), -1); que.push(Pi(0, s)); min_cost[s] = 0; while (!que.empty()) { Pi p = que.top(); que.pop(); if (p.second == g) return p.first; if (p.first > min_cost[p.second]) continue; for (int i = 0; i < info[p.second].size(); i++) { edge &e = info[p.second][i]; if (min_cost[e.to] == -1 || e.to + p.first < min_cost[e.to]) { min_cost[e.to] = p.first + e.cost; que.push(Pi(min_cost[e.to], e.to)); } } } return -1; } int main() { int n, k, sele, a, b, c, d, e; while (cin >> n >> k, n) { // nが0以外の間 Graph info; info.resize(k); for (int i = 0; i < k; i++) { cin >> sele; if (sele == 0) { cin >> a >> b; // aからbへの経路探索 cout << Dijkstr(info, a, b) << endl; } else if (sele == 1) { cin >> c >> d >> e; info[c].push_back((edge){d, e}); info[d].push_back((edge){c, e}); // cout << "ehehe" << endl; } } } }
#include <iostream> #include <map> #include <queue> #include <vector> using namespace std; typedef pair<int, int> Pi; struct edge { int to, cost; }; typedef vector<vector<edge>> Graph; int Dijkstr(Graph &info, int s, int g) { // if(info.size() <= 0) return -1; vector<int> min_cost; // その場の最小値 priority_queue<Pi, vector<Pi>, greater<Pi>> que; min_cost.resize(info.size(), -1); que.push(Pi(0, s)); min_cost[s] = 0; while (!que.empty()) { Pi p = que.top(); que.pop(); if (p.second == g) return p.first; if (p.first > min_cost[p.second]) continue; for (int i = 0; i < info[p.second].size(); i++) { edge &e = info[p.second][i]; if (min_cost[e.to] == -1 || e.cost + p.first < min_cost[e.to]) { min_cost[e.to] = p.first + e.cost; que.push(Pi(min_cost[e.to], e.to)); } } } return -1; } int main() { int n, k, sele, a, b, c, d, e; while (cin >> n >> k, n) { // nが0以外の間 Graph info; info.resize(k); for (int i = 0; i < k; i++) { cin >> sele; if (sele == 0) { cin >> a >> b; // aからbへの経路探索 cout << Dijkstr(info, a, b) << endl; } else if (sele == 1) { cin >> c >> d >> e; info[c].push_back((edge){d, e}); info[d].push_back((edge){c, e}); // cout << "ehehe" << endl; } } } }
replace
31
32
31
32
0
p00449
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define ALL(g) (g).begin(), (g).end() #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define F(i, j, k) fill(i[0], i[0] + j * j, k) #define P(p) cout << (p) << endl; #define EXIST(s, e) ((s).find(e) != (s).end()) #define INF 1 << 25 #define pb push_back typedef vector<int> vi; typedef vector<long long> vl; typedef vector<double> vd; typedef pair<int, int> pii; typedef pair<long, long> pll; typedef long long ll; int main() { int n, k; int cost[101][101]; while (cin >> n >> k, n | k) { fill_n((int *)cost, 101 * 101, INF); bool ifwf = false; for (int cnt = 0; cnt < k; cnt++) { int z; if (cin >> z, z == 1) { int c, d, e; cin >> c >> d >> e; cost[c][d] = cost[d][c] = min(cost[c][d], e); ifwf = true; } else { if (ifwf) { for (int l = 1; l <= n; l++) { for (int i = 0; i <= n; i++) { for (int j = 1; j <= n; j++) { cost[i][j] = cost[j][i] = min(cost[i][j], cost[i][l] + cost[l][j]); } } } ifwf = false; } int a, b; cin >> a >> b; if (cost[a][b] != INF) cout << cost[a][b] << endl; else cout << -1 << endl; } } } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; #define ALL(g) (g).begin(), (g).end() #define REP(i, x, n) for (int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define F(i, j, k) fill(i[0], i[0] + j * j, k) #define P(p) cout << (p) << endl; #define EXIST(s, e) ((s).find(e) != (s).end()) #define INF 1 << 25 #define pb push_back typedef vector<int> vi; typedef vector<long long> vl; typedef vector<double> vd; typedef pair<int, int> pii; typedef pair<long, long> pll; typedef long long ll; int main() { int n, k; int cost[101][101]; while (cin >> n >> k, n | k) { fill_n((int *)cost, 101 * 101, INF); bool ifwf = false; for (int cnt = 0; cnt < k; cnt++) { int z; if (cin >> z, z == 1) { int c, d, e; cin >> c >> d >> e; cost[c][d] = cost[d][c] = min(cost[c][d], e); ifwf = true; } else { if (ifwf) { for (int l = 1; l <= n; l++) { for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { cost[i][j] = cost[j][i] = min(cost[i][j], cost[i][l] + cost[l][j]); } } } ifwf = false; } int a, b; cin >> a >> b; if (cost[a][b] != INF) cout << cost[a][b] << endl; else cout << -1 << endl; } } } return 0; }
replace
55
57
55
57
TLE
p00449
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define all(c) (c).begin(), (c).end() #define pb push_back #define mp make_pair #define ERASE(v, i) (v).erase(remove(all(v), i), (v).end()) #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define each(it, c) \ for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define debug(x) cerr << #x << " = " << (x) << endl; #define LINE cerr << "LINE: " << __LINE__ << endl; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> void preview(T a, T b) { for (T it = a; it != b; ++it) cerr << *it << " "; cerr << endl; } const int INF = 100000000; const double PI = acos(-1.0), EPS = 1e-10; int dist[101][101]; int main() { for (int n, k; cin >> n >> k, n || k;) { for (int i = 1; i <= n; i++) fill(dist[i], dist[i] + 101, INF); for (int i = 1; i <= n; i++) dist[i][i] = 0; rep(K, k) { int p; cin >> p; if (p == 0) { int a, b; cin >> a >> b; if (dist[a][b] == INF) { cout << -1 << endl; } else { cout << dist[a][b] << endl; } } else { int c, d, e; cin >> c >> d >> e; if (dist[c][d] > e) { dist[c][d] = e; dist[d][c] = e; for (int k = 1; k <= n; k++) for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } } } } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define all(c) (c).begin(), (c).end() #define pb push_back #define mp make_pair #define ERASE(v, i) (v).erase(remove(all(v), i), (v).end()) #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define each(it, c) \ for (typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define debug(x) cerr << #x << " = " << (x) << endl; #define LINE cerr << "LINE: " << __LINE__ << endl; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> void preview(T a, T b) { for (T it = a; it != b; ++it) cerr << *it << " "; cerr << endl; } const int INF = 100000000; const double PI = acos(-1.0), EPS = 1e-10; int dist[101][101]; int main() { for (int n, k; cin >> n >> k, n || k;) { for (int i = 1; i <= n; i++) fill(dist[i], dist[i] + 101, INF); for (int i = 1; i <= n; i++) dist[i][i] = 0; rep(K, k) { int p; cin >> p; if (p == 0) { int a, b; cin >> a >> b; if (dist[a][b] == INF) { cout << -1 << endl; } else { cout << dist[a][b] << endl; } } else { int c, d, e; cin >> c >> d >> e; if (dist[c][d] > e) { dist[c][d] = e; dist[d][c] = e; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { dist[i][j] = min(dist[i][j], dist[i][c] + dist[c][j]); dist[i][j] = min(dist[i][j], dist[i][d] + dist[d][j]); dist[j][i] = dist[i][j]; } } } } } return 0; }
replace
78
83
78
84
TLE
p00449
C++
Time Limit Exceeded
#include <iostream> #define INF 1000000000 using namespace std; int dis[5010][5010]; int gedi(int x, int y) { if (x > y) return dis[y][x]; else return dis[x][y]; } void sedi(int x, int y, int v) { if (x > y) dis[y][x] = v; else dis[x][y] = v; } int N; void wf() { for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { sedi(i, j, min(gedi(i, j), gedi(i, k) + gedi(k, j))); } } } } int main() { int K, hog, bak, aho, kso; while (1) { cin >> N >> K; if (N == 0 && K == 0) break; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dis[i][j] = INF; } } for (int i = 0; i < K; i++) { //// // for(int i=0;i<N;i++){ // for(int j=0;j<N;j++){ // cout<<"dis["<<i<<"]["<<j<<"]="<<gedi(i,j)<<" "; // } // cout<<endl; // } //// cin >> hog; if (hog == 0) { cin >> bak >> aho; bak--; aho--; if (gedi(bak, aho) != INF) { cout << gedi(bak, aho) << endl; } else { cout << -1 << endl; } } else { cin >> bak >> aho >> kso; bak--; aho--; if (gedi(bak, aho) > kso) { sedi(bak, aho, kso); wf(); } } } } return 0; }
#include <iostream> #define INF 1000000000 using namespace std; int dis[5010][5010]; int gedi(int x, int y) { if (x > y) return dis[y][x]; else return dis[x][y]; } void sedi(int x, int y, int v) { if (x > y) dis[y][x] = v; else dis[x][y] = v; } int N; void wf() { for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = i; j < N; j++) { sedi(i, j, min(gedi(i, j), gedi(i, k) + gedi(k, j))); } } } } int main() { int K, hog, bak, aho, kso; while (1) { cin >> N >> K; if (N == 0 && K == 0) break; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dis[i][j] = INF; } } for (int i = 0; i < K; i++) { //// // for(int i=0;i<N;i++){ // for(int j=0;j<N;j++){ // cout<<"dis["<<i<<"]["<<j<<"]="<<gedi(i,j)<<" "; // } // cout<<endl; // } //// cin >> hog; if (hog == 0) { cin >> bak >> aho; bak--; aho--; if (gedi(bak, aho) != INF) { cout << gedi(bak, aho) << endl; } else { cout << -1 << endl; } } else { cin >> bak >> aho >> kso; bak--; aho--; if (gedi(bak, aho) > kso) { sedi(bak, aho, kso); wf(); } } } } return 0; }
replace
21
22
21
22
TLE