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
p00090
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <climits> #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 <string> #include <utility> #include <vector> #define ALL(A) (A).begin(), (A).end() #define DUMP(A) cout << #A << "=" << (A) << endl #define SIZE(A) (int)((A).size()) #define P2(A) ((A) * (A)) using namespace std; typedef long long ll; int main() { int n; for (;;) { scanf("%d\n", &n); if (n == 0) break; vector<double> xs(n), ys(n); for (int i = 0; i < n; i++) { scanf("%lf,%lf\n", &xs[i], &ys[i]); } if (n == 1) { printf("1\n"); continue; } int ma = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2, vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])), llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my))); double p1x = mx + (ys[i] - ys[j]) * (llen / vlen), p1y = my - (xs[i] - xs[j]) * (llen / vlen); double p2x = mx - (ys[i] - ys[j]) * (llen / vlen), p2y = my + (xs[i] - xs[j]) * (llen / vlen); int now = 0; for (int k = 0; k < n; k++) { if (sqrt(P2(xs[k] - p1x) + P2(ys[k] - p1y)) <= 1) now++; } ma = max(now, ma); now = 0; for (int k = 0; k < n; k++) { if (sqrt(P2(xs[k] - p2x) + P2(ys[k] - p2y)) <= 1) now++; } ma = max(now, ma); } } printf("%d\n", ma); } }
#include <algorithm> #include <bitset> #include <climits> #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 <string> #include <utility> #include <vector> #define ALL(A) (A).begin(), (A).end() #define DUMP(A) cout << #A << "=" << (A) << endl #define SIZE(A) (int)((A).size()) #define P2(A) ((A) * (A)) using namespace std; typedef long long ll; int main() { int n; for (;;) { scanf("%d\n", &n); if (n == 0) break; vector<double> xs(n), ys(n); for (int i = 0; i < n; i++) { scanf("%lf,%lf\n", &xs[i], &ys[i]); } if (n == 1) { printf("1\n"); continue; } int ma = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2, vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])), llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my))); double p1x = mx + (ys[i] - ys[j]) * (llen / vlen), p1y = my - (xs[i] - xs[j]) * (llen / vlen); double p2x = mx - (ys[i] - ys[j]) * (llen / vlen), p2y = my + (xs[i] - xs[j]) * (llen / vlen); int now = 0; for (int k = 0; k < n; k++) { if (sqrt(P2(xs[k] - p1x) + P2(ys[k] - p1y)) <= 1) now++; } ma = max(now, ma); now = 0; for (int k = 0; k < n; k++) { if (sqrt(P2(xs[k] - p2x) + P2(ys[k] - p2y)) <= 1) now++; } ma = max(now, ma); } } printf("%d\n", ma); } }
replace
44
47
44
45
TLE
p00090
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <climits> #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 <string> #include <utility> #include <vector> #define ALL(A) (A).begin(), (A).end() #define DUMP(A) cout << #A << "=" << (A) << endl #define SIZE(A) (int)((A).size()) #define P2(A) ((A) * (A)) using namespace std; typedef long long ll; int main() { int n; for (;;) { scanf("%d\n", &n); if (n == 0) break; vector<double> xs(n), ys(n); for (int i = 0; i < n; i++) { scanf("%lf %lf\n", &xs[i], &ys[i]); } if (n == 1) { printf("1\n"); continue; } int ma = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2, vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])), llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my))); if (vlen >= 2.00005) continue; double p1x = mx + (ys[i] - ys[j]) * (llen / vlen), p1y = my - (xs[i] - xs[j]) * (llen / vlen); double p2x = mx - (ys[i] - ys[j]) * (llen / vlen), p2y = my + (xs[i] - xs[j]) * (llen / vlen); int now1 = 0, now2 = 0; for (int k = 0; k < n; k++) { if (P2(xs[k] - p1x) + P2(ys[k] - p1y) <= 1.00005) now1++; if (P2(xs[k] - p2x) + P2(ys[k] - p2y) <= 1.00005) now2++; } ma = max(now1, ma); ma = max(now2, ma); } } printf("%d\n", ma); } }
#include <algorithm> #include <bitset> #include <climits> #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 <string> #include <utility> #include <vector> #define ALL(A) (A).begin(), (A).end() #define DUMP(A) cout << #A << "=" << (A) << endl #define SIZE(A) (int)((A).size()) #define P2(A) ((A) * (A)) using namespace std; typedef long long ll; int main() { int n; for (;;) { scanf("%d\n", &n); if (n == 0) break; vector<double> xs(n), ys(n); for (int i = 0; i < n; i++) { scanf("%lf,%lf\n", &xs[i], &ys[i]); } if (n == 1) { printf("1\n"); continue; } int ma = 1; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { double mx = (xs[i] + xs[j]) / 2, my = (ys[i] + ys[j]) / 2, vlen = sqrt(P2(xs[i] - xs[j]) + P2(ys[i] - ys[j])), llen = sqrt(1 - (P2(xs[i] - mx) + P2(ys[i] - my))); if (vlen >= 2.00005) continue; double p1x = mx + (ys[i] - ys[j]) * (llen / vlen), p1y = my - (xs[i] - xs[j]) * (llen / vlen); double p2x = mx - (ys[i] - ys[j]) * (llen / vlen), p2y = my + (xs[i] - xs[j]) * (llen / vlen); int now1 = 0, now2 = 0; for (int k = 0; k < n; k++) { if (P2(xs[k] - p1x) + P2(ys[k] - p1y) <= 1.00005) now1++; if (P2(xs[k] - p2x) + P2(ys[k] - p2y) <= 1.00005) now2++; } ma = max(now1, ma); ma = max(now2, ma); } } printf("%d\n", ma); } }
replace
36
37
36
37
TLE
p00091
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int n; int a[10][10]; int res[3][12][2]; int ii, jj, kk; int dy1[] = {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}; int dx1[] = {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}; int dy2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dx2[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int dy3[] = {-1, 0, 0, 0, 1}; int dx3[] = {0, -1, 0, 1, 0}; bool solve(int i, int j, int k, int y, int x) { if (y == 10) { if (i == 0 && j == 0 && k == 0) { rep(t, ii) cout << res[0][t][1] << " " << res[0][t][0] << " 3" << endl; rep(t, jj) cout << res[1][t][1] << " " << res[1][t][0] << " 2" << endl; rep(t, kk) cout << res[2][t][1] << " " << res[2][t][0] << " 1" << endl; return true; } else { return false; } } if (x == 10) return solve(i, j, k, y + 1, 0); if (a[y][x] == 0) return solve(i, j, k, y, x + 1); if (solve(i, j, k, y, x + 1)) return true; if (i > 0 && 2 <= y && y < 8 && 2 <= x && x < 8) { rep(t, 13) if (a[y + dy1[t]][x + dx1[t]] == 0) goto fail1; res[0][i - 1][0] = y; res[0][i - 1][1] = x; rep(t, 13)-- a[y + dy1[t]][x + dx1[t]]; if (solve(i - 1, j, k, y, x)) return true; rep(t, 13)++ a[y + dy1[t]][x + dx1[t]]; } fail1:; if (j > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) { rep(t, 9) if (a[y + dy2[t]][x + dx2[t]] == 0) goto fail2; res[1][j - 1][0] = y; res[1][j - 1][1] = x; rep(t, 9)-- a[y + dy2[t]][x + dx2[t]]; if (solve(i, j - 1, k, y, x)) return true; rep(t, 9)++ a[y + dy2[t]][x + dx2[t]]; } fail2:; if (k > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) { rep(t, 5) if (a[y + dy3[t]][x + dx3[t]] == 0) goto fail3; res[2][k - 1][0] = y; res[2][k - 1][1] = x; rep(t, 5)-- a[y + dy3[t]][x + dx3[t]]; if (solve(i, j, k - 1, y, x)) return true; rep(t, 5)++ a[y + dy3[t]][x + dx3[t]]; } fail3:; return false; } int main() { cin >> n; rep(i, 10) rep(j, 10) cin >> a[i][j]; int cnt = 0; rep(i, 10) rep(j, 10) cnt += a[i][j]; rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) { if (i + j + k != n) continue; if (i * 13 + j * 9 + k * 5 != cnt) continue; ii = i; jj = j; kk = k; if (solve(i, j, k, 0, 0)) return 0; } }
#include <cmath> #include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) int n; int a[10][10]; int res[3][12][2]; int ii, jj, kk; int dy1[] = {-2, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 2}; int dx1[] = {0, -1, 0, 1, -2, -1, 0, 1, 2, -1, 0, 1, 0}; int dy2[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dx2[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int dy3[] = {-1, 0, 0, 0, 1}; int dx3[] = {0, -1, 0, 1, 0}; bool solve(int i, int j, int k, int y, int x) { if (y == 10) { if (i == 0 && j == 0 && k == 0) { rep(t, ii) cout << res[0][t][1] << " " << res[0][t][0] << " 3" << endl; rep(t, jj) cout << res[1][t][1] << " " << res[1][t][0] << " 2" << endl; rep(t, kk) cout << res[2][t][1] << " " << res[2][t][0] << " 1" << endl; return true; } else { return false; } } if (x == 10) return solve(i, j, k, y + 1, 0); if (3 <= y && a[y - 3][x]) return false; if (a[y][x] == 0) return solve(i, j, k, y, x + 1); if (solve(i, j, k, y, x + 1)) return true; if (i > 0 && 2 <= y && y < 8 && 2 <= x && x < 8) { rep(t, 13) if (a[y + dy1[t]][x + dx1[t]] == 0) goto fail1; res[0][i - 1][0] = y; res[0][i - 1][1] = x; rep(t, 13)-- a[y + dy1[t]][x + dx1[t]]; if (solve(i - 1, j, k, y, x)) return true; rep(t, 13)++ a[y + dy1[t]][x + dx1[t]]; } fail1:; if (j > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) { rep(t, 9) if (a[y + dy2[t]][x + dx2[t]] == 0) goto fail2; res[1][j - 1][0] = y; res[1][j - 1][1] = x; rep(t, 9)-- a[y + dy2[t]][x + dx2[t]]; if (solve(i, j - 1, k, y, x)) return true; rep(t, 9)++ a[y + dy2[t]][x + dx2[t]]; } fail2:; if (k > 0 && 1 <= y && y < 9 && 1 <= x && x < 9) { rep(t, 5) if (a[y + dy3[t]][x + dx3[t]] == 0) goto fail3; res[2][k - 1][0] = y; res[2][k - 1][1] = x; rep(t, 5)-- a[y + dy3[t]][x + dx3[t]]; if (solve(i, j, k - 1, y, x)) return true; rep(t, 5)++ a[y + dy3[t]][x + dx3[t]]; } fail3:; return false; } int main() { cin >> n; rep(i, 10) rep(j, 10) cin >> a[i][j]; int cnt = 0; rep(i, 10) rep(j, 10) cnt += a[i][j]; rep(i, n + 1) rep(j, n + 1) rep(k, n + 1) { if (i + j + k != n) continue; if (i * 13 + j * 9 + k * 5 != cnt) continue; ii = i; jj = j; kk = k; if (solve(i, j, k, 0, 0)) return 0; } }
insert
31
31
31
33
TLE
p00091
C++
Time Limit Exceeded
#include <iostream> #include <numeric> using namespace std; int Y[12], X[12], S[12]; int g[10][10]; const int W = 13 * 12 + 1; bool dp[13][W] = {true}; bool dfs(int y, int x, int s, int n) { int sum = accumulate(g[0], g[10], 0); if (!dp[n][sum]) return false; if (n == 0) return true; for (int i = s; i >= 0; i--) { for (int j = y; j < 10; j++) { y = 0; for (int k = x; k < 10; k++) { x = 0; static int dy[][4] = {{-1, 0, 0, 1}, {-1, -1, 1, 1}, {-2, 0, 0, 2}}; static int dx[][4] = {{0, -1, 1, 0}, {-1, 1, -1, 1}, {0, -2, 2, 0}}; bool f = !g[j][k]; for (int l = 0; l <= i; l++) { for (int m = 0; m < 4; m++) { int ny = j + dy[l][m]; int nx = k + dx[l][m]; f |= ny < 0 || 10 <= ny || nx < 0 || 10 <= nx || g[ny][nx] == 0; } } if (!f) { g[j][k]--; S[n - 1] = i; Y[n - 1] = j; X[n - 1] = k; for (int l = 0; l <= i; l++) { for (int m = 0; m < 4; m++) { int ny = j + dy[l][m]; int nx = k + dx[l][m]; g[ny][nx]--; } } if (dfs(j, k, i, n - 1)) return true; g[j][k]++; for (int l = 0; l <= i; l++) { for (int m = 0; m < 4; m++) { int ny = j + dy[l][m]; int nx = k + dx[l][m]; g[ny][nx]++; } } } } } } return false; } int main() { for (int i = 0; i < 12; i++) { for (int j = 0; j < W; j++) { if (dp[i][j]) { int d[] = {5, 9, 13}; for (int k = 0; k < 3; k++) { if (j + d[k] < W) { dp[i + 1][j + d[k]] = true; } } } } } int n; cin >> n; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cin >> g[i][j]; } } dfs(0, 0, 2, n); while (n--) { cout << X[n] << ' ' << Y[n] << ' ' << S[n] + 1 << endl; } }
#include <iostream> #include <numeric> using namespace std; int Y[12], X[12], S[12]; int g[10][10]; const int W = 13 * 12 + 1; bool dp[13][W] = {true}; bool dfs(int y, int x, int s, int n) { int sum = accumulate(g[0], g[10], 0); if (!dp[n][sum]) return false; if (n == 0) return true; for (int i = s; i >= 0; i--) { for (int j = y; j < 10; j++) { y = 0; for (int k = x; k < 10; k++) { x = 0; static int dy[][4] = {{-1, 0, 0, 1}, {-1, -1, 1, 1}, {-2, 0, 0, 2}}; static int dx[][4] = {{0, -1, 1, 0}, {-1, 1, -1, 1}, {0, -2, 2, 0}}; bool f = !g[j][k]; for (int l = 0; l <= i; l++) { for (int m = 0; m < 4; m++) { int ny = j + dy[l][m]; int nx = k + dx[l][m]; f |= ny < 0 || 10 <= ny || nx < 0 || 10 <= nx || g[ny][nx] == 0; } } if (!f) { g[j][k]--; S[n - 1] = i; Y[n - 1] = j; X[n - 1] = k; for (int l = 0; l <= i; l++) { for (int m = 0; m < 4; m++) { int ny = j + dy[l][m]; int nx = k + dx[l][m]; g[ny][nx]--; } } if (dfs(j, k, i, n - 1)) return true; g[j][k]++; for (int l = 0; l <= i; l++) { for (int m = 0; m < 4; m++) { int ny = j + dy[l][m]; int nx = k + dx[l][m]; g[ny][nx]++; } } if (i == 0) return false; } } } } return false; } int main() { for (int i = 0; i < 12; i++) { for (int j = 0; j < W; j++) { if (dp[i][j]) { int d[] = {5, 9, 13}; for (int k = 0; k < 3; k++) { if (j + d[k] < W) { dp[i + 1][j + d[k]] = true; } } } } } int n; cin >> n; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { cin >> g[i][j]; } } dfs(0, 0, 2, n); while (n--) { cout << X[n] << ' ' << Y[n] << ' ' << S[n] + 1 << endl; } }
insert
53
53
53
55
TLE
p00091
C++
Time Limit Exceeded
#include <bits/stdc++.h> //{{{ uf.hpp #ifndef INCLUDE_UF_HPP #define INCLUDE_UF_HPP #include <algorithm> #include <vector> namespace orislib { namespace ds { //{{{ UF merge, same, root, size, count struct UF { std::vector<int> data; int cnt; UF(int n) : data(n, -1), cnt(n) {} bool merge(int a, int b) { a = root(a); b = root(b); if (a != b) { cnt--; if (data[b] < data[a]) std::swap(a, b); data[a] += data[b]; data[b] = a; } return a != b; } bool same(int a, int b) { return root(a) == root(b); } int root(int a) { return data[a] >= 0 ? data[a] = root(data[a]) : a; } int size(int a) { return -data[root(a)]; } int count() { return cnt; } }; //}}} //{{{ UF2d merge, same, size, count struct UF2d { UF uf; const int W, H; UF2d(int w, int h) : uf(w * h), W(w), H(h) {} bool merge(int ax, int ay, int bx, int by) { return uf.merge(ay * W + ax, by * W + bx); } bool same(int ax, int ay, int bx, int by) { return uf.same(ay * W + ax, by * W + bx); } int size(int x, int y) { return uf.size(y * W + x); } int count() { return uf.count(); } }; //}}} } // namespace ds } // namespace orislib #endif //}}} using namespace std; using namespace orislib::ds; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; typedef tuple<int, int, int> tri; const int dx[] = {0, 0, 0, 1, -1, 1, 1, -1, -1, 2, -2, 0, 0}; const int dy[] = {0, 1, -1, 0, 0, 1, -1, 1, -1, 0, 0, 2, -2}; const int Mod = 1000000000 + 0; //{{{ templates #define TT_ template <typename T> inline #define TTF_ template <typename T, typename F> inline TT_ T sq(T x) { return x * x; } TT_ T In() { T x; cin >> x; return x; } TT_ void Out(T &x) { cout << x; } TT_ void sort(T &v) { sort(begin(v), end(v)); } TT_ void revs(T &v) { reverse(begin(v), end(v)); } TT_ void uniq(T &v) { sort(v); v.erase(unique(begin(v), end(v)), end(v)); } TT_ int ubnd(T &v, typename T::value_type &x) { return upper_bound(begin(v), end(v), x) - begin(v); } TT_ int lbnd(T &v, typename T::value_type &x) { return lower_bound(begin(v), end(v), x) - begin(v); } TTF_ void inpt(T &v, int n, F f) { for (v.reserve(n); n--; v.emplace_back(f())) ; } TTF_ void show(T &v, F f, string d = " ", string e = "\n") { int i = 0; for (auto &x : v) i++ && (cout << d), f(x); cout << e; } TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); } TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); } inline void fast_io() { ios::sync_with_stdio(0); cin.tie(0); } inline int in() { int x; scanf("%d", &x); return x; } inline ll pow_mod(ll a, ll k, ll m) { ll r = 1; for (; k > 0; a = a * a % m, k >>= 1) if (k & 1) r = r * a % m; return r; } inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); } //}}} priority_queue queue deque front stringstream max_element min_element //insert count make_tuple #define USE_HASH struct Zhash { Zhash() { mt19937 mt; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int s = 0; s < 256; s++) { rands[i][j][s] = mt(); } } } } int hash(int data[10][10]) { int h = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { h ^= rands[i][j][data[i][j]]; } } return h; } int rands[10][10][256]; }; const int len[] = {5, 9, 13}; struct Board { Board() { memset(valid_table, 0, sizeof(valid_table)); valid_table[0][0] = true; for (int t = 1; t <= 12; t++) { for (int v = 0; v <= 12 * 13; v++) { if (!valid_table[t - 1][v]) continue; valid_table[t][v + 5] = true; valid_table[t][v + 9] = true; valid_table[t][v + 13] = true; } } memset(cnt, 0, sizeof(cnt)); } void read() { N = in(); tot = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { data[i][j] = in(); tot += data[i][j]; } } } bool invalid(int x, int y) { return x < 0 || x >= 10 || y < 0 || y >= 10; } bool drop_ink(int x, int y, int t) { const int l = len[t]; tot -= l; cnt[t]++; bool ok = tot >= 0 && valid_table[N - (cnt[0] + cnt[1] + cnt[2])][tot]; for (int d = 0; d < l; d++) { int nx = x + dx[d], ny = y + dy[d]; if (invalid(nx, ny)) { ok = false; continue; } data[ny][nx]--; if (data[ny][nx] < 0) ok = false; } ans.emplace_back(x, y, t + 1); if (ok) { #ifdef USE_HASH int h = zhash.hash(data); if (vis.count(h)) return false; vis.insert(h); if (vis.size() >= 1000000u) vis.clear(); #endif UF2d uf(10, 10); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (data[i][j] <= 0) continue; for (int d = 0; d < 5; d++) { int nx = j + dx[d], ny = i + dy[d]; if (invalid(nx, ny)) continue; if (data[ny][nx] <= 0) continue; uf.merge(j, i, nx, ny); } } } int mini = 128; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (data[i][j] >= 1) mini = min(mini, uf.size(j, i)); } } if (mini < 5) return false; } return ok; } void undo(int x, int y, int t) { const int l = len[t]; tot += l; cnt[t]--; for (int d = 0; d < l; d++) { int nx = x + dx[d], ny = y + dy[d]; if (invalid(nx, ny)) continue; data[ny][nx]++; } ans.pop_back(); } bool solve() { if (cnt[0] + cnt[1] + cnt[2] == N) return true; for (int t = 0; t < 3; t++) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { bool ok = drop_ink(j, i, t); if (ok && solve()) return true; undo(j, i, t); } } } return false; } int data[10][10]; int cnt[3]; int tot; int N; bool valid_table[13][13 * 13 + 1]; unordered_set<int> vis; vector<tri> ans; Zhash zhash; }; int main() { Board b; b.read(); b.solve(); for (const auto &a : b.ans) { cout << get<0>(a) << " " << get<1>(a) << " " << get<2>(a) << "\n"; } return 0; }
#include <bits/stdc++.h> //{{{ uf.hpp #ifndef INCLUDE_UF_HPP #define INCLUDE_UF_HPP #include <algorithm> #include <vector> namespace orislib { namespace ds { //{{{ UF merge, same, root, size, count struct UF { std::vector<int> data; int cnt; UF(int n) : data(n, -1), cnt(n) {} bool merge(int a, int b) { a = root(a); b = root(b); if (a != b) { cnt--; if (data[b] < data[a]) std::swap(a, b); data[a] += data[b]; data[b] = a; } return a != b; } bool same(int a, int b) { return root(a) == root(b); } int root(int a) { return data[a] >= 0 ? data[a] = root(data[a]) : a; } int size(int a) { return -data[root(a)]; } int count() { return cnt; } }; //}}} //{{{ UF2d merge, same, size, count struct UF2d { UF uf; const int W, H; UF2d(int w, int h) : uf(w * h), W(w), H(h) {} bool merge(int ax, int ay, int bx, int by) { return uf.merge(ay * W + ax, by * W + bx); } bool same(int ax, int ay, int bx, int by) { return uf.same(ay * W + ax, by * W + bx); } int size(int x, int y) { return uf.size(y * W + x); } int count() { return uf.count(); } }; //}}} } // namespace ds } // namespace orislib #endif //}}} using namespace std; using namespace orislib::ds; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; typedef tuple<int, int, int> tri; const int dx[] = {0, 0, 0, 1, -1, 1, 1, -1, -1, 2, -2, 0, 0}; const int dy[] = {0, 1, -1, 0, 0, 1, -1, 1, -1, 0, 0, 2, -2}; const int Mod = 1000000000 + 0; //{{{ templates #define TT_ template <typename T> inline #define TTF_ template <typename T, typename F> inline TT_ T sq(T x) { return x * x; } TT_ T In() { T x; cin >> x; return x; } TT_ void Out(T &x) { cout << x; } TT_ void sort(T &v) { sort(begin(v), end(v)); } TT_ void revs(T &v) { reverse(begin(v), end(v)); } TT_ void uniq(T &v) { sort(v); v.erase(unique(begin(v), end(v)), end(v)); } TT_ int ubnd(T &v, typename T::value_type &x) { return upper_bound(begin(v), end(v), x) - begin(v); } TT_ int lbnd(T &v, typename T::value_type &x) { return lower_bound(begin(v), end(v), x) - begin(v); } TTF_ void inpt(T &v, int n, F f) { for (v.reserve(n); n--; v.emplace_back(f())) ; } TTF_ void show(T &v, F f, string d = " ", string e = "\n") { int i = 0; for (auto &x : v) i++ && (cout << d), f(x); cout << e; } TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); } TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); } inline void fast_io() { ios::sync_with_stdio(0); cin.tie(0); } inline int in() { int x; scanf("%d", &x); return x; } inline ll pow_mod(ll a, ll k, ll m) { ll r = 1; for (; k > 0; a = a * a % m, k >>= 1) if (k & 1) r = r * a % m; return r; } inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); } //}}} priority_queue queue deque front stringstream max_element min_element //insert count make_tuple #define USE_HASH struct Zhash { Zhash() { mt19937 mt; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { for (int s = 0; s < 256; s++) { rands[i][j][s] = mt(); } } } } int hash(int data[10][10]) { int h = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { h ^= rands[i][j][data[i][j]]; } } return h; } int rands[10][10][256]; }; const int len[] = {5, 9, 13}; struct Board { Board() { memset(valid_table, 0, sizeof(valid_table)); valid_table[0][0] = true; for (int t = 1; t <= 12; t++) { for (int v = 0; v <= 12 * 13; v++) { if (!valid_table[t - 1][v]) continue; valid_table[t][v + 5] = true; valid_table[t][v + 9] = true; valid_table[t][v + 13] = true; } } memset(cnt, 0, sizeof(cnt)); } void read() { N = in(); tot = 0; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { data[i][j] = in(); tot += data[i][j]; } } } bool invalid(int x, int y) { return x < 0 || x >= 10 || y < 0 || y >= 10; } bool drop_ink(int x, int y, int t) { const int l = len[t]; tot -= l; cnt[t]++; bool ok = tot >= 0 && valid_table[N - (cnt[0] + cnt[1] + cnt[2])][tot]; for (int d = 0; d < l; d++) { int nx = x + dx[d], ny = y + dy[d]; if (invalid(nx, ny)) { ok = false; continue; } data[ny][nx]--; if (data[ny][nx] < 0) ok = false; } ans.emplace_back(x, y, t + 1); if (ok) { #ifdef USE_HASH int h = zhash.hash(data); if (vis.count(h)) return false; vis.insert(h); if (vis.size() >= 1000000u) vis.clear(); #endif UF2d uf(10, 10); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (data[i][j] <= 0) continue; for (int d = 0; d < 5; d++) { int nx = j + dx[d], ny = i + dy[d]; if (invalid(nx, ny)) continue; if (data[ny][nx] <= 0) continue; uf.merge(j, i, nx, ny); } } } int mini = 128; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (data[i][j] >= 1) mini = min(mini, uf.size(j, i)); } } if (mini < 5) return false; } return ok; } void undo(int x, int y, int t) { const int l = len[t]; tot += l; cnt[t]--; for (int d = 0; d < l; d++) { int nx = x + dx[d], ny = y + dy[d]; if (invalid(nx, ny)) continue; data[ny][nx]++; } ans.pop_back(); } bool solve() { if (cnt[0] + cnt[1] + cnt[2] == N) return true; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (!data[i][j]) continue; bool ok; ok = drop_ink(j, i + 1, 0); if (ok && solve()) return true; undo(j, i + 1, 0); ok = drop_ink(j + 1, i + 1, 1); if (ok && solve()) return true; undo(j + 1, i + 1, 1); ok = drop_ink(j, i + 2, 2); if (ok && solve()) return true; undo(j, i + 2, 2); return false; } } return true; } int data[10][10]; int cnt[3]; int tot; int N; bool valid_table[13][13 * 13 + 1]; unordered_set<int> vis; vector<tri> ans; Zhash zhash; }; int main() { Board b; b.read(); b.solve(); for (const auto &a : b.ans) { cout << get<0>(a) << " " << get<1>(a) << " " << get<2>(a) << "\n"; } return 0; }
replace
237
248
237
258
TLE
p00091
C++
Time Limit Exceeded
#include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <queue> #include <tuple> #include <vector> using namespace std; vector<vector<char>> S; int n; bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0; vector<vector<char>> solve(vector<vector<char>> p, int x, int y, int r) { if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; } if (r == 2) { for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) p[x + i][y + j]--; } if (r == 3) { for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; } return p; } bool isgood(int p) { if (p % 4 == 1 && p >= 5) return true; if (p % 4 == 2 && p >= 10) return true; if (p % 4 == 3 && p >= 15) return true; if (p % 4 == 0 && p >= 20) return true; return false; } bool hantei(vector<vector<char>> p) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (p[i][j] < 0) return false; } } bool OKs[10][10]; for (int i = 0; i < 100; i++) OKs[i / 10][i % 10] = false; for (int i = 1; i < 9; i++) { for (int j = 1; j < 9; j++) { if (p[i][j] == 0) continue; bool OK6 = false; if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) { OK6 = true; OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true; } if (OK6 == false) continue; bool OK4 = true; for (int k = -1; k <= 1; k++) for (int l = -1; l <= 1; l++) if (p[i + k][j + l] == 0) OK4 = false; if (OK4 == false) continue; for (int k = -1; k <= 1; k++) for (int l = -1; l <= 1; l++) OKs[i + k][j + l] = true; } } for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { if (OKs[i][j] == false && p[i][j] >= 1) return false; } } queue<pair<int, int>> Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++) OK5[i / 10][i % 10] = false; if (rand() % 37 <= 7 && n == 12 && _size >= 1000) return false; return true; } vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>> Vec; void zen_shori() { int JJ = 165; if (LIM2 == 2) JJ = 27061; for (int i = 0; i < JJ; i++) { tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>> ZZ; Vec.push_back(ZZ); } vector<vector<char>> ZERO; int LL = 0, RR = 0; vector<tuple<char, char, char>> ZERO3; for (int i = 0; i < 10; i++) { vector<char> ZERO5(10, 0); ZERO.push_back(ZERO5); } Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++; while (LL < RR && RR < JJ) { vector<vector<char>> a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]); vector<tuple<char, char, char>> a3 = get<2>(Vec[LL]); LL++; if (a2 == LIM2) continue; int L[4] = {0, 1, 1, 2}, R[4] = {9, 8, 8, 7}, P[4] = {0, 5, 9, 13}; for (int i = 1; i <= 3; i++) { for (int j = L[i]; j <= R[i]; j++) { for (int k = L[i]; k <= R[i]; k++) { vector<vector<char>> a4 = solve(a1, j, k, i); vector<tuple<char, char, char>> a5 = a3; a5.push_back(make_tuple(j, k, i)); if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; } } } } } for (int i = 0; i < Vec.size(); i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { get<0>(Vec[i])[j][k] *= -1; } } } sort(Vec.begin(), Vec.end()); } int main() { srand((unsigned)time(NULL)); cin >> n; dp[0][0] = true; LIM2 = 2; for (int i = 0; i < 12; i++) { for (int j = 0; j < 160; j++) { if (dp[i][j] == false) continue; dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true; } } for (int i = 0; i < 10; i++) { vector<char> V(10, 0); S.push_back(V); } vector<vector<char>> START = S; int SUM = 0; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; } queue<tuple<int, vector<tuple<char, char, char>>, int>> Q; vector<tuple<char, char, char>> ZERO; Q.push(make_tuple(0, ZERO, SUM)); zen_shori(); CC = SUM; while (!Q.empty()) { vector<vector<char>> a1 = S; int a2 = get<0>(Q.front()); vector<tuple<char, char, char>> a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size(); for (int i = 0; i < a3.size(); i++) { a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i])); } int L[4] = {0, 1, 1, 2}, R[4] = {9, 8, 8, 7}, P[4] = {0, 5, 9, 13}; for (int i = 1; i <= 3; i++) { int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true; if (dp[rem2][rem1] == false) OK = false; if (OK == false) continue; int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]); for (int j = L[i]; j <= R[i]; j++) { for (int k = L[i]; k <= R[i]; k++) { int DD = j * 100 + k * 10 + i; if (DD < LIM) continue; vector<vector<char>> G = solve(a1, j, k, i); vector<tuple<char, char, char>> H = a3; if (hantei(G) == false) continue; H.push_back(make_tuple(j, k, i)); if (G == START && a2 + 1 == n) { for (int j = 0; j < H.size(); j++) { cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl; } goto E; } if (a2 + 1 >= n - LIM2) { int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin(); if (P < Vec.size() && get<0>(Vec[P]) == G) { for (int j = 0; j < H.size(); j++) { cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl; } vector<tuple<char, char, char>> J = get<2>(Vec[P]); for (int j = 0; j < J.size(); j++) { cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl; } goto E; } } Q.push(make_tuple(a2 + 1, H, a4 - P[i])); } } } } E:; return 0; }
#include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <queue> #include <tuple> #include <vector> using namespace std; vector<vector<char>> S; int n; bool dp[13][160]; int LIM2 = 0; int _size = 0; int CC = 0; vector<vector<char>> solve(vector<vector<char>> p, int x, int y, int r) { if (r == 1) { p[x][y]--; p[x + 1][y]--; p[x - 1][y]--; p[x][y - 1]--; p[x][y + 1]--; } if (r == 2) { for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) p[x + i][y + j]--; } if (r == 3) { for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) p[x + i][y + j]--; p[x + 2][y]--; p[x][y + 2]--; p[x - 2][y]--; p[x][y - 2]--; } return p; } bool isgood(int p) { if (p % 4 == 1 && p >= 5) return true; if (p % 4 == 2 && p >= 10) return true; if (p % 4 == 3 && p >= 15) return true; if (p % 4 == 0 && p >= 20) return true; return false; } bool hantei(vector<vector<char>> p) { for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (p[i][j] < 0) return false; } } bool OKs[10][10]; for (int i = 0; i < 100; i++) OKs[i / 10][i % 10] = false; for (int i = 1; i < 9; i++) { for (int j = 1; j < 9; j++) { if (p[i][j] == 0) continue; bool OK6 = false; if (p[i - 1][j] >= 1 && p[i + 1][j] >= 1 && p[i][j - 1] >= 1 && p[i][j + 1] >= 1) { OK6 = true; OKs[i][j] = true; OKs[i - 1][j] = true; OKs[i][j - 1] = true; OKs[i][j + 1] = true; OKs[i + 1][j] = true; } if (OK6 == false) continue; bool OK4 = true; for (int k = -1; k <= 1; k++) for (int l = -1; l <= 1; l++) if (p[i + k][j + l] == 0) OK4 = false; if (OK4 == false) continue; for (int k = -1; k <= 1; k++) for (int l = -1; l <= 1; l++) OKs[i + k][j + l] = true; } } for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { if (OKs[i][j] == false && p[i][j] >= 1) return false; } } queue<pair<int, int>> Q3; bool OK5[10][10]; for (int i = 0; i < 100; i++) OK5[i / 10][i % 10] = false; if (rand() % 9 <= 1 && n == 12 && _size >= 1000) return false; return true; } vector<tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>>> Vec; void zen_shori() { int JJ = 165; if (LIM2 == 2) JJ = 27061; for (int i = 0; i < JJ; i++) { tuple<vector<vector<char>>, int, vector<tuple<char, char, char>>> ZZ; Vec.push_back(ZZ); } vector<vector<char>> ZERO; int LL = 0, RR = 0; vector<tuple<char, char, char>> ZERO3; for (int i = 0; i < 10; i++) { vector<char> ZERO5(10, 0); ZERO.push_back(ZERO5); } Vec[0] = make_tuple(ZERO, 0, ZERO3); RR++; while (LL < RR && RR < JJ) { vector<vector<char>> a1 = get<0>(Vec[LL]); int a2 = get<1>(Vec[LL]); vector<tuple<char, char, char>> a3 = get<2>(Vec[LL]); LL++; if (a2 == LIM2) continue; int L[4] = {0, 1, 1, 2}, R[4] = {9, 8, 8, 7}, P[4] = {0, 5, 9, 13}; for (int i = 1; i <= 3; i++) { for (int j = L[i]; j <= R[i]; j++) { for (int k = L[i]; k <= R[i]; k++) { vector<vector<char>> a4 = solve(a1, j, k, i); vector<tuple<char, char, char>> a5 = a3; a5.push_back(make_tuple(j, k, i)); if (RR < JJ) { Vec[RR] = make_tuple(a4, a2 + 1, a5); RR++; } } } } } for (int i = 0; i < Vec.size(); i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 10; k++) { get<0>(Vec[i])[j][k] *= -1; } } } sort(Vec.begin(), Vec.end()); } int main() { srand((unsigned)time(NULL)); cin >> n; dp[0][0] = true; LIM2 = 2; for (int i = 0; i < 12; i++) { for (int j = 0; j < 160; j++) { if (dp[i][j] == false) continue; dp[i + 1][j + 5] = true; dp[i + 1][j + 9] = true; dp[i + 1][j + 13] = true; } } for (int i = 0; i < 10; i++) { vector<char> V(10, 0); S.push_back(V); } vector<vector<char>> START = S; int SUM = 0; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) { int SS; cin >> SS; S[i][j] = SS; SUM += S[i][j]; } queue<tuple<int, vector<tuple<char, char, char>>, int>> Q; vector<tuple<char, char, char>> ZERO; Q.push(make_tuple(0, ZERO, SUM)); zen_shori(); CC = SUM; while (!Q.empty()) { vector<vector<char>> a1 = S; int a2 = get<0>(Q.front()); vector<tuple<char, char, char>> a3 = get<1>(Q.front()); int a4 = get<2>(Q.front()); Q.pop(); _size = Q.size(); for (int i = 0; i < a3.size(); i++) { a1 = solve(a1, get<0>(a3[i]), get<1>(a3[i]), get<2>(a3[i])); } int L[4] = {0, 1, 1, 2}, R[4] = {9, 8, 8, 7}, P[4] = {0, 5, 9, 13}; for (int i = 1; i <= 3; i++) { int rem1 = a4 - P[i], rem2 = n - (a2 + 1); bool OK = true; if (dp[rem2][rem1] == false) OK = false; if (OK == false) continue; int LIM = 0; if (a3.size() >= 1) LIM = get<0>(a3[a3.size() - 1]) * 100 + get<1>(a3[a3.size() - 1]) * 10 + get<2>(a3[a3.size() - 1]); for (int j = L[i]; j <= R[i]; j++) { for (int k = L[i]; k <= R[i]; k++) { int DD = j * 100 + k * 10 + i; if (DD < LIM) continue; vector<vector<char>> G = solve(a1, j, k, i); vector<tuple<char, char, char>> H = a3; if (hantei(G) == false) continue; H.push_back(make_tuple(j, k, i)); if (G == START && a2 + 1 == n) { for (int j = 0; j < H.size(); j++) { cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl; } goto E; } if (a2 + 1 >= n - LIM2) { int P = lower_bound(Vec.begin(), Vec.end(), make_tuple(G, 0, ZERO)) - Vec.begin(); if (P < Vec.size() && get<0>(Vec[P]) == G) { for (int j = 0; j < H.size(); j++) { cout << (int)get<1>(H[j]) << ' ' << (int)get<0>(H[j]) << ' ' << (int)get<2>(H[j]) << endl; } vector<tuple<char, char, char>> J = get<2>(Vec[P]); for (int j = 0; j < J.size(); j++) { cout << (int)get<1>(J[j]) << ' ' << (int)get<0>(J[j]) << ' ' << (int)get<2>(J[j]) << endl; } goto E; } } Q.push(make_tuple(a2 + 1, H, a4 - P[i])); } } } } E:; return 0; }
replace
97
98
97
98
TLE
p00091
C++
Time Limit Exceeded
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> using namespace std; struct aa { int x; int y; int t; aa(int a, int b, int c) { x = a; y = b; t = c; } }; int inks[3][5][5] = { { {0, 0, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}, }, { {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 0, 0, 0, 0}, }, { {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, }, }; bool ok(const vector<vector<int>> &v, int ink_x, int ink_y, int ink_id) { for (int dy = 0; dy < 5; ++dy) { for (int dx = 0; dx < 5; ++dx) { if (inks[ink_id][dy][dx]) { int ax = ink_x - 2 + dx; int ay = ink_y - 2 + dy; if (ax < 0 || ax >= 10 || ay < 0 || ay >= 10) return false; if (v[ay][ax] <= 0) return false; } } } return true; } vector<aa> solve(int now_x, int now_y, int rest, vector<vector<int>> &v) { if (rest == 0) { bool ok = true; for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { if (v[i][j]) ok = false; } } aa k = aa(-1, -1, -1); if (ok) return vector<aa>(); else return vector<aa>(1, aa(-1, -1, -1)); } if (now_y == 10) { return vector<aa>(1, aa(-1, -1, -1)); } for (int ink_id = 0; ink_id <= 2; ++ink_id) { if (ok(v, now_x, now_y, ink_id)) { for (int dy = 0; dy < 5; ++dy) { for (int dx = 0; dx < 5; ++dx) { if (inks[ink_id][dy][dx]) { int ax = now_x - 2 + dx; int ay = now_y - 2 + dy; if (ax < 0 || ax >= 10 || ay < 0 || ay >= 10) assert(false); if (v[ay][ax] <= 0) assert(false); v[ay][ax]--; } } } vector<aa> aas = solve(now_x, now_y, rest - 1, v); for (int dy = 0; dy < 5; ++dy) { for (int dx = 0; dx < 5; ++dx) { if (inks[ink_id][dy][dx]) { int ax = now_x - 2 + dx; int ay = now_y - 2 + dy; v[ay][ax]++; } } } if (aas.size() == 1 && aas[0].x == -1) continue; else { aas.push_back(aa(now_x, now_y, ink_id)); return aas; } } } int next_x = now_x + 1; int next_y = now_y; if (next_x == 10) { next_x = 0; next_y = next_y + 1; } return solve(next_x, next_y, rest, v); } int main() { int N; cin >> N; vector<vector<int>> v(10, vector<int>(10)); for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { cin >> v[i][j]; } } auto p = solve(0, 0, N, v); for (int i = 0; i < p.size(); ++i) { cout << p[i].x << " " << p[i].y << " " << p[i].t + 1 << endl; } // cout<<"0"<<endl; return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> using namespace std; struct aa { int x; int y; int t; aa(int a, int b, int c) { x = a; y = b; t = c; } }; int inks[3][5][5] = { { {0, 0, 0, 0, 0}, {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, {0, 0, 0, 0, 0}, }, { {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 1, 1, 1, 0}, {0, 0, 0, 0, 0}, }, { {0, 0, 1, 0, 0}, {0, 1, 1, 1, 0}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 0}, {0, 0, 1, 0, 0}, }, }; bool ok(const vector<vector<int>> &v, int ink_x, int ink_y, int ink_id) { for (int dy = 0; dy < 5; ++dy) { for (int dx = 0; dx < 5; ++dx) { if (inks[ink_id][dy][dx]) { int ax = ink_x - 2 + dx; int ay = ink_y - 2 + dy; if (ax < 0 || ax >= 10 || ay < 0 || ay >= 10) return false; if (v[ay][ax] <= 0) return false; } } } return true; } vector<aa> solve(int now_x, int now_y, int rest, vector<vector<int>> &v) { if (rest == 0) { bool ok = true; for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { if (v[i][j]) ok = false; } } aa k = aa(-1, -1, -1); if (ok) return vector<aa>(); else return vector<aa>(1, aa(-1, -1, -1)); } if (now_y == 10) { return vector<aa>(1, aa(-1, -1, -1)); } if (now_y >= 3 && now_x == 0) { for (int y = 0; y < now_y - 2; ++y) { for (int x = 0; x < 10; ++x) { if (v[y][x]) return vector<aa>(1, aa(-1, -1, -1)); } } } for (int ink_id = 0; ink_id <= 2; ++ink_id) { if (ok(v, now_x, now_y, ink_id)) { for (int dy = 0; dy < 5; ++dy) { for (int dx = 0; dx < 5; ++dx) { if (inks[ink_id][dy][dx]) { int ax = now_x - 2 + dx; int ay = now_y - 2 + dy; if (ax < 0 || ax >= 10 || ay < 0 || ay >= 10) assert(false); if (v[ay][ax] <= 0) assert(false); v[ay][ax]--; } } } vector<aa> aas = solve(now_x, now_y, rest - 1, v); for (int dy = 0; dy < 5; ++dy) { for (int dx = 0; dx < 5; ++dx) { if (inks[ink_id][dy][dx]) { int ax = now_x - 2 + dx; int ay = now_y - 2 + dy; v[ay][ax]++; } } } if (aas.size() == 1 && aas[0].x == -1) continue; else { aas.push_back(aa(now_x, now_y, ink_id)); return aas; } } } int next_x = now_x + 1; int next_y = now_y; if (next_x == 10) { next_x = 0; next_y = next_y + 1; } return solve(next_x, next_y, rest, v); } int main() { int N; cin >> N; vector<vector<int>> v(10, vector<int>(10)); for (int i = 0; i < 10; ++i) { for (int j = 0; j < 10; ++j) { cin >> v[i][j]; } } auto p = solve(0, 0, N, v); for (int i = 0; i < p.size(); ++i) { cout << p[i].x << " " << p[i].y << " " << p[i].t + 1 << endl; } // cout<<"0"<<endl; return 0; }
insert
75
75
75
83
TLE
p00092
C++
Time Limit Exceeded
#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 INT_MAX / 3 #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CLR(a) memset(a, 0, sizeof(a)) typedef long long int ll; using namespace std; int main() { while (true) { int n; cin >> n; vector<vector<char>> map(n, vector<char>(n, '.')); REP(i, n) { REP(j, n) { cin >> map[i][j]; } } if (n == 0) break; bool flg = true; int high, low, middle; high = n + 1; low = 0; middle = (high + low) / 2; while (high - low > 1) { REP(j, n - middle + 1) { REP(k, n - middle + 1) { flg = true; REP(l, middle) { REP(m, middle) { if (map[j + l][k + m] == '*') { flg = false; break; } } if (!flg) break; } if (flg) { break; } } if (flg) break; } if (flg) { low = middle; } else { high = middle; } middle = (high + low) / 2; } cout << middle << 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 INT_MAX / 3 #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CLR(a) memset(a, 0, sizeof(a)) typedef long long int ll; using namespace std; int main() { while (true) { int n; cin >> n; vector<vector<char>> map(n, vector<char>(n, '.')); REP(i, n) { REP(j, n) { cin >> map[i][j]; } } if (n == 0) break; bool flg = true; int high, low, middle; high = n + 1; low = 0; middle = (high + low) / 2; while (high - low > 1) { REP(j, n - middle + 1) { REP(k, n - middle + 1) { flg = true; REP(l, middle) { REP(m, middle) { if (map[j + l][k + m] == '*') { flg = false; k = k + m; if (k >= n - middle + 1) break; break; } } if (!flg) break; } if (flg) { break; } } if (flg) break; } if (flg) { low = middle; } else { high = middle; } middle = (high + low) / 2; } cout << middle << endl; } return 0; }
insert
40
40
40
43
TLE
p00092
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) { break; } vector<vector<char>> d(n, vector<char>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> d[i][j]; } } vector<vector<int>> dd(n, vector<int>(n)); int c = 0; for (int i = 0; i < n; i++) { int cc = 0; for (int j = n - 1; j >= 0; j--) { if (d[i][j] == '.') { cc++; } else { cc = 0; } dd[i][j] = cc; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dd[i][j] > c) { int ccc = dd[i][j]; for (int k = 0; i + k < n; k++) { if (dd[i + k][j] == 0) { break; } ccc = min(ccc, dd[i + k][j]); if (ccc <= k + 1) { c = max(c, ccc); } } } } } cout << c << endl; } return 0; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) { break; } vector<vector<char>> d(n, vector<char>(n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> d[i][j]; } } vector<vector<int>> dd(n, vector<int>(n)); int c = 0; for (int i = 0; i < n; i++) { int cc = 0; for (int j = n - 1; j >= 0; j--) { if (d[i][j] == '.') { cc++; } else { cc = 0; } dd[i][j] = cc; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (dd[i][j] > c) { int ccc = dd[i][j]; for (int k = 0; i + k < n; k++) { if (dd[i + k][j] <= c) { break; } ccc = min(ccc, dd[i + k][j]); if (ccc <= k + 1) { c = max(c, ccc); } } } } } cout << c << endl; } return 0; }
replace
37
38
37
38
TLE
p00092
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define PB push_back #define MP make_pair #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 100000; int cnt[1000][1000]; int main() { int n; char fld[1000][1000]; while (scanf("%d", &n) && n) { memset(cnt, 0, sizeof(cnt)); REP(i, n) { scanf("%s", fld[i]); REP(j, n) if (fld[i][j] == '*') cnt[i][j]++; } // REP(i,n){REP(j,n)cout<<cnt[j][i];cout<<endl;} REP(i, n) REP(j, n) { if (i != 0) cnt[j][i] += cnt[j][i - 1]; if (j != 0) cnt[j][i] += cnt[j - 1][i]; if (i != 0 && j != 0) cnt[j][i] -= cnt[j - 1][i - 1]; } // REP(i,n){REP(j,n)cout<<cnt[j][i]<<" ";cout<<endl;} int ans = 0; REP(x, n) REP(y, n) { REP(d, min(n - x, n - y)) { int nx = x + d, ny = y + d; int c = cnt[ny][nx]; if (x != 0) c -= cnt[ny][x - 1]; if (y != 0) c -= cnt[y - 1][nx]; if (x != 0 && y != 0) c += cnt[y - 1][x - 1]; if (c == 0 && ans < d + 1) { // cout<<x<<" "<<y<<" "<<d+1<<endl; ans = d + 1; } } } printf("%d\n", ans); } }
#include <bits/stdc++.h> #define PB push_back #define MP make_pair #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 100000; int cnt[1000][1000]; int main() { int n; char fld[1000][1000]; while (scanf("%d", &n) && n) { memset(cnt, 0, sizeof(cnt)); REP(i, n) { scanf("%s", fld[i]); REP(j, n) if (fld[i][j] == '*') cnt[i][j]++; } // REP(i,n){REP(j,n)cout<<cnt[j][i];cout<<endl;} REP(i, n) REP(j, n) { if (i != 0) cnt[j][i] += cnt[j][i - 1]; if (j != 0) cnt[j][i] += cnt[j - 1][i]; if (i != 0 && j != 0) cnt[j][i] -= cnt[j - 1][i - 1]; } // REP(i,n){REP(j,n)cout<<cnt[j][i]<<" ";cout<<endl;} int ans = 0; REP(x, n) REP(y, n) { for (int d = ans; d < min(n - x, n - y); d++) { int nx = x + d, ny = y + d; int c = cnt[ny][nx]; if (x != 0) c -= cnt[ny][x - 1]; if (y != 0) c -= cnt[y - 1][nx]; if (x != 0 && y != 0) c += cnt[y - 1][x - 1]; if (c == 0 && ans < d + 1) { // cout<<x<<" "<<y<<" "<<d+1<<endl; ans = d + 1; } } } printf("%d\n", ans); } }
replace
34
35
34
35
TLE
p00092
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int dp[1001][1001]; int latte(int i, int j, int k) { return dp[i + k][j + k] - dp[i + k][j - 1] - dp[i - 1][j + k] + dp[i - 1][j - 1]; } int main() { int n; while (cin >> n, n) { fill(dp[0], dp[0] + 1001 * 1001, 0); for (int i = 0; i < n; i++) { string str; cin >> str; for (int j = 0; j < n; j++) { dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j]; if (str[j] == '*') dp[i + 1][j + 1]++; } } int Max = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (latte(i, j, 0)) continue; int lb = 0, ub = max(n - i, n - j) + 1; while (ub - lb > 1) { int k = (ub + lb) / 2; // if(i+k>n||j+k>n)ub=k; if (latte(i, j, k)) ub = k; else lb = k; } Max = max(Max, lb + 1); } } cout << Max << endl; } }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int dp[1001][1001]; int latte(int i, int j, int k) { return dp[i + k][j + k] - dp[i + k][j - 1] - dp[i - 1][j + k] + dp[i - 1][j - 1]; } int main() { int n; while (cin >> n, n) { fill(dp[0], dp[0] + 1001 * 1001, 0); for (int i = 0; i < n; i++) { string str; cin >> str; for (int j = 0; j < n; j++) { dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j]; if (str[j] == '*') dp[i + 1][j + 1]++; } } int Max = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (latte(i, j, 0)) continue; int lb = 0, ub = min(n - i, n - j) + 1; while (ub - lb > 1) { int k = (ub + lb) / 2; // if(i+k>n||j+k>n)ub=k; if (latte(i, j, k)) ub = k; else lb = k; } Max = max(Max, lb + 1); } } cout << Max << endl; } }
replace
28
29
28
29
0
p00092
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; #define MAX 504 int hseq[MAX][MAX]; int vseq[MAX][MAX]; int sq[MAX][MAX]; char f[MAX][MAX]; int main() { while (true) { int n; scanf("%d", &n); if (n == 0) break; int ans = 0; for (int y = 1; y <= n; ++y) { scanf("%s", &f[y][1]); for (int x = 1; x <= n; ++x) { hseq[y][x] = f[y][x] == '.' ? hseq[y][x - 1] + 1 : 0; vseq[y][x] = f[y][x] == '.' ? vseq[y - 1][x] + 1 : 0; sq[y][x] = f[y][x] == '.' ? min(sq[y - 1][x - 1], min(hseq[y][x - 1], vseq[y - 1][x])) + 1 : 0; ans = max(ans, sq[y][x]); } } /* for(int y=1; y<=n; ++y) { for(int x=1; x<=n; ++x) { printf(" %2d", sq[y][x]); } printf("\n"); } */ printf("%d\n", ans); } return 0; }
#include <algorithm> #include <cstdio> using namespace std; #define MAX 1004 int hseq[MAX][MAX]; int vseq[MAX][MAX]; int sq[MAX][MAX]; char f[MAX][MAX]; int main() { while (true) { int n; scanf("%d", &n); if (n == 0) break; int ans = 0; for (int y = 1; y <= n; ++y) { scanf("%s", &f[y][1]); for (int x = 1; x <= n; ++x) { hseq[y][x] = f[y][x] == '.' ? hseq[y][x - 1] + 1 : 0; vseq[y][x] = f[y][x] == '.' ? vseq[y - 1][x] + 1 : 0; sq[y][x] = f[y][x] == '.' ? min(sq[y - 1][x - 1], min(hseq[y][x - 1], vseq[y - 1][x])) + 1 : 0; ans = max(ans, sq[y][x]); } } /* for(int y=1; y<=n; ++y) { for(int x=1; x<=n; ++x) { printf(" %2d", sq[y][x]); } printf("\n"); } */ printf("%d\n", ans); } return 0; }
replace
3
4
3
4
0
p00092
C++
Runtime Error
#include <algorithm> #include <stdio.h> using namespace std; int main() { int n, ans = 0; int dp[110][110]; char field; while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { scanf(" %c", &field); dp[j + 1][i + 1] = 0; if (field == '*') dp[j + 1][i + 1] = -1; } for (int i = 1; i < n + 1; i++) { for (int j = 1; j < n + 1; j++) { if (dp[j][i] == -1) ; else if (j == 1 || i == 1) dp[j][i] = 1; else dp[j][i] = max( 1, min(dp[j - 1][i - 1], min(dp[j - 1][i], dp[j][i - 1])) + 1); ans = max(ans, dp[j][i]); } } /*for(int i = 1; i < n + 1; i++) { for(int j = 1; j < n + 1; j++) { printf("%2d",dp[j][i]); } printf("\n"); }*/ printf("%d\n", ans); ans = 0; } return 0; }
#include <algorithm> #include <stdio.h> using namespace std; int main() { int n, ans = 0; int dp[1100][1100]; char field; while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { scanf(" %c", &field); dp[j + 1][i + 1] = 0; if (field == '*') dp[j + 1][i + 1] = -1; } for (int i = 1; i < n + 1; i++) { for (int j = 1; j < n + 1; j++) { if (dp[j][i] == -1) ; else if (j == 1 || i == 1) dp[j][i] = 1; else dp[j][i] = max( 1, min(dp[j - 1][i - 1], min(dp[j - 1][i], dp[j][i - 1])) + 1); ans = max(ans, dp[j][i]); } } /*for(int i = 1; i < n + 1; i++) { for(int j = 1; j < n + 1; j++) { printf("%2d",dp[j][i]); } printf("\n"); }*/ printf("%d\n", ans); ans = 0; } return 0; }
replace
5
6
5
6
0
p00092
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> using namespace std; int n; int ans; int dp[10000][10000]; int main() { while (1) { scanf("%d", &n); if (n == 0) return 0; ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { char c; scanf("%c ", &c); if (c == '.') { dp[i][j] = 1; if (i > 0 && j > 0) { int t = min(dp[i - 1][j], dp[i][j - 1]); dp[i][j] = max(dp[i][j], min(t, dp[i - 1][j - 1]) + 1); } } else dp[i][j] = 0; ans = max(ans, dp[i][j]); } } printf("%d\n", ans); } }
#include <algorithm> #include <cstdio> using namespace std; int n; int ans; int dp[10000][10000]; int main() { while (1) { scanf("%d", &n); if (n == 0) return 0; ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { char c; scanf(" %c", &c); if (c == '.') { dp[i][j] = 1; if (i > 0 && j > 0) { int t = min(dp[i - 1][j], dp[i][j - 1]); dp[i][j] = max(dp[i][j], min(t, dp[i - 1][j - 1]) + 1); } } else dp[i][j] = 0; ans = max(ans, dp[i][j]); } } printf("%d\n", ans); } }
replace
18
19
18
19
TLE
p00092
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iostream> #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++) using namespace std; int w[1005][1005]; int main() { string s[1005]; int n; while (cin >> n && n) { memset(w, 0, sizeof(w)); rep(i, n) { cin >> s[i]; } rep(i, n) { rep(j, n) { if (s[i][j] == '*') w[i][j] = 0; else w[i][j] = 1; } } int ans = 0; rep(i, n) { rep(j, n) { if (s[i][j] == '*') { w[i][j] = 0; } else { w[i][j] = min(w[i - 1][j - 1], min(w[i - 1][j], w[i][j - 1])) + 1; ans = max(ans, w[i][j]); } } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #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++) using namespace std; int w[1005][1005]; int main() { string s[1005]; int n; while (cin >> n && n) { memset(w, 0, sizeof(w)); rep(i, n) { cin >> s[i]; } rep(i, n) { rep(j, n) { if (s[i][j] == '*') w[i][j] = 0; else w[i][j] = 1; } } int ans = 0; REP(i, 1, n) { REP(j, 1, n) { if (s[i][j] == '*') { w[i][j] = 0; } else { w[i][j] = min(w[i - 1][j - 1], min(w[i - 1][j], w[i][j - 1])) + 1; ans = max(ans, w[i][j]); } } } cout << ans << endl; } return 0; }
replace
29
31
29
31
0
p00092
C++
Runtime Error
#include <cctype> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <deque> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repi(i, l, n) for (int(i) = (int)(l); (i) < (int)(n); (i)++) #define d_arr(arr, h, w) \ rep(i, (h)) { \ cout << "["; \ rep(j, (w)) { cout << (arr)[i][j] << ", "; } \ cout << "]" << endl; \ } #define IN(x, s, g) ((x) >= (s) && (x) < (g)) #define ISIN(x, y, w, h) (IN((x), 0, (w)) && IN((y), 0, (h))) #define print(x) printf("%d\n", x); typedef pair<int, int> P; class car { int id; int num; public: car(int x, int y) { id = x; num = y; } }; int main() { char grid[500][500]; int dp[500][500]; int N; int maxn = 0; cin >> N; while (N != 0) { maxn = 0; rep(i, N) { rep(j, N) { cin >> grid[i][j]; } } rep(i, N) { rep(j, N) { if (grid[i][j] == '*') { dp[i][j] = 0; continue; } if (i == 0 && j == 0) { dp[i][j] = 1; } else if (i == 0 | j == 0) { dp[i][j] = 1; } else { dp[i][j] = 1 + min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]); // cout << "min(" << dp[i-1][j] << "," << dp[i][j-1] << "," << // dp[i-1][j-1] << ") = " << endl; cout << dp[i][j] << endl; } } } rep(i, N) { rep(j, N) { if (maxn < dp[i][j]) { maxn = dp[i][j]; } } } cout << maxn << endl; cin >> N; } return 0; }
#include <cctype> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <algorithm> #include <deque> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repi(i, l, n) for (int(i) = (int)(l); (i) < (int)(n); (i)++) #define d_arr(arr, h, w) \ rep(i, (h)) { \ cout << "["; \ rep(j, (w)) { cout << (arr)[i][j] << ", "; } \ cout << "]" << endl; \ } #define IN(x, s, g) ((x) >= (s) && (x) < (g)) #define ISIN(x, y, w, h) (IN((x), 0, (w)) && IN((y), 0, (h))) #define print(x) printf("%d\n", x); typedef pair<int, int> P; class car { int id; int num; public: car(int x, int y) { id = x; num = y; } }; int main() { char grid[1000][1000]; int dp[1000][1000]; int N; int maxn = 0; cin >> N; while (N != 0) { maxn = 0; rep(i, N) { rep(j, N) { cin >> grid[i][j]; } } rep(i, N) { rep(j, N) { if (grid[i][j] == '*') { dp[i][j] = 0; continue; } if (i == 0 && j == 0) { dp[i][j] = 1; } else if (i == 0 | j == 0) { dp[i][j] = 1; } else { dp[i][j] = 1 + min(min(dp[i - 1][j], dp[i][j - 1]), dp[i - 1][j - 1]); // cout << "min(" << dp[i-1][j] << "," << dp[i][j-1] << "," << // dp[i-1][j-1] << ") = " << endl; cout << dp[i][j] << endl; } } } rep(i, N) { rep(j, N) { if (maxn < dp[i][j]) { maxn = dp[i][j]; } } } cout << maxn << endl; cin >> N; } return 0; }
replace
40
42
40
42
0
p00092
C++
Time Limit Exceeded
// 23 #include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { for (int n; cin >> n, n;) { int c[1000] = {}; int ans = 0; for (int i = 0; i < n; i++) { char l[1001]; cin >> l; int cl[1000]; for (int j = 0; j < n; j++) { cl[j] = (l[j] == '*') ? 0 : c[j] + 1; } for (int j = 1; j <= n; j++) { int ms = 0, cs = 0; for (int k = 0; k < n; k++) { if (cl[k] >= j) { cs++; ms = max(ms, cs); } else { cs = 0; } } if (ms < j) break; ans = max(ans, j); } memcpy(c, cl, sizeof(c)); } cout << ans << endl; } return 0; }
// 23 #include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { for (int n; cin >> n, n;) { int c[1000] = {}; int ans = 0; for (int i = 0; i < n; i++) { char l[1001]; cin >> l; int cl[1000]; for (int j = 0; j < n; j++) { cl[j] = (l[j] == '*') ? 0 : c[j] + 1; } for (int j = ans + 1; j <= n; j++) { int ms = 0, cs = 0; for (int k = 0; k < n; k++) { if (cl[k] >= j) { cs++; ms = max(ms, cs); } else { cs = 0; } } if (ms < j) break; ans = max(ans, j); } memcpy(c, cl, sizeof(c)); } cout << ans << endl; } return 0; }
replace
18
19
18
19
TLE
p00092
C++
Runtime Error
#include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cctype> // require tolower, toupper #include <cfloat> #include <climits> #include <cmath> // require fabs #include <cstdio> // require scanf printf #include <cstdlib> // require abs exit atof atoi #include <cstring> // require memset #include <ctime> // require srand #include <deque> #include <fstream> // require freopen #include <functional> #include <iomanip> // require setw #include <iostream> #include <limits> #include <map> #include <numeric> // require accumulate #include <queue> #include <set> #include <sstream> // require stringstream #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair<int, int> P; char grid[12][12]; int dp[12][12]; void disp_grid(int n) { cout << "grid: " << endl; rep(i, n) { rep(j, n) { cout << grid[i][j]; } // end rep cout << endl; } // end rep } void disp_dp(int n) { cout << "dp: " << endl; rep(i, n) { rep(j, n) { cout << dp[i][j]; } // end rep cout << endl; } // end rep } int main() { // cut here before submit // freopen ("testcase.square_searching", "r", stdin ); int n; while (scanf("%d", &n), n) { memset(grid, 0, sizeof(grid)); memset(dp, 0, sizeof(dp)); rep(i, n) { rep(j, n) { scanf(" %c", &grid[i][j]); } // end rep } // end rep dp[0][0] = (grid[0][0] == '.' ? 1 : 0); for (int i = 1; i < n; i++) { dp[i][0] = (grid[i][0] == '*' ? 0 : 1); } // end for for (int j = 1; j < n; j++) { dp[0][j] = (grid[0][j] == '*' ? 0 : 1); } // end for for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { dp[i][j] = (grid[i][j] == '*' ? 0 : min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1); } // end for } // end for // disp_grid (n ); // disp_dp (n ); int res = 0; for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { res = max(res, dp[i][j]); } // end for } // end for printf("%d\n", res); } // end loop return 0; }
#include <algorithm> // require sort next_permutation count __gcd reverse etc. #include <cctype> // require tolower, toupper #include <cfloat> #include <climits> #include <cmath> // require fabs #include <cstdio> // require scanf printf #include <cstdlib> // require abs exit atof atoi #include <cstring> // require memset #include <ctime> // require srand #include <deque> #include <fstream> // require freopen #include <functional> #include <iomanip> // require setw #include <iostream> #include <limits> #include <map> #include <numeric> // require accumulate #include <queue> #include <set> #include <sstream> // require stringstream #include <stack> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair<int, int> P; char grid[1005][1005]; int dp[1005][1005]; void disp_grid(int n) { cout << "grid: " << endl; rep(i, n) { rep(j, n) { cout << grid[i][j]; } // end rep cout << endl; } // end rep } void disp_dp(int n) { cout << "dp: " << endl; rep(i, n) { rep(j, n) { cout << dp[i][j]; } // end rep cout << endl; } // end rep } int main() { // cut here before submit // freopen ("testcase.square_searching", "r", stdin ); int n; while (scanf("%d", &n), n) { memset(grid, 0, sizeof(grid)); memset(dp, 0, sizeof(dp)); rep(i, n) { rep(j, n) { scanf(" %c", &grid[i][j]); } // end rep } // end rep dp[0][0] = (grid[0][0] == '.' ? 1 : 0); for (int i = 1; i < n; i++) { dp[i][0] = (grid[i][0] == '*' ? 0 : 1); } // end for for (int j = 1; j < n; j++) { dp[0][j] = (grid[0][j] == '*' ? 0 : 1); } // end for for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { dp[i][j] = (grid[i][j] == '*' ? 0 : min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1); } // end for } // end for // disp_grid (n ); // disp_dp (n ); int res = 0; for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { res = max(res, dp[i][j]); } // end for } // end for printf("%d\n", res); } // end loop return 0; }
replace
30
32
30
32
0
p00092
C++
Time Limit Exceeded
// Name: Square Searching // Level: 2 // Category: 動的計画法,DP,累積和 // Note: /* * 座標(0,0)と(r,c)をそれぞれ左上,右下に持つ矩形を考えて,その中の*の数を記憶しておく. * これを使うと任意の矩形内の*の数がO(1)で求められる. * 正方形の左上は任意に決められるのでN^2通り存在し,それに対応する右下の決め方は高々N通りである. * (正方形であることに注意). * したがって,ナイーブに探索するとO(N^3)個の正方形について内部の*の数を数え,0個のもののサイズを覚えればよい. */ #include <algorithm> #include <iostream> #include <string> using namespace std; int dp[1000][1000]; int N; inline int get(int r, int c) { if (r < 0 || r >= N || c < 0 || c >= N) return 0; return dp[r][c]; } int main() { cin.tie(0); ios::sync_with_stdio(0); while (cin >> N) { if (N == 0) break; for (int i = 0; i < N; ++i) { string line; cin >> line; for (int c = 0; c < N; ++c) { dp[i][c] = get(i - 1, c) + get(i, c - 1) - get(i - 1, c - 1); if (line[c] == '*') dp[i][c]++; } } int ans = 0; for (int r = 0; r < N; ++r) { for (int c = 0; c < N; ++c) { for (int size = 1; size <= N; ++size) { const int er = r + size - 1; const int ec = c + size - 1; if (er >= N || ec >= N) break; const int marks = get(er, ec) - get(er, c - 1) - get(r - 1, ec) + get(r - 1, c - 1); if (marks == 0) { ans = max(ans, size); } } } } cout << ans << endl; } return 0; }
// Name: Square Searching // Level: 2 // Category: 動的計画法,DP,累積和 // Note: /* * 座標(0,0)と(r,c)をそれぞれ左上,右下に持つ矩形を考えて,その中の*の数を記憶しておく. * これを使うと任意の矩形内の*の数がO(1)で求められる. * 正方形の左上は任意に決められるのでN^2通り存在し,それに対応する右下の決め方は高々N通りである. * (正方形であることに注意). * したがって,ナイーブに探索するとO(N^3)個の正方形について内部の*の数を数え,0個のもののサイズを覚えればよい. */ #include <algorithm> #include <iostream> #include <string> using namespace std; int dp[1000][1000]; int N; inline int get(int r, int c) { if (r < 0 || r >= N || c < 0 || c >= N) return 0; return dp[r][c]; } int main() { cin.tie(0); ios::sync_with_stdio(0); while (cin >> N) { if (N == 0) break; for (int i = 0; i < N; ++i) { string line; cin >> line; for (int c = 0; c < N; ++c) { dp[i][c] = get(i - 1, c) + get(i, c - 1) - get(i - 1, c - 1); if (line[c] == '*') dp[i][c]++; } } int ans = 0; for (int r = 0; r < N; ++r) { for (int c = 0; c < N; ++c) { for (int size = ans + 1; size <= N; ++size) { const int er = r + size - 1; const int ec = c + size - 1; if (er >= N || ec >= N) break; const int marks = get(er, ec) - get(er, c - 1) - get(r - 1, ec) + get(r - 1, c - 1); if (marks == 0) { ans = max(ans, size); } } } } cout << ans << endl; } return 0; }
replace
45
46
45
46
TLE
p00092
C++
Runtime Error
#include <cstdio> #include <iostream> #define INF 2100000000 using namespace std; int minix(int a, int b, int c) { if (b >= a && c >= a) { return a; } if (a >= b && c >= b) { return b; } if (b >= c && a >= c) { return c; } } int main() { int n; int masu[102][102]; int ura[102][102]; char str[1002]; while (1) { scanf("%d", &n); if (n == 0) { break; } for (int i = 1; i <= n; i++) { scanf("%s", str); for (int j = 1; j <= n; j++) { if (str[j - 1] == '.') { ura[i][j] = 0; } else { ura[i][j] = 1; } } } for (int i = 0; i <= n; i++) { masu[i][0] = masu[0][i] = 0; } int maxi = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (ura[i][j] == 0) { masu[i][j] = minix(masu[i - 1][j], masu[i][j - 1], masu[i - 1][j - 1]) + 1; maxi = max(masu[i][j], maxi); } else { masu[i][j] = 0; } } } printf("%d\n", maxi); } }
#include <cstdio> #include <iostream> #define INF 2100000000 using namespace std; int minix(int a, int b, int c) { if (b >= a && c >= a) { return a; } if (a >= b && c >= b) { return b; } if (b >= c && a >= c) { return c; } } int main() { int n; int masu[1002][1002]; int ura[1002][1002]; char str[1002]; while (1) { scanf("%d", &n); if (n == 0) { break; } for (int i = 1; i <= n; i++) { scanf("%s", str); for (int j = 1; j <= n; j++) { if (str[j - 1] == '.') { ura[i][j] = 0; } else { ura[i][j] = 1; } } } for (int i = 0; i <= n; i++) { masu[i][0] = masu[0][i] = 0; } int maxi = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (ura[i][j] == 0) { masu[i][j] = minix(masu[i - 1][j], masu[i][j - 1], masu[i - 1][j - 1]) + 1; maxi = max(masu[i][j], maxi); } else { masu[i][j] = 0; } } } printf("%d\n", maxi); } }
replace
21
23
21
23
0
p00092
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int isSquare(string map[], int x, int y, int size) { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { int nx = x + j, ny = y + i; if (nx >= map[0].length() || ny >= map[0].length()) return 0; if (map[ny][nx] == '*') return 0; } } return 1; } int main() { int n; while (1) { cin >> n; if (n == 0) break; string map[10]; getchar(); for (int i = 0; i < n; i++) { getline(cin, map[i]); } int max = 0; for (int s = 1; s <= n; s++) { bool flag = false; for (int i = 0; !flag && i <= n - s; i++) { for (int j = 0; !flag && j <= n - s; j++) { if (isSquare(map, j, i, s)) { max = s; flag = true; } } } if (!flag) break; } cout << max << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int isSquare(string map[], int x, int y, int size) { for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { int nx = x + j, ny = y + i; if (nx >= map[0].length() || ny >= map[0].length()) return 0; if (map[ny][nx] == '*') return 0; } } return 1; } int main() { int n; while (1) { cin >> n; if (n == 0) break; string map[n]; getchar(); for (int i = 0; i < n; i++) { getline(cin, map[i]); } int max = 0; for (int s = 1; s <= n; s++) { bool flag = false; for (int i = 0; !flag && i <= n - s; i++) { for (int j = 0; !flag && j <= n - s; j++) { if (isSquare(map, j, i, s)) { max = s; flag = true; } } } if (!flag) break; } cout << max << endl; } return 0; }
replace
24
25
24
25
0
p00092
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <stdio.h> int n; using namespace std; /* int main(){ n=1000; box = new int*[n]; for(int i=0; i<n; i++)box[i] = new int[n]; while(cin>>n){ if(n==0)break; char c; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin>>c; if(c=='.')box[i][j]=0; else box[i][j]=1; } } int ans=0; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(box[i][j]==0){ bool flag=true; for(int k=i; k<i+ans+1; k++){ if(k==n){ flag=false; break; } for(int l=j; l<j+ans+1; l++){ if(l==n){ flag=false; break; } if(box[k][l]==1){ flag=false; break; } } if(!flag)break; } if(flag){ ans++; j--; } } } } cout<<ans<<endl; } n=1000; for(int i=0; i<n; i++)delete[] box[i]; delete[] box; } */ /* int main(){ n=1000; box = new int*[n]; for(int i=0; i<n; i++)box[i] = new int[n]; while(cin>>n){ if(n==0)break; char c; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin>>c; if(c=='.')box[i][j]=0; else box[i][j]=1; } } int ans=0; for(int i=0; i<n; i++){ if(ans>(n-i)*(n-i))break; for(int j=0; j<n; j++){ if(ans>(n-j)*(n-j))break; if(box[i][j]==0){ int temp=1; bool f=true; for(int k=j; k<=j+ans; k++){ if(box[i][k]==1){ f=false; break; } if(!f)break; } while(1){ bool flag=true; for(int k=i; k<=i+temp; k++){ if(k==n){ flag=false; break; } if(box[k][j+temp]!=0){ flag=false; break; } } for(int k=j; k<=j+temp; k++){ if(k==n){ flag=false; break; } if(box[i+temp][k]!=0){ flag=false; break; } } if(flag)temp++; else break; } ans=max(ans, temp); } } } cout<<ans<<endl; } n=1000; for(int i=0; i<n; i++)delete[] box[i]; delete[] box; } */ int main() { while (cin >> n) { if (n == 0) break; int box[1001][1001] = {0}; char c; for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { cin >> c; if (c == '.') { count++; box[i][j] = count; } else { count = 0; box[i][j] = 0; } } } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int temp = box[i][j]; if (temp > ans) { for (int k = i; k < i + box[i][j]; k++) { if (temp <= k - i) break; temp = min(temp, box[k][j]); } ans = max(temp, ans); } } } cout << ans << endl; } }
#include <algorithm> #include <iostream> #include <stdio.h> int n; using namespace std; /* int main(){ n=1000; box = new int*[n]; for(int i=0; i<n; i++)box[i] = new int[n]; while(cin>>n){ if(n==0)break; char c; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin>>c; if(c=='.')box[i][j]=0; else box[i][j]=1; } } int ans=0; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ if(box[i][j]==0){ bool flag=true; for(int k=i; k<i+ans+1; k++){ if(k==n){ flag=false; break; } for(int l=j; l<j+ans+1; l++){ if(l==n){ flag=false; break; } if(box[k][l]==1){ flag=false; break; } } if(!flag)break; } if(flag){ ans++; j--; } } } } cout<<ans<<endl; } n=1000; for(int i=0; i<n; i++)delete[] box[i]; delete[] box; } */ /* int main(){ n=1000; box = new int*[n]; for(int i=0; i<n; i++)box[i] = new int[n]; while(cin>>n){ if(n==0)break; char c; for(int i=0; i<n; i++){ for(int j=0; j<n; j++){ cin>>c; if(c=='.')box[i][j]=0; else box[i][j]=1; } } int ans=0; for(int i=0; i<n; i++){ if(ans>(n-i)*(n-i))break; for(int j=0; j<n; j++){ if(ans>(n-j)*(n-j))break; if(box[i][j]==0){ int temp=1; bool f=true; for(int k=j; k<=j+ans; k++){ if(box[i][k]==1){ f=false; break; } if(!f)break; } while(1){ bool flag=true; for(int k=i; k<=i+temp; k++){ if(k==n){ flag=false; break; } if(box[k][j+temp]!=0){ flag=false; break; } } for(int k=j; k<=j+temp; k++){ if(k==n){ flag=false; break; } if(box[i+temp][k]!=0){ flag=false; break; } } if(flag)temp++; else break; } ans=max(ans, temp); } } } cout<<ans<<endl; } n=1000; for(int i=0; i<n; i++)delete[] box[i]; delete[] box; } */ int main() { while (cin >> n) { if (n == 0) break; int box[1001][1001] = {0}; char c; for (int i = 0; i < n; i++) { int count = 0; for (int j = 0; j < n; j++) { cin >> c; if (c == '.') { count++; box[i][j] = count; } else { count = 0; box[i][j] = 0; } } } int ans = 0; for (int i = 0; i < n; i++) { for (int j = n - 1; j >= 0; j--) { int temp = box[i][j]; if (temp > ans) { for (int k = i; k < i + box[i][j]; k++) { if (temp <= k - i) break; temp = min(temp, box[k][j]); } ans = max(temp, ans); } } } cout << ans << endl; } }
replace
176
177
176
177
TLE
p00092
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int n; for (; cin >> n, n;) { string map[n]; int sum[n][n]; for (int i = 0; i < n; i++) { cin >> map[i]; for (int j = 0; j < n; j++) { int tmp = 0; if (j > 0) tmp += sum[i][j - 1]; if (i > 0) tmp += sum[i - 1][j]; if (j > 0 && i > 0) tmp -= sum[i - 1][j - 1]; if (map[i][j] == '.') tmp++; sum[i][j] = tmp; } } /* cout<<endl; for(int i=0;i<n;i++,cout<<endl) for(int j=0;j<n;j++) printf("%3d ",sum[i][j]);*/ int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int x = min(i, j); x >= 0; x--) { int tmp = sum[i][j]; if (i - x > 0) tmp -= sum[i - x - 1][j]; if (j - x > 0) tmp -= sum[i][j - x - 1]; if (i - x > 0 && j - x > 0) tmp += sum[i - x - 1][j - x - 1]; if ((x + 1) * (x + 1) == tmp) ans = max(x + 1, ans); } cout << ans << endl; } }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int n; for (; cin >> n, n;) { string map[n]; int sum[n][n]; for (int i = 0; i < n; i++) { cin >> map[i]; for (int j = 0; j < n; j++) { int tmp = 0; if (j > 0) tmp += sum[i][j - 1]; if (i > 0) tmp += sum[i - 1][j]; if (j > 0 && i > 0) tmp -= sum[i - 1][j - 1]; if (map[i][j] == '.') tmp++; sum[i][j] = tmp; } } /* cout<<endl; for(int i=0;i<n;i++,cout<<endl) for(int j=0;j<n;j++) printf("%3d ",sum[i][j]);*/ int ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int x = min(i, j); x >= ans; x--) { int tmp = sum[i][j]; if (i - x > 0) tmp -= sum[i - x - 1][j]; if (j - x > 0) tmp -= sum[i][j - x - 1]; if (i - x > 0 && j - x > 0) tmp += sum[i - x - 1][j - x - 1]; if ((x + 1) * (x + 1) == tmp) ans = max(x + 1, ans); } cout << ans << endl; } }
replace
32
33
32
33
TLE
p00092
C++
Runtime Error
#include <cstdio> #include <iostream> #include <string> using namespace std; int dp[1002][1002]; int main() { int n; while (scanf("%d", &n), n) { int ret = 0; char line[101]; for (int i = 1; i <= n; ++i) { scanf("%s", line); for (int j = 0; j < n; ++j) { if (line[j] == '.') { dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1; ret = max(ret, dp[i][j]); } else { dp[i][j] = 0; } } } printf("%d\n", ret); } return 0; }
#include <cstdio> #include <iostream> #include <string> using namespace std; int dp[1002][1002]; int main() { int n; while (scanf("%d", &n), n) { int ret = 0; char line[1001]; for (int i = 1; i <= n; ++i) { scanf("%s", line); for (int j = 0; j < n; ++j) { if (line[j] == '.') { dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1; ret = max(ret, dp[i][j]); } else { dp[i][j] = 0; } } } printf("%d\n", ret); } return 0; }
replace
11
12
11
12
0
p00093
C++
Time Limit Exceeded
#include <iostream> using namespace std; int x[10000], y[10000][10000], a, b, cnt2; void uruu(int s) { for (int i = 0; i < s; i++) { if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { x[i] = 1; } } } void hantei(int start, int end) { int cnt = 0; for (int i = start; i <= end; i++) { if (x[i]) { cout << i << endl; cnt++; } } if (!cnt) { cout << "NA" << endl; } } int main() { uruu(10000); while (true) { cin >> a >> b; if (cnt2) { cout << endl; } cnt2++; hantei(a, b); } }
#include <iostream> using namespace std; int x[10000], y[10000][10000], a, b, cnt2; void uruu(int s) { for (int i = 0; i < s; i++) { if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { x[i] = 1; } } } void hantei(int start, int end) { int cnt = 0; for (int i = start; i <= end; i++) { if (x[i]) { cout << i << endl; cnt++; } } if (!cnt) { cout << "NA" << endl; } } int main() { uruu(10000); while (true) { cin >> a >> b; if (!a) { break; } if (cnt2) { cout << endl; } cnt2++; hantei(a, b); } }
insert
29
29
29
32
TLE
p00094
C++
Time Limit Exceeded
#include <cstdio> int main() { int a, b; for (; scanf("%d%d", &a, &b);) printf("%f", (double)a * b / 3.305785); }
#include <cstdio> int main() { int a, b; for (; ~scanf("%d%d", &a, &b);) printf("%f", (double)a * b / 3.305785); }
replace
3
4
3
4
TLE
p00095
C++
Time Limit Exceeded
#include <stdio.h> int main() { int x, y, n; int X = 0, Y = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", &x, &y); if (i = 0) { Y = y; X = x; } if (Y == y && x < X) { X = x; Y = y; } else if (Y < y) { X = x; Y = y; } } printf("%d %d\n", X, Y); return 0; }
#include <stdio.h> int main() { int x, y, n; int X = 0, Y = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d %d", &x, &y); if (i == 0) { Y = y; X = x; } if (Y == y && x < X) { X = x; Y = y; } else if (Y < y) { X = x; Y = y; } } printf("%d %d\n", X, Y); return 0; }
replace
11
12
11
12
TLE
p00096
C++
Runtime Error
#include <iostream> using namespace std; int ab[2001]; int main() { int n; while (cin >> n) { int ans = 0; for (int i = 0; i < 2001; i++) ab[i] = 0; for (int a = 0; a <= 1000; a++) for (int b = 0; b <= 1000; b++) ab[a + b]++; for (int c = 0; c <= 1000; c++) for (int d = 0; d <= 1000; d++) if (n - c - d >= 0) ans += ab[n - c - d]; cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int ab[2001]; int main() { int n; while (cin >> n) { int ans = 0; for (int i = 0; i < 2001; i++) ab[i] = 0; for (int a = 0; a <= 1000; a++) for (int b = 0; b <= 1000; b++) ab[a + b]++; for (int c = 0; c <= 1000; c++) for (int d = 0; d <= 1000; d++) if (n - c - d >= 0 && n - c - d <= 2000) ans += ab[n - c - d]; cout << ans << endl; } return 0; }
replace
21
22
21
22
0
p00096
C++
Time Limit Exceeded
#define _crt_secure_no_warnings #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #ifdef __GXX_EXPERIMENTAL_CXX0X__ #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #ifdef __GXX_EXPERIMENTAL_CXX0X__ #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; int data[4][4001] = {}; long long int saiki(int N, int x) { if (N < 0) return 0; if (N > x * 1000) return 0; if (x == 1 && N <= 1000) return 1; int count = 0; for (size_t i = 0; i <= 1000 && i <= N; i++) { // if (!data[x - 1][N - i]) { data[x - 1][N - i] = saiki(N - i, x - 1); } count += data[x - 1][N - i]; } return count; } int main() { int N; while (cin >> N) { cout << saiki(N, 4) << endl; } }
#define _crt_secure_no_warnings #ifndef _GLIBCXX_NO_ASSERT #include <cassert> #endif #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #ifdef __GXX_EXPERIMENTAL_CXX0X__ #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> #endif #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #ifdef __GXX_EXPERIMENTAL_CXX0X__ #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; int data[4][4001] = {}; long long int saiki(int N, int x) { if (N < 0) return 0; if (N > x * 1000) return 0; if (x == 1 && N <= 1000) return 1; int count = 0; for (size_t i = 0; i <= 1000 && i <= N; i++) { if (!data[x - 1][N - i]) { data[x - 1][N - i] = saiki(N - i, x - 1); } count += data[x - 1][N - i]; } return count; } int main() { int N; while (cin >> N) { cout << saiki(N, 4) << endl; } }
replace
99
101
99
102
TLE
p00096
C++
Time Limit Exceeded
#include <iostream> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) using namespace std; int main() { int n; while (cin >> n) { int ans = 0; int x = 0; if (n > 3000) x = n - 3000; for (int i = x; i < 1001 && i <= n; i++) { // cout<<i<<"-"<<endl; int y = 0; if (n - i > 2000) y = n - i - 2000; for (int j = y; j < 1001 && i + j <= n; j++) { // cout<<j<<"--"<<endl; // if(n-i-j>=2001)continue; int z = 0; if (n - i - j > 1000) z = n - i - j - 1000; for (int k = z; k < 1001 && i + j + k <= n; k++) { // cout<<k<<"---"<<endl;; ans++; } } } cout << ans << endl; } return 0; }
#include <iostream> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) using namespace std; int main() { int n; while (cin >> n) { int ans = 0; int x = 0; if (n > 3000) x = n - 3000; for (int i = x; i < 1001 && i <= n; i++) { // cout<<i<<"-"<<endl; int y = 0; if (n - i > 2000) y = n - i - 2000; for (int j = y; j < 1001 && i + j <= n; j++) { // cout<<j<<"--"<<endl; // if(n-i-j>=2001)continue; int z = 0; if (n - i - j > 1000) z = n - i - j - 1000; int zz = 1001; if (1001 > n - i - j + 1) zz = n - i - j + 1; ans += zz - z; } } cout << ans << endl; } return 0; }
replace
25
29
25
30
TLE
p00096
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int main() { int num[2001] = {0}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { num[i + j]++; } } int n; while (cin >> n, n) { int res = 0; for (int i = 0; i <= n; i++) { if (i > 2000 || n - i > 2000) continue; res += num[i] * num[n - i]; } cout << res << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int num[2001] = {0}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { num[i + j]++; } } int n; while (cin >> n) { int res = 0; for (int i = 0; i <= n; i++) { if (i > 2000 || n - i > 2000) continue; res += num[i] * num[n - i]; } cout << res << endl; } return 0; }
replace
13
14
13
14
TLE
p00096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MP make_pair #define PB push_back #define MOD 1000000007 #define INF (1LL << 30) #define LLINF (1LL << 60) #define PI 3.14159265359 #define EPS 1e-12 #define int ll signed main(void) { int n; while (cin >> n) { int a[2010] = {0}; REP(i, 1001) REP(j, 1001) { a[i + j]++; } int ret = 0; REP(i, 1001) REP(j, 1001) { if (i + j <= n) { ret += a[n - i - j]; } } cout << ret << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MP make_pair #define PB push_back #define MOD 1000000007 #define INF (1LL << 30) #define LLINF (1LL << 60) #define PI 3.14159265359 #define EPS 1e-12 #define int ll signed main(void) { int n; while (cin >> n) { int a[5010] = {0}; REP(i, 1001) REP(j, 1001) { a[i + j]++; } int ret = 0; REP(i, 1001) REP(j, 1001) { if (i + j <= n) { ret += a[n - i - j]; } } cout << ret << endl; } return 0; }
replace
25
26
25
26
0
p00096
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int dp[2000]; int main() { memset(dp, 0, sizeof(dp)); for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { dp[i + j]++; } } int n; while (cin >> n) { int ans = 0; for (int i = 0; i <= n; i++) { ans += dp[i] * dp[n - i]; } cout << ans << endl; } return 0; }
#include <cstring> #include <iostream> using namespace std; int dp[4000]; int main() { memset(dp, 0, sizeof(dp)); for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { dp[i + j]++; } } int n; while (cin >> n) { int ans = 0; for (int i = 0; i <= n; i++) { ans += dp[i] * dp[n - i]; } cout << ans << endl; } return 0; }
replace
5
6
5
6
0
p00096
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; long r; while (cin >> n) { r = 0; for (int a = 0; a <= 1000; a++) { for (int b = 0; b <= 1000; b++) { for (int c = 0; c <= 1000; c++) { int d = n - a - b - c; if (d >= 0 && d <= 1000) r++; } } } cout << r << endl; } return (0); }
#include <bits/stdc++.h> using namespace std; int main() { int n; long r; while (cin >> n) { r = 0; for (int a = 0; a <= 1000; a++) { for (int b = 0; b <= 1000; b++) { int s = n - a - b; if (s <= 1000 && s >= 0) { r += s + 1; } else if (s <= 2000 && s > 1000) { r += 2001 - s; } } } cout << r << endl; } return (0); }
replace
10
14
10
15
TLE
p00096
C++
Runtime Error
#include <algorithm> #include <cassert> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(c) (c).begin(), (c).end() #define mp make_pair #define pb push_back #define each(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int n, dp[2010]; int main() { rep(i, 1001) rep(j, 1001) dp[i + j]++; while (cin >> n) { ll ans = 0; rep(i, n + 1) ans += (ll)dp[i] * dp[n - i]; cout << ans << endl; } return 0; }
#include <algorithm> #include <cassert> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(c) (c).begin(), (c).end() #define mp make_pair #define pb push_back #define each(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int n, dp[4010]; int main() { rep(i, 1001) rep(j, 1001) dp[i + j]++; while (cin >> n) { ll ans = 0; rep(i, n + 1) ans += (ll)dp[i] * dp[n - i]; cout << ans << endl; } return 0; }
replace
28
29
28
29
0
p00096
C++
Runtime Error
#include <cstring> #include <iostream> int half[2001]; // 0<=a, b<=1000 として a+b となる組み合わせの数 void makeSet() { memset(half, 0, sizeof(half)); // 半分全列挙 for (int i = 0; i <= 1000; ++i) { for (int j = 0; j <= 1000; ++j) { int k = i + j; ++half[k]; } } } int solve(int n) { int num = 0; int max = n < 2000 ? n : 2000; // Counterが半分全列挙の上限を超えない為 for (int i = 0; i <= max; ++i) { num += half[i] * half[n - i]; // 左半分の組み合わせ * 右半分の組み合わせ = 全組み合わせ } return num; } int main() { makeSet(); while (true) { int n; std::cin >> n; if (std::cin.eof()) break; std::cout << solve(n) << std::endl; } return 0; }
#include <cstring> #include <iostream> int half[2001]; // 0<=a, b<=1000 として a+b となる組み合わせの数 void makeSet() { memset(half, 0, sizeof(half)); // 半分全列挙 for (int i = 0; i <= 1000; ++i) { for (int j = 0; j <= 1000; ++j) { int k = i + j; ++half[k]; } } } int solve(int n) { int num = 0; int max = n < 2000 ? n : 2000; // Counterが半分全列挙の上限を超えない為 for (int i = 0; i <= max; ++i) { if (n - i <= 2000) num += half[i] * half[n - i]; // 左半分の組み合わせ * 右半分の組み合わせ = 全組み合わせ } return num; } int main() { makeSet(); while (true) { int n; std::cin >> n; if (std::cin.eof()) break; std::cout << solve(n) << std::endl; } return 0; }
replace
21
24
21
25
0
p00096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i <= (n); i++) int dp[2020]; int main() { int n; rep(i, 1000) rep(j, 1000) { dp[i + j]++; } while (cin >> n) { int ans = 0; rep(i, n) ans += dp[i] * dp[n - i]; cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i <= (n); i++) int dp[4040]; int main() { int n; rep(i, 1000) rep(j, 1000) { dp[i + j]++; } while (cin >> n) { int ans = 0; rep(i, n) ans += dp[i] * dp[n - i]; cout << ans << endl; } }
replace
5
6
5
6
0
p00096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<int> v; int a[2001]; int main() { for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { a[i + j]++; } } int n; while (~scanf("%d", &n)) { int res = 0; for (int i = 0; i <= n; i++) { res += a[i] * a[n - i]; } printf("%d\n", res); } }
#include <bits/stdc++.h> using namespace std; vector<int> v; int a[10001]; int main() { for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { a[i + j]++; } } int n; while (~scanf("%d", &n)) { int res = 0; for (int i = 0; i <= n; i++) { res += a[i] * a[n - i]; } printf("%d\n", res); } }
replace
4
5
4
5
0
p00096
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int n; int cnt[2020]; void setcnt() { memset(cnt, 0, sizeof(cnt)); for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) cnt[i + j]++; } void solve() { int ans = 0; for (int ab = 0; ab <= n; ab++) { ans += cnt[ab] * cnt[n - ab]; } cout << ans << endl; } int main() { setcnt(); while (cin >> n) { solve(); } return 0; }
#include <cstring> #include <iostream> using namespace std; int n; int cnt[4040]; void setcnt() { memset(cnt, 0, sizeof(cnt)); for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) cnt[i + j]++; } void solve() { int ans = 0; for (int ab = 0; ab <= n; ab++) { ans += cnt[ab] * cnt[n - ab]; } cout << ans << endl; } int main() { setcnt(); while (cin >> n) { solve(); } return 0; }
replace
6
7
6
7
0
p00096
C++
Runtime Error
#include <iostream> using namespace std; int sum[2001]; int main() { for (int i = 0; i < 1001; ++i) { for (int j = 0; j < 1001; ++j) { sum[i + j]++; } } int n; while (cin >> n) { int ans = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; i + j <= n; ++j) { ans += sum[n - i - j]; } } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int sum[2001]; int main() { for (int i = 0; i < 1001; ++i) { for (int j = 0; j < 1001; ++j) { sum[i + j]++; } } int n; while (cin >> n) { long long ans = 0; for (int i = 0; i <= 1000; ++i) { for (int j = 0; j <= 1000; ++j) { if (n - i - j > 2001) continue; if (n - i - j < 0) break; ans += sum[n - i - j]; } } cout << ans << endl; } return 0; }
replace
11
14
11
18
0
p00096
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define lengthof(array) (sizeof(array) / sizeof(*array)) #define dump(a) (cerr << (#a) << " = " << (a) << endl) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define RFOR(it, c) \ for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) template <class T> inline void chmax(T &a, const T &b) { if (b > a) a = b; } template <class T> inline void chmin(T &a, const T &b) { if (b < a) a = b; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { copy(v.begin(), v.end(), ostream_iterator<T>(os, " ")); return os; } int main() { cin.tie(0); ios::sync_with_stdio(false); vector<long long> cnt(2001, 0); for (int i = 0; i <= 1000; ++i) for (int j = 0; j <= 1000; ++j) ++cnt[i + j]; for (int n; cin >> n;) { long long ans = 0; for (int i = max(0, n - 2000); i <= n; ++i) ans += cnt[i] * cnt[n - i]; cout << ans << endl; } return EXIT_SUCCESS; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define lengthof(array) (sizeof(array) / sizeof(*array)) #define dump(a) (cerr << (#a) << " = " << (a) << endl) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define RFOR(it, c) \ for (__typeof((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) template <class T> inline void chmax(T &a, const T &b) { if (b > a) a = b; } template <class T> inline void chmin(T &a, const T &b) { if (b < a) a = b; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { copy(v.begin(), v.end(), ostream_iterator<T>(os, " ")); return os; } int main() { cin.tie(0); ios::sync_with_stdio(false); vector<long long> cnt(2001, 0); for (int i = 0; i <= 1000; ++i) for (int j = 0; j <= 1000; ++j) ++cnt[i + j]; for (int n; cin >> n;) { long long ans = 0; const int start = max(0, n - 2000), end = min(2000, n); for (int i = start; i <= end; ++i) ans += cnt[i] * cnt[n - i]; cout << ans << endl; } return EXIT_SUCCESS; }
replace
65
66
65
67
0
p00096
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int ab[2050]; int main(void) { int n; for (int a = 0; a <= 1000; a++) { for (int b = 0; b <= 1000; b++) { ab[a + b]++; } } while (cin >> n) { if (cin.eof()) break; int ret = 0; for (int cd = 0; cd <= 2000; cd++) { if (n - cd >= 0) { ret += ab[cd] * ab[n - cd]; } } cout << ret << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int ab[2050]; int main(void) { int n; for (int a = 0; a <= 1000; a++) { for (int b = 0; b <= 1000; b++) { ab[a + b]++; } } while (cin >> n) { if (cin.eof()) break; int ret = 0; for (int cd = 0; cd <= 2000; cd++) { if (n - cd >= 0 && n - cd <= 2000) { ret += ab[cd] * ab[n - cd]; } } cout << ret << endl; } return 0; }
replace
24
25
24
25
0
p00096
C++
Time Limit Exceeded
#include <cmath> #include <iostream> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) using namespace std; int main() { int n; while (cin >> n) { long long cnt = 0; for (int i = max(0, n - 3000); i <= min(1000, n); i++) { for (int j = max(0, n - i - 2000); j <= min(1000, n); j++) { for (int k = max(0, n - i - j - 1000); k <= min(1000, n); k++) { if ((n - (i + j + k)) >= 0 && (n - (i + j + k)) <= 1000) cnt++; } } } cout << cnt << endl; } return 0; }
#include <cmath> #include <iostream> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) using namespace std; int main() { int n; while (cin >> n) { long long cnt = 0; for (int i = max(0, n - 3000); i <= min(1000, n); i++) { for (int j = max(0, n - i - 2000); j <= min(1000, n - i); j++) { cnt += (min(1000, n - i - j) - max(0, n - i - j - 1000) + 1); } } cout << cnt << endl; } return 0; }
replace
11
16
11
13
TLE
p00096
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int AB[2001] = {0}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { AB[i + j]++; } } while (cin >> n) { int ans = 0; for (int i = 0; i <= 2000; i++) { if (n - i >= 0) ans += AB[i] * AB[n - i]; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int AB[2001] = {0}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { AB[i + j]++; } } while (cin >> n) { int ans = 0; for (int i = 0; i <= 2000; i++) { if (n - i > 2000) continue; if (n - i >= 0) ans += AB[i] * AB[n - i]; } cout << ans << endl; } return 0; }
insert
16
16
16
18
0
p00096
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a[2001] = {}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { a[i + j]++; } } int n; while (cin >> n) { long long int all = 0; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000 && j <= n - i; j++) { all += a[n - i - j]; } } cout << all << endl; } return 0; }
#include <iostream> using namespace std; int main() { int a[4001] = {}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { a[i + j]++; } } int n; while (cin >> n) { long long int all = 0; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000 && j <= n - i; j++) { all += a[n - i - j]; } } cout << all << endl; } return 0; }
replace
3
4
3
4
0
p00096
C++
Runtime Error
#include <iostream> using namespace std; int t[2001]; int n, sum; int main() { for (int i = 0; i < 2001; i++) { if (i < 1001) t[i] = i + 1; else t[i] = 2001 - i; } while (cin >> n) { sum = 0; for (int i = 0; i < 2001; i++) { if (n - i >= 0) sum += t[i] * t[n - i]; } cout << sum << endl; } return 0; }
#include <iostream> using namespace std; int t[2001]; int n, sum; int main() { for (int i = 0; i < 2001; i++) { if (i < 1001) t[i] = i + 1; else t[i] = 2001 - i; } while (cin >> n) { sum = 0; for (int i = 0; i < 2001; i++) { if (n - i >= 0 && n - i <= 2000) { sum = sum + t[i] * t[n - i]; } } cout << sum << endl; } return 0; }
replace
14
16
14
17
0
p00096
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int n; int a_add_b[2001] = {0}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { a_add_b[i + j]++; } } while (scanf("%d", &n) != EOF) { long long int ans = 0; for (int i = 0; i <= n; i++) { ans += a_add_b[i] * a_add_b[n - i]; } std::cout << ans << std::endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int n; int a_add_b[2001] = {0}; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { a_add_b[i + j]++; } } while (scanf("%d", &n) != EOF) { long long int ans = 0; for (int i = 0; i <= 2000; i++) { if (0 <= n - i && n - i <= 2000) ans += a_add_b[i] * a_add_b[n - i]; } std::cout << ans << std::endl; } return 0; }
replace
16
18
16
19
0
p00097
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; using lint = long long; lint n, s; lint dp[1001][101][101]; lint dfs(int sum = 0, int num = 0, int cnt = 0) { if (cnt == n) return sum == s; if (num > 100 || sum > s) return 0; lint &ret = dp[sum][num][cnt]; if (~ret) return ret; ret = dfs(sum, num + 1, cnt) + dfs(sum + num, num + 1, cnt + 1); return ret; } int main() { while (cin >> n >> s, n + s) { memset(dp, -1, sizeof(dp)); cout << dfs() << endl; } }
#include <bits/stdc++.h> using namespace std; using lint = long long; lint n, s; lint dp[1001][101][11]; lint dfs(int sum = 0, int num = 0, int cnt = 0) { if (cnt == n) return sum == s; if (num > 100 || sum > s) return 0; lint &ret = dp[sum][num][cnt]; if (~ret) return ret; ret = dfs(sum, num + 1, cnt) + dfs(sum + num, num + 1, cnt + 1); return ret; } int main() { while (cin >> n >> s, n + s) { memset(dp, -1, sizeof(dp)); cout << dfs() << endl; } }
replace
6
7
6
7
MLE
p00097
C++
Runtime Error
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; // const int INF = 1e8; using namespace std; int main() { int n, s; while (cin >> n >> s, n) { long long dp[10][1005] = {{0}}; dp[0][0] = 1; rep(j, 101) { for (int i = n; i >= 0; i--) { for (int k = s; k >= 0; k--) { dp[i + 1][k + j] += dp[i][k]; } } } cout << dp[n][s] << endl; } }
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) for (int i = 0; i < (b); i++) #define all(a) (a).begin(), (a).end() #define show(x) cerr << #x << " = " << (x) << endl; // const int INF = 1e8; using namespace std; int main() { int n, s; while (cin >> n >> s, n) { long long dp[10][2005] = {{0}}; dp[0][0] = 1; rep(j, 101) { for (int i = n; i >= 0; i--) { for (int k = s; k >= 0; k--) { dp[i + 1][k + j] += dp[i][k]; } } } cout << dp[n][s] << endl; } }
replace
11
12
11
12
0
p00097
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { long long n, s, dp[102][11][1001]; for (int i = 0; i < 101; i++) for (int j = 0; j < 10; j++) for (int k = 0; k < 1001; k++) dp[i][j][k] = 0; dp[0][0][0] = 1; for (int i = 0; i < 101; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 1001; k++) { if (dp[i][j][k] == 0) continue; dp[i + 1][j][k] += dp[i][j][k]; if (8 < j || 1000 < k + i) continue; dp[i + 1][j + 1][k + i] += dp[i][j][k]; } } } while (cin >> n >> s, n | s) cout << dp[101][n][s] << endl; return 0; }
#include <iostream> using namespace std; int main(void) { static long long n, s, dp[102][11][1001]; for (int i = 0; i < 101; i++) for (int j = 0; j < 10; j++) for (int k = 0; k < 1001; k++) dp[i][j][k] = 0; dp[0][0][0] = 1; for (int i = 0; i < 101; i++) { for (int j = 0; j < 10; j++) { for (int k = 0; k < 1001; k++) { if (dp[i][j][k] == 0) continue; dp[i + 1][j][k] += dp[i][j][k]; if (8 < j || 1000 < k + i) continue; dp[i + 1][j + 1][k + i] += dp[i][j][k]; } } } while (cin >> n >> s, n | s) cout << dp[101][n][s] << endl; return 0; }
replace
5
6
5
6
-11
p00097
C++
Runtime Error
#include <iostream> #include <string> using namespace std; long long int a[101][11][1100]; int main() { int n, s; a[0][0][0] = 1; a[0][1][0] = 1; for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k <= 1000; k++) { a[i + 1][j][k] += a[i][j][k]; a[i + 1][j + 1][k + i + 1] += a[i][j][k]; } } } while (1) { cin >> n >> s; if (n == 0 && s == 0) break; cout << a[100][n][s] << endl; } return 0; }
#include <iostream> #include <string> using namespace std; long long int a[102][11][1100]; int main() { int n, s; a[0][0][0] = 1; a[0][1][0] = 1; for (int i = 0; i <= 100; i++) { for (int j = 0; j <= 9; j++) { for (int k = 0; k <= 1000; k++) { a[i + 1][j][k] += a[i][j][k]; a[i + 1][j + 1][k + i + 1] += a[i][j][k]; } } } while (1) { cin >> n >> s; if (n == 0 && s == 0) break; cout << a[100][n][s] << endl; } return 0; }
replace
3
4
3
4
-11
p00098
C++
Runtime Error
#include <iostream> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, a[100][100], rs[100][100], sum[100][100]; cin >> n; rep(i, n) rep(j, n) cin >> a[i][j]; rep(i, n) rs[0][i] = 0; rep(i, n) { rs[i + 1][0] = 0; rep(j, n) { rs[i + 1][j + 1] = rs[i + 1][j] + a[i][j]; } } rep(i, n + 1) { sum[0][i] = 0; rep(j, n) { sum[j + 1][i] = sum[j][i] + rs[j + 1][i]; } } int ans = -1000000000; rep(i, n) rep(j, n) rep(k, n + 1) rep(l, n + 1) { if (i < k && j < l) { ans = std::max(ans, sum[k][l] - sum[k][j] - sum[i][l] + sum[i][j]); } } cout << ans << endl; }
#include <iostream> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n, a[110][110], rs[110][110], sum[110][110]; cin >> n; rep(i, n) rep(j, n) cin >> a[i][j]; rep(i, n) rs[0][i] = 0; rep(i, n) { rs[i + 1][0] = 0; rep(j, n) { rs[i + 1][j + 1] = rs[i + 1][j] + a[i][j]; } } rep(i, n + 1) { sum[0][i] = 0; rep(j, n) { sum[j + 1][i] = sum[j][i] + rs[j + 1][i]; } } int ans = -1000000000; rep(i, n) rep(j, n) rep(k, n + 1) rep(l, n + 1) { if (i < k && j < l) { ans = std::max(ans, sum[k][l] - sum[k][j] - sum[i][l] + sum[i][j]); } } cout << ans << endl; }
replace
5
6
5
6
0
p00098
C++
Time Limit Exceeded
#include <iostream> #define rep(i, N) for (i = 1; i <= N; i++) using namespace std; int n; int data[102][102]; int rui[102][102]; // rui[i][j] = (1,1)を左上とするi*j行列の要素和 int main() { int i, j, k, l; cin >> n; rep(i, n) { rep(j, n) { cin >> data[i][j]; } } // 左→右 rep(i, n) { rep(j, n) { rui[i][j] = rui[i][j - 1] + data[i][j]; } } // 上→下 rep(j, n) { rep(i, n) { rui[i][j] = rui[i - 1][j] + rui[i][j]; } } int ans = -1145141919; rep(i, n) { rep(j, n) { for (k = i; k < n; k++) { for (l = j; k < n; l++) { // 左上(i,j), 右下(k,l)とする行列の要素和を求める int mats = rui[k][l] - rui[k][j - 1] - rui[i - 1][l] + rui[i - 1][j - 1]; ans = max(ans, mats); } } } } cout << ans << endl; return 0; } /*Σ(k=a, k=b)A[k]を知りたい! 愚直に計算O(b-a) 先に Σ(k=1, k=n)A[k] = rui[n]としておく. すると、 Σ(k=a, k=b)A[k] = rui[b] - rui[a]; で計算できる。 O(1) */
#include <iostream> #define rep(i, N) for (i = 1; i <= N; i++) using namespace std; int n; int data[102][102]; int rui[102][102]; // rui[i][j] = (1,1)を左上とするi*j行列の要素和 int main() { int i, j, k, l; cin >> n; rep(i, n) { rep(j, n) { cin >> data[i][j]; } } // 左→右 rep(i, n) { rep(j, n) { rui[i][j] = rui[i][j - 1] + data[i][j]; } } // 上→下 rep(j, n) { rep(i, n) { rui[i][j] = rui[i - 1][j] + rui[i][j]; } } int ans = -1145141919; rep(i, n) { rep(j, n) { for (k = i; k <= n; k++) { for (l = j; l <= n; l++) { // 左上(i,j), 右下(k,l)とする行列の要素和を求める int mats = rui[k][l] - rui[k][j - 1] - rui[i - 1][l] + rui[i - 1][j - 1]; ans = max(ans, mats); } } } } cout << ans << endl; return 0; } /*Σ(k=a, k=b)A[k]を知りたい! 愚直に計算O(b-a) 先に Σ(k=1, k=n)A[k] = rui[n]としておく. すると、 Σ(k=a, k=b)A[k] = rui[b] - rui[a]; で計算できる。 O(1) */
replace
27
29
27
29
TLE
p00099
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define foreach(it, c) \ for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define rforeach(it, c) \ for (__typeof__((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define CL(arr, val) memset(arr, val, sizeof(arr)) #define COPY(dest, src) memcpy(dest, src, sizeof(dest)) #define ten(n) ((long long)(1e##n)) #define bin(n) (1LL << (n)) #define erep(i, n) for (int i = 0; i <= (int)(n); ++i) #define revrep(i, n) for (int i = (n); i >= 0; --i) #define pb push_back template <class T> void chmax(T &a, const T &b) { a = max(a, b); } template <class T> void chmin(T &a, const T &b) { a = min(a, b); } template <class T> void uniq(T &c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); } template <class T> string to_s(const T &a) { ostringstream os; os << a; return os.str(); } template <class T> T to_T(const string &s) { istringstream is(s); T res; is >> res; return res; } template <typename T> void print_container(ostream &os, const T &c) { const char *_s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) cout << _s; } } } template <typename T> ostream &operator<<(ostream &os, const vector<T> &c) { print_container(os, c); return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &c) { print_container(os, c); return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &c) { print_container(os, c); return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &c) { print_container(os, c); return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &c) { print_container(os, c); return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "( " << p.first << ", " << p.second << " )"; return os; } template <class T> void print(T a, int n, const string &deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; } template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; } template <class T> void input(T &a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } template <class T> void input(T *a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); } void fast_io() { cin.tie(0); ios::sync_with_stdio(false); } #define trace(x) (cout << #x << ": " << (x) << endl) bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; } typedef long long ll; typedef pair<int, int> pint; // y(v): v>^< y(^): ^>v< const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const double PI = acos(-1.0); #define mp make_pair int main() { fast_io(); int n, Q; cin >> n >> Q; map<int, int> fish; priority_queue<pint> q; while (Q--) { int a, v; cin >> a >> v; fish[a] += v; q.push(pint(v, -a)); while (q.top().first != fish[-q.top().second]) q.pop(); cout << -q.top().second << " " << q.top().first << endl; } }
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define foreach(it, c) \ for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define rforeach(it, c) \ for (__typeof__((c).rbegin()) it = (c).rbegin(); it != (c).rend(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define CL(arr, val) memset(arr, val, sizeof(arr)) #define COPY(dest, src) memcpy(dest, src, sizeof(dest)) #define ten(n) ((long long)(1e##n)) #define bin(n) (1LL << (n)) #define erep(i, n) for (int i = 0; i <= (int)(n); ++i) #define revrep(i, n) for (int i = (n); i >= 0; --i) #define pb push_back template <class T> void chmax(T &a, const T &b) { a = max(a, b); } template <class T> void chmin(T &a, const T &b) { a = min(a, b); } template <class T> void uniq(T &c) { sort(c.begin(), c.end()); c.erase(unique(c.begin(), c.end()), c.end()); } template <class T> string to_s(const T &a) { ostringstream os; os << a; return os.str(); } template <class T> T to_T(const string &s) { istringstream is(s); T res; is >> res; return res; } template <typename T> void print_container(ostream &os, const T &c) { const char *_s = " "; if (!c.empty()) { __typeof__(c.begin()) last = --c.end(); foreach (it, c) { os << *it; if (it != last) cout << _s; } } } template <typename T> ostream &operator<<(ostream &os, const vector<T> &c) { print_container(os, c); return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &c) { print_container(os, c); return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &c) { print_container(os, c); return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &c) { print_container(os, c); return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &c) { print_container(os, c); return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "( " << p.first << ", " << p.second << " )"; return os; } template <class T> void print(T a, int n, const string &deli = " ", int br = 1) { for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } while (br--) cout << endl; } template <class T> void print2d(T a, int w, int h, int width = -1, int br = 1) { for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (width != -1) cout.width(width); cout << a[i][j] << ' '; } cout << endl; } while (br--) cout << endl; } template <class T> void input(T &a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } template <class T> void input(T *a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } void fix_pre(int n) { cout.setf(ios::fixed, ios::floatfield); cout.precision(10); } void fast_io() { cin.tie(0); ios::sync_with_stdio(false); } #define trace(x) (cout << #x << ": " << (x) << endl) bool in_rect(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; } typedef long long ll; typedef pair<int, int> pint; // y(v): v>^< y(^): ^>v< const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; const double PI = acos(-1.0); #define mp make_pair int main() { fast_io(); int n, Q; cin >> n >> Q; map<int, int> fish; priority_queue<pint> q; while (Q--) { int a, v; cin >> a >> v; fish[a] += v; q.push(pint(fish[a], -a)); while (q.top().first != fish[-q.top().second]) q.pop(); cout << -q.top().second << " " << q.top().first << endl; } }
replace
170
171
170
171
0
p00099
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i, a, b) for (int i = (a); i < (b); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; // segment-tree ll n; // nは2のべき乗 pii dat[1000110 * 2 - 1]; // 初期化 void init(ll _n) { // べき乗を計算しておく n = 1; while (n < _n) n *= 2; // すべての値をINT_MAXに for (ll i = 0; i < 2 * n - 1; i++) { dat[i].first = -INF; } } // i番目の値(0-indexed)をxに変更 void update(ll i, ll x, ll c) { // 葉のノード番号 i += n - 1; dat[i].first = x; dat[i].second = -c; while (i > 0) { i = (i - 1) / 2; if (dat[i * 2 + 1] > dat[i * 2 + 2]) { dat[i] = dat[i * 2 + 1]; } else { dat[i] = dat[i * 2 + 2]; } } } //[a,b)の最小値,l,rにはノードkに対応づく区画を与える // 外からはquery(a,b,0,0,n)のように呼ぶ /*int query(int a,int b,int k,int l,int r){ if(r <=a||b <=l)//交差しない return INT_MAX; if(a <=l&&r<=b)//完全に含む return dat[k].first; else{ int vl =query(a, b, k*2+1, l, (l+r)/2); int vr =query(a, b, k*2+2, (l+r)/2, r); return min(vl,vr); } }*/ int main() { int q; cin >> n >> q; init(n); for (int i = 0; i < q; i++) { ll x, y; cin >> x >> y; x--; ll tmp = x + n - 1; if (dat[tmp].first != -INF) { update(x, dat[tmp].first + y, x); } else { update(x, y, x); } cout << -1 * dat[0].second + 1 << " " << dat[0].first << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i, a, b) for (int i = (a); i < (b); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; // segment-tree ll n; // nは2のべき乗 pii dat[2000110 * 2 - 1]; // 初期化 void init(ll _n) { // べき乗を計算しておく n = 1; while (n < _n) n *= 2; // すべての値をINT_MAXに for (ll i = 0; i < 2 * n - 1; i++) { dat[i].first = -INF; } } // i番目の値(0-indexed)をxに変更 void update(ll i, ll x, ll c) { // 葉のノード番号 i += n - 1; dat[i].first = x; dat[i].second = -c; while (i > 0) { i = (i - 1) / 2; if (dat[i * 2 + 1] > dat[i * 2 + 2]) { dat[i] = dat[i * 2 + 1]; } else { dat[i] = dat[i * 2 + 2]; } } } //[a,b)の最小値,l,rにはノードkに対応づく区画を与える // 外からはquery(a,b,0,0,n)のように呼ぶ /*int query(int a,int b,int k,int l,int r){ if(r <=a||b <=l)//交差しない return INT_MAX; if(a <=l&&r<=b)//完全に含む return dat[k].first; else{ int vl =query(a, b, k*2+1, l, (l+r)/2); int vr =query(a, b, k*2+2, (l+r)/2, r); return min(vl,vr); } }*/ int main() { int q; cin >> n >> q; init(n); for (int i = 0; i < q; i++) { ll x, y; cin >> x >> y; x--; ll tmp = x + n - 1; if (dat[tmp].first != -INF) { update(x, dat[tmp].first + y, x); } else { update(x, y, x); } cout << -1 * dat[0].second + 1 << " " << dat[0].first << endl; } return 0; }
replace
40
41
40
41
0
p00099
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; struct DATA { int player, wakasagi; }; int n, q, a, v, top_player, cnt = 0; int wakasagi_sum[1000001]; DATA data[1000001]; void heep_in(int); int heep_out(void); int main() { cin >> n >> q; for (int i = 0; i < 1000001; i++) { data[i].wakasagi = -1; data[i].player = 1e9; wakasagi_sum[i] = 0; } for (int i = 0; i < q; i++) { cin >> a >> v; wakasagi_sum[a] += v; heep_in(a); top_player = heep_out(); cout << top_player << " " << wakasagi_sum[top_player] << endl; } return 0; } void heep_in(int a) { int number; number = ++cnt; data[cnt].player = a; data[cnt].wakasagi = wakasagi_sum[a]; while (1) { if (number == 1) break; if (data[number].wakasagi > data[number / 2].wakasagi) { swap(data[number].wakasagi, data[number / 2].wakasagi); swap(data[number].player, data[number / 2].player); } else if (data[number].wakasagi == data[number / 2].wakasagi && data[number].player < data[number / 2].player) { swap(data[number].player, data[number / 2].player); } else { break; } number /= 2; } } int heep_out(void) { int number, i; number = cnt; if (data[1].wakasagi == wakasagi_sum[data[1].player]) { return data[1].player; } else { data[1].wakasagi = data[cnt].wakasagi; data[1].player = data[cnt].player; i = 1; while (1) { if (data[i * 2].wakasagi > data[i * 2 + 1].wakasagi || (data[i * 2].wakasagi == data[i * 2 + 1].wakasagi && data[i * 2].player <= data[i * 2 + 1].player)) { if (data[i * 2].wakasagi > data[i].wakasagi) { swap(data[i].wakasagi, data[i * 2].wakasagi); swap(data[i].player, data[i * 2].player); i = i * 2; } else if (data[i * 2].wakasagi == data[i].wakasagi && data[i * 2].player <= data[i].player) { swap(data[i].player, data[i * 2].player); i = i * 2; } } else if (data[i * 2].wakasagi < data[i * 2 + 1].wakasagi || (data[i * 2].wakasagi == data[i * 2 + 1].wakasagi && data[i * 2].player > data[i * 2 + 1].player)) { if (data[i * 2 + 1].wakasagi > data[i].wakasagi) { swap(data[i].wakasagi, data[i * 2 + 1].wakasagi); swap(data[i].player, data[i * 2 + 1].player); i = i * 2 + 1; } else if (data[i * 2 + 1].wakasagi == data[i].wakasagi && data[i * 2 + 1].player <= data[i].player) { swap(data[i].player, data[i * 2 + 1].player); i = i * 2 + 1; } else break; } else { break; } if (i * 2 > cnt) break; } cnt--; } return heep_out(); }
#include <algorithm> #include <iostream> using namespace std; struct DATA { int player, wakasagi; }; int n, q, a, v, top_player, cnt = 0; int wakasagi_sum[1000001]; DATA data[1000001]; void heep_in(int); int heep_out(void); int main() { cin >> n >> q; for (int i = 0; i < 1000001; i++) { data[i].wakasagi = -1; data[i].player = 1e9; wakasagi_sum[i] = 0; } for (int i = 0; i < q; i++) { cin >> a >> v; wakasagi_sum[a] += v; heep_in(a); top_player = heep_out(); cout << top_player << " " << wakasagi_sum[top_player] << endl; } return 0; } void heep_in(int a) { int number; number = ++cnt; data[cnt].player = a; data[cnt].wakasagi = wakasagi_sum[a]; while (1) { if (number == 1) break; if (data[number].wakasagi > data[number / 2].wakasagi) { swap(data[number].wakasagi, data[number / 2].wakasagi); swap(data[number].player, data[number / 2].player); } else if (data[number].wakasagi == data[number / 2].wakasagi && data[number].player < data[number / 2].player) { swap(data[number].player, data[number / 2].player); } else { break; } number /= 2; } } int heep_out(void) { int number, i; number = cnt; if (data[1].wakasagi == wakasagi_sum[data[1].player]) { return data[1].player; } else { data[1].wakasagi = data[cnt].wakasagi; data[1].player = data[cnt].player; i = 1; while (1) { if (data[i * 2].wakasagi > data[i * 2 + 1].wakasagi || (data[i * 2].wakasagi == data[i * 2 + 1].wakasagi && data[i * 2].player <= data[i * 2 + 1].player)) { if (data[i * 2].wakasagi > data[i].wakasagi) { swap(data[i].wakasagi, data[i * 2].wakasagi); swap(data[i].player, data[i * 2].player); i = i * 2; } else if (data[i * 2].wakasagi == data[i].wakasagi && data[i * 2].player <= data[i].player) { swap(data[i].player, data[i * 2].player); i = i * 2; } else break; } else if (data[i * 2].wakasagi < data[i * 2 + 1].wakasagi || (data[i * 2].wakasagi == data[i * 2 + 1].wakasagi && data[i * 2].player > data[i * 2 + 1].player)) { if (data[i * 2 + 1].wakasagi > data[i].wakasagi) { swap(data[i].wakasagi, data[i * 2 + 1].wakasagi); swap(data[i].player, data[i * 2 + 1].player); i = i * 2 + 1; } else if (data[i * 2 + 1].wakasagi == data[i].wakasagi && data[i * 2 + 1].player <= data[i].player) { swap(data[i].player, data[i * 2 + 1].player); i = i * 2 + 1; } else break; } else { break; } if (i * 2 > cnt) break; } cnt--; } return heep_out(); }
replace
93
94
93
95
TLE
p00099
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define INF -(1 << 29) #define F first #define S second #define T P using namespace std; typedef pair<int, int> P; const int MAX_N = 1000010; bool cmp(const P &a, const P &b) { if (a.first == b.first) return a.second > b.second; return a.first < b.first; } int n; T dat[2 * MAX_N - 1]; void init(int n_) { n = 1; while (n < n_) n *= 2; for (int i = 0; i < 2 * n - 1; i++) dat[i] = P(INF, INF); } // k番めの値(0-indexed)をaに変更 void update(int k, T a) { k += n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2], cmp); } } // [a,b)の最大値を求める T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return P(INF, INF); else if (a <= l && r <= b) return dat[k]; T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr, cmp); } // nの範囲でミスしないように極力こっちを利用 T _query(int a, int b) { return query(a, b, 0, 0, n); } int main() { int n, q; cin >> n >> q; init(n); P total[n + 1]; for (int i = 0; i <= n; i++) total[i] = P(INF, INF); vector<P> vec; for (int i = 0; i < q; i++) { int a, v; cin >> a >> v; if (total[a] == P(INF, INF)) { vec.push_back(P(a, v)); int index = vec.size() - 1; total[a] = P(v, index); update(index, P(v, a)); } else { total[a].first += v; update(total[a].second, P(total[a].first, a)); } P p = _query(0, vec.size()); cout << p.second << " " << p.first << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> #define INF -(1 << 29) #define F first #define S second #define T P using namespace std; typedef pair<int, int> P; const int MAX_N = 1000010; bool cmp(const P &a, const P &b) { if (a.first == b.first) return a.second > b.second; return a.first < b.first; } int n; T dat[3 * MAX_N - 1]; void init(int n_) { n = 1; while (n < n_) n *= 2; for (int i = 0; i < 2 * n - 1; i++) dat[i] = P(INF, INF); } // k番めの値(0-indexed)をaに変更 void update(int k, T a) { k += n - 1; dat[k] = a; while (k > 0) { k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2], cmp); } } // [a,b)の最大値を求める T query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return P(INF, INF); else if (a <= l && r <= b) return dat[k]; T vl = query(a, b, k * 2 + 1, l, (l + r) / 2); T vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr, cmp); } // nの範囲でミスしないように極力こっちを利用 T _query(int a, int b) { return query(a, b, 0, 0, n); } int main() { int n, q; cin >> n >> q; init(n); P total[n + 1]; for (int i = 0; i <= n; i++) total[i] = P(INF, INF); vector<P> vec; for (int i = 0; i < q; i++) { int a, v; cin >> a >> v; if (total[a] == P(INF, INF)) { vec.push_back(P(a, v)); int index = vec.size() - 1; total[a] = P(v, index); update(index, P(v, a)); } else { total[a].first += v; update(total[a].second, P(total[a].first, a)); } P p = _query(0, vec.size()); cout << p.second << " " << p.first << endl; } return 0; }
replace
18
19
18
19
0
p00099
C++
Runtime Error
#include <cstdio> #include <set> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { int n, q; scanf("%d%d", &n, &q); static int num[100001]; multiset<pair<int, int>> S; S.insert(make_pair(0, 0)); rep(_, q) { int a, v; scanf("%d%d", &a, &v); if (num[a] > 0) S.erase(S.find(make_pair(-num[a], a))); num[a] += v; if (num[a] > 0) S.insert(make_pair(-num[a], a)); printf("%d %d\n", S.begin()->second, -S.begin()->first); } return 0; }
#include <cstdio> #include <set> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { int n, q; scanf("%d%d", &n, &q); static int num[1000001]; set<pair<int, int>> S; S.insert(make_pair(0, 1)); rep(_, q) { int a, v; scanf("%d%d", &a, &v); if (num[a] > 0) S.erase(S.find(make_pair(-num[a], a))); num[a] += v; if (num[a] > 0) S.insert(make_pair(-num[a], a)); printf("%d %d\n", S.begin()->second, -S.begin()->first); } return 0; }
replace
10
13
10
13
0
p00099
C++
Memory Limit Exceeded
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repb(i, a, b) for (int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define fi first #define se second using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; int d[1000001]; set<pii> st; signed main() { int n, q; cin >> n >> q; rep(i, 0, n) { st.insert(make_pair(0, i)); } rep(i, 0, q) { int a, v; cin >> a >> v; a--; st.erase(st.find(make_pair(d[a], a))); d[a] -= v; st.insert(make_pair(d[a], a)); set<pii>::iterator it = st.begin(); cout << it->se + 1 << " " << -it->fi << endl; } }
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repb(i, a, b) for (int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl // #define int long long #define fi first #define se second using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; int d[1000001]; set<pii> st; signed main() { int n, q; cin >> n >> q; rep(i, 0, n) { st.insert(make_pair(0, i)); } rep(i, 0, q) { int a, v; cin >> a >> v; a--; st.erase(st.find(make_pair(d[a], a))); d[a] -= v; st.insert(make_pair(d[a], a)); set<pii>::iterator it = st.begin(); cout << it->se + 1 << " " << -it->fi << endl; } }
replace
5
6
5
6
MLE
p00099
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 INT_MAX / 3 #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CLR(a) memset(a, 0, sizeof(a)) #define MAX(a, b) a > b ? a : b typedef long long int ll; using namespace std; pair<int, int> tree[2000001]; int n, q; pair<int, int> pmax(pair<int, int> a, pair<int, int> b) { pair<int, int> ret = MAX(a, b); if (a.first == b.first) { ret.second = min(a.second, b.second); } return ret; } void init(int k, int l, int r) { if (r - l == 1) tree[k] = tree[l]; else { int chl = 2 * k + 1, chr = 2 * k + 2; int m = (int)((l + r) / 2); init(chl, l, m); init(chr, m, r); tree[k] = pmax(tree[chl], tree[chr]); } } void update(int k, int a) { k += n; tree[k].first += a; while (k > 0) { k = (k - 1) / 2; tree[k] = pmax(tree[2 * k + 1], tree[2 * k + 2]); } } int main() { // pair<int,int> ma(-100000000,-1); cin >> n >> q; REP(i, 2 * n) tree[n + i] = pair<int, int>(0, 0); REP(i, n) { tree[n + i].second = i + 1; } vector<pair<int, int>> ar(n); vector<bool> u(q, false); REP(i, q) { int a, v; cin >> a >> v; update(a - 1, v); cout << tree[0].second << " " << tree[0].first << 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 INT_MAX / 3 #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CLR(a) memset(a, 0, sizeof(a)) #define MAX(a, b) a > b ? a : b typedef long long int ll; using namespace std; pair<int, int> tree[3000001]; int n, q; pair<int, int> pmax(pair<int, int> a, pair<int, int> b) { pair<int, int> ret = MAX(a, b); if (a.first == b.first) { ret.second = min(a.second, b.second); } return ret; } void init(int k, int l, int r) { if (r - l == 1) tree[k] = tree[l]; else { int chl = 2 * k + 1, chr = 2 * k + 2; int m = (int)((l + r) / 2); init(chl, l, m); init(chr, m, r); tree[k] = pmax(tree[chl], tree[chr]); } } void update(int k, int a) { k += n; tree[k].first += a; while (k > 0) { k = (k - 1) / 2; tree[k] = pmax(tree[2 * k + 1], tree[2 * k + 2]); } } int main() { // pair<int,int> ma(-100000000,-1); cin >> n >> q; REP(i, 2 * n) tree[n + i] = pair<int, int>(0, 0); REP(i, n) { tree[n + i].second = i + 1; } vector<pair<int, int>> ar(n); vector<bool> u(q, false); REP(i, q) { int a, v; cin >> a >> v; update(a - 1, v); cout << tree[0].second << " " << tree[0].first << endl; } return 0; }
replace
16
17
16
17
0
p00099
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i, j) for (int i = 0; i < (int)(j); ++i) #define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define REVERSE(v) reverse((v).begin(), (v).end()) typedef pair<int, int> P; const int MAX_N = 1000010; int N, Q; P v[2 * MAX_N - 1]; void init(int _n) { N = 1; while (N < _n) N *= 2; REP(i, 2 * N - 1) v[i] = P(0, 0); REP(i, _n) v[i + N - 1].second = i * -1; } void update(int k, int a) { k += N - 1; v[k].first += a; while (k > 0) { k = (k - 1) / 2; v[k] = max(v[k * 2 + 1], v[k * 2 + 2]); } } int main() { cin >> N >> Q; init(N); REP(i, Q) { int a, b; cin >> a >> b; update(a - 1, b); cout << v[0].second * -1 + 1 << " " << v[0].first << endl; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define REP(i, j) for (int i = 0; i < (int)(j); ++i) #define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define REVERSE(v) reverse((v).begin(), (v).end()) typedef pair<int, int> P; const int MAX_N = 2000010; int N, Q; P v[2 * MAX_N - 1]; void init(int _n) { N = 1; while (N < _n) N *= 2; REP(i, 2 * N - 1) v[i] = P(0, 0); REP(i, _n) v[i + N - 1].second = i * -1; } void update(int k, int a) { k += N - 1; v[k].first += a; while (k > 0) { k = (k - 1) / 2; v[k] = max(v[k * 2 + 1], v[k * 2 + 2]); } } int main() { cin >> N >> Q; init(N); REP(i, Q) { int a, b; cin >> a >> b; update(a - 1, b); cout << v[0].second * -1 + 1 << " " << v[0].first << endl; } return 0; }
replace
25
26
25
26
0
p00099
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct P { int a, v; bool operator<(const P &t) const { if (v == t.v) return a > t.a; return v < t.v; } }; int n; P dat[2000000]; void update(int i, int x) { i += n - 1; dat[i].v += x; while (i > 0) { i = (i - 1) / 2; dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]); } } int main() { int q; scanf("%d %d", &n, &q); for (int i = 1;; i *= 2) { if (n <= i) { n = i; break; } } for (int i = 0; i < n; i++) { dat[i + n - 1].a = i; } for (int i = 0; i < q; i++) { int a, v; scanf("%d %d", &a, &v); a--; update(a, v); printf("%d %d\n", dat[0].a + 1, dat[0].v); } return 0; }
#include <bits/stdc++.h> using namespace std; struct P { int a, v; bool operator<(const P &t) const { if (v == t.v) return a > t.a; return v < t.v; } }; int n; P dat[10000000]; void update(int i, int x) { i += n - 1; dat[i].v += x; while (i > 0) { i = (i - 1) / 2; dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]); } } int main() { int q; scanf("%d %d", &n, &q); for (int i = 1;; i *= 2) { if (n <= i) { n = i; break; } } for (int i = 0; i < n; i++) { dat[i + n - 1].a = i; } for (int i = 0; i < q; i++) { int a, v; scanf("%d %d", &a, &v); a--; update(a, v); printf("%d %d\n", dat[0].a + 1, dat[0].v); } return 0; }
replace
13
14
13
14
0
p00099
C++
Memory Limit Exceeded
#include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int main() { int n, q, fig, value; cin >> n >> q; vector<int> memo(n + 1); fill(memo.begin(), memo.end(), 0); priority_queue<pair<int, int>> que; que.push(make_pair(0, -1)); while (q--) { cin >> fig >> value; memo[fig] += value; for (int i = 1; i <= n; i++) que.push(make_pair(memo[i], -i)); for (;;) { if (que.top().first == memo[-que.top().second]) { cout << -que.top().second << " " << que.top().first << endl; break; } que.pop(); } } }
#include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int main() { int n, q, fig, value; cin >> n >> q; vector<int> memo(n + 1); fill(memo.begin(), memo.end(), 0); priority_queue<pair<int, int>> que; que.push(make_pair(0, -1)); while (q--) { cin >> fig >> value; memo[fig] += value; que.push(make_pair(memo[fig], -fig)); for (;;) { if (que.top().first == memo[-que.top().second]) { cout << -que.top().second << " " << que.top().first << endl; break; } que.pop(); } } }
replace
16
18
16
17
MLE
p00099
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cfloat> #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 <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; typedef pair<double, int> d_i; typedef pair<long long, long long> ll_ll; typedef pair<double, double> d_d; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define rep2d(i, j, n) \ for (i = 0; i < n; ++i) \ for (j = i + 1; j < n; ++j) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define scn(n, a) rep(i, n) cin >> a[i] #define sc2n(n, a, b) rep(i, n) cin >> a[i] >> b[i] #define pri(x) cout << x << "\n" #define pri2(x, y) cout << x << " " << y << "\n" #define pri3(x, y, z) cout << x << " " << y << " " << z << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << x << "\n" #define debug2(x, y) cout << " --- " << x << " " << y << "\n" #define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) bool mycom(i_i a, i_i b) { if (a.X == b.X) return a.Y < b.Y; return a.X > b.X; } signed main(void) { int i, j, k; int a[25] = {1}; rep1(i, 25) a[i] = a[i - 1] * 2; for (int testcase = 0; testcase < 1234567; testcase++) { int2(n, q); rep(i, 25) if (n <= a[i]) break; vector<i_i> sgt; sgt.resize(a[i]); rep(j, a[i + 1]) sgt[j] = mp(-123, n + 1); sgt[0] = mp(i, a[i]); rep(i, n) sgt[sgt[0].Y + i] = mp(0, i + 1); for (; q--;) { int2(x, v); x = sgt[0].Y + x - 1; if (v > 0) { sgt[x].X += v; for (; x != 1; x /= 2) { if (mycom(sgt[x], sgt[x / 2])) sgt[x / 2] = sgt[x]; else break; } } else { sgt[x].X += v; for (; x != 1; x /= 2) { if (mycom(sgt[(x / 2) * 2], sgt[(x / 2) * 2 + 1])) sgt[x / 2] = sgt[(x / 2) * 2]; else sgt[x / 2] = sgt[(x / 2) * 2 + 1]; } } pri2(sgt[1].Y, sgt[1].X); } /*/ //*/ break; } return 0; }
#include <algorithm> #include <bitset> #include <cfloat> #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 <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> i_i; typedef pair<long long, int> ll_i; typedef pair<double, int> d_i; typedef pair<long long, long long> ll_ll; typedef pair<double, double> d_d; #define PI 3.141592653589793238462643383279 #define mod 1000000007LL #define rep(i, n) for (i = 0; i < n; ++i) #define rep1(i, n) for (i = 1; i < n; ++i) #define rep2d(i, j, n) \ for (i = 0; i < n; ++i) \ for (j = i + 1; j < n; ++j) #define per(i, n) for (i = n - 1; i > -1; --i) #define int(x) \ int x; \ scanf("%d", &x) #define int2(x, y) \ int x, y; \ scanf("%d%d", &x, &y) #define int3(x, y, z) \ int x, y, z; \ scanf("%d%d%d", &x, &y, &z) #define scn(n, a) rep(i, n) cin >> a[i] #define sc2n(n, a, b) rep(i, n) cin >> a[i] >> b[i] #define pri(x) cout << x << "\n" #define pri2(x, y) cout << x << " " << y << "\n" #define pri3(x, y, z) cout << x << " " << y << " " << z << "\n" #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define endl "\n" #define kabe puts("---------------------------") #define kara puts("") #define debug(x) cout << " --- " << x << "\n" #define debug2(x, y) cout << " --- " << x << " " << y << "\n" #define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n" #define X first #define Y second #define eps 0.0001 #define prid(x) printf("%.15lf\n", x) bool mycom(i_i a, i_i b) { if (a.X == b.X) return a.Y < b.Y; return a.X > b.X; } signed main(void) { int i, j, k; int a[25] = {1}; rep1(i, 25) a[i] = a[i - 1] * 2; for (int testcase = 0; testcase < 1234567; testcase++) { int2(n, q); rep(i, 25) if (n <= a[i]) break; vector<i_i> sgt; sgt.resize(a[i + 1]); rep(j, a[i + 1]) sgt[j] = mp(-123, n + 1); sgt[0] = mp(i, a[i]); rep(i, n) sgt[sgt[0].Y + i] = mp(0, i + 1); for (; q--;) { int2(x, v); x = sgt[0].Y + x - 1; if (v > 0) { sgt[x].X += v; for (; x != 1; x /= 2) { if (mycom(sgt[x], sgt[x / 2])) sgt[x / 2] = sgt[x]; else break; } } else { sgt[x].X += v; for (; x != 1; x /= 2) { if (mycom(sgt[(x / 2) * 2], sgt[(x / 2) * 2 + 1])) sgt[x / 2] = sgt[(x / 2) * 2]; else sgt[x / 2] = sgt[(x / 2) * 2 + 1]; } } pri2(sgt[1].Y, sgt[1].X); } /*/ //*/ break; } return 0; }
replace
84
85
84
85
-6
malloc(): corrupted top size
p00099
C++
Time Limit Exceeded
#include <cstdio> #include <queue> #pragma warning(disable : 4996) using namespace std; int n, q, c[1000000], a, v; int main() { scanf("%d", &n); scanf("%d", &q); priority_queue<pair<int, int>> que; for (int i = 0; i < q; i++) { scanf("%d", &a); scanf("%d", &v); c[a - 1] += v; que.push(make_pair(c[a - 1], -a)); pair<int, int> maximum; while (true) { maximum = que.top(); if (maximum.first != c[-maximum.second + 1]) { que.pop(); } else { break; } } printf("%d %d\n", -maximum.second, maximum.first); } return 0; }
#include <cstdio> #include <queue> #pragma warning(disable : 4996) using namespace std; int n, q, c[1000000], a, v; int main() { scanf("%d", &n); scanf("%d", &q); priority_queue<pair<int, int>> que; for (int i = 0; i < q; i++) { scanf("%d", &a); scanf("%d", &v); c[a - 1] += v; que.push(make_pair(c[a - 1], -a)); pair<int, int> maximum; while (true) { maximum = que.top(); if (maximum.first != c[-maximum.second - 1]) { que.pop(); } else { break; } } printf("%d %d\n", -maximum.second, maximum.first); } return 0; }
replace
27
28
27
28
TLE
p00099
C++
Runtime Error
#include <cstdio> #include <map> #define INF 2000000000 #define fi first #define sec second using namespace std; typedef pair<int, int> P; const int MAX_N = 1 << 15; int n, q; P dat[2 * MAX_N - 1]; void init(int n_) { n = 1; while (n < n_) n *= 2; for (int i = 0; i < 2 * n - 1; i++) { dat[i].fi = i - n + 1; dat[i].sec = -1 * INF; } } void update(int k, int a) { k += n - 1; if (dat[k].sec == -1 * INF) dat[k].sec = a; else dat[k].sec += a; while (k > 0) { k = (k - 1) / 2; if (dat[k * 2 + 1].sec > dat[k * 2 + 2].sec) { dat[k].fi = dat[k * 2 + 1].fi; dat[k].sec = dat[k * 2 + 1].sec; } else { if (dat[k * 2 + 1].sec == dat[k * 2 + 2].sec) { if (dat[k * 2 + 1].fi < dat[k * 2 + 2].fi) { dat[k].fi = dat[k * 2 + 1].fi; dat[k].sec = dat[k * 2 + 1].sec; } else { dat[k].fi = dat[k * 2 + 2].fi; dat[k].sec = dat[k * 2 + 2].sec; } } else { dat[k].fi = dat[k * 2 + 2].fi; dat[k].sec = dat[k * 2 + 2].sec; } } } } P query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return P(-1 * INF, -1 * INF); if (a <= l && r <= b) return dat[k]; else { P vl = query(a, b, k * 2 + 1, l, (l + r) / 2); P vr = query(a, b, k * 2 + 2, (l + r) / 2, r); if (vl.sec > vr.sec) { return vl; } else { if (vl.sec == vr.sec) { if (vl.fi > vr.fi) return vr; else return vl; } else return vr; } } } int main() { scanf("%d%d", &n, &q); init(n); for (int i = 0; i < q; i++) { int a, b; scanf("%d%d", &a, &b); a--; update(a, b); P out = query(0, n, 0, 0, n); printf("%d %d\n", out.fi + 1, out.sec); } }
#include <cstdio> #include <map> #define INF 2000000000 #define fi first #define sec second using namespace std; typedef pair<int, int> P; const int MAX_N = 1 << 21; int n, q; P dat[2 * MAX_N - 1]; void init(int n_) { n = 1; while (n < n_) n *= 2; for (int i = 0; i < 2 * n - 1; i++) { dat[i].fi = i - n + 1; dat[i].sec = -1 * INF; } } void update(int k, int a) { k += n - 1; if (dat[k].sec == -1 * INF) dat[k].sec = a; else dat[k].sec += a; while (k > 0) { k = (k - 1) / 2; if (dat[k * 2 + 1].sec > dat[k * 2 + 2].sec) { dat[k].fi = dat[k * 2 + 1].fi; dat[k].sec = dat[k * 2 + 1].sec; } else { if (dat[k * 2 + 1].sec == dat[k * 2 + 2].sec) { if (dat[k * 2 + 1].fi < dat[k * 2 + 2].fi) { dat[k].fi = dat[k * 2 + 1].fi; dat[k].sec = dat[k * 2 + 1].sec; } else { dat[k].fi = dat[k * 2 + 2].fi; dat[k].sec = dat[k * 2 + 2].sec; } } else { dat[k].fi = dat[k * 2 + 2].fi; dat[k].sec = dat[k * 2 + 2].sec; } } } } P query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return P(-1 * INF, -1 * INF); if (a <= l && r <= b) return dat[k]; else { P vl = query(a, b, k * 2 + 1, l, (l + r) / 2); P vr = query(a, b, k * 2 + 2, (l + r) / 2, r); if (vl.sec > vr.sec) { return vl; } else { if (vl.sec == vr.sec) { if (vl.fi > vr.fi) return vr; else return vl; } else return vr; } } } int main() { scanf("%d%d", &n, &q); init(n); for (int i = 0; i < q; i++) { int a, b; scanf("%d%d", &a, &b); a--; update(a, b); P out = query(0, n, 0, 0, n); printf("%d %d\n", out.fi + 1, out.sec); } }
replace
7
8
7
8
0
p00099
C++
Memory Limit Exceeded
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; /* const int INF = 1 << 29; const int MAX_N = 1000001; // Segment Tree // (数列のサイズ N に対してSegment Treeの頂点は 2*N-1 となる) struct Seg_tree{ int n; vector<int> dat; // コンストラクタで初期化 Seg_tree(int n_){ // 簡単のために要素数を2のべき乗にする n = 1; while( n < n_ ) n *= 2; // すべての頂点の値を -INF にする for(int i = 0; i < 2 * n - 1; i++){ dat.push_back(-INF); } } // k 番目の値 (0-indexed) を a に更新 void update(int k, int a){ k += n - 1; dat[k] = a; // 登りながら更新 while( k > 0 ){ k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // [a,b)の最小値を求める int query(int a, int b, int k=0, int l=0, int r=-INF){ // 初回呼び出し時 if( k == 0 && l == 0 && r == -INF ) r = n; // [a,b) と [l,r) が交差しないとき if( r <= a || b <= l ) return -INF; // [a,b) が [l,r) を完全に含んでいるとき if( a <= l && r <= b ){ return dat[k]; }else{ // それ以外 int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } }; */ // s[k] := k匹釣った人の集合 set<int> s[500001]; // id[k] := 番号 k の人が釣った数 int id[1000000] = {0}; int main() { int n, q, x = 0, y = 0; cin >> n >> q; for (int i = 0; i < n; i++) s[0].insert(i); for (int i = 0; i < q; i++) { int a, v; cin >> a >> v; a--; int prev = id[a]; int next = id[a] + v; x = min(x, next); y = max(y, next); s[prev].erase(a); s[next].insert(a); for (int k = y; k >= x; k--) { if (s[k].size()) { cout << ((*s[k].begin()) + 1) << " " << k << endl; break; } else { y = k; } } id[a] = next; } }
#include <algorithm> #include <iostream> #include <set> #include <vector> using namespace std; /* const int INF = 1 << 29; const int MAX_N = 1000001; // Segment Tree // (数列のサイズ N に対してSegment Treeの頂点は 2*N-1 となる) struct Seg_tree{ int n; vector<int> dat; // コンストラクタで初期化 Seg_tree(int n_){ // 簡単のために要素数を2のべき乗にする n = 1; while( n < n_ ) n *= 2; // すべての頂点の値を -INF にする for(int i = 0; i < 2 * n - 1; i++){ dat.push_back(-INF); } } // k 番目の値 (0-indexed) を a に更新 void update(int k, int a){ k += n - 1; dat[k] = a; // 登りながら更新 while( k > 0 ){ k = (k - 1) / 2; dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]); } } // [a,b)の最小値を求める int query(int a, int b, int k=0, int l=0, int r=-INF){ // 初回呼び出し時 if( k == 0 && l == 0 && r == -INF ) r = n; // [a,b) と [l,r) が交差しないとき if( r <= a || b <= l ) return -INF; // [a,b) が [l,r) を完全に含んでいるとき if( a <= l && r <= b ){ return dat[k]; }else{ // それ以外 int vl = query(a, b, k * 2 + 1, l, (l + r) / 2); int vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } } }; */ // s[k] := k匹釣った人の集合 set<int> s[100001]; // id[k] := 番号 k の人が釣った数 int id[1000000] = {0}; int main() { int n, q, x = 0, y = 0; cin >> n >> q; for (int i = 0; i < n; i++) s[0].insert(i); for (int i = 0; i < q; i++) { int a, v; cin >> a >> v; a--; int prev = id[a]; int next = id[a] + v; x = min(x, next); y = max(y, next); s[prev].erase(a); s[next].insert(a); for (int k = y; k >= x; k--) { if (s[k].size()) { cout << ((*s[k].begin()) + 1) << " " << k << endl; break; } else { y = k; } } id[a] = next; } }
replace
56
57
56
57
MLE
p00099
C++
Runtime Error
// RMQ問題:次の2つのクエリがたくさん与えられる,高速に答えよ。 // 1.区間[i,j]内の要素ai〜ajの最大値をこたえる。2.要素aiにxを追加する。 // ただし、0 <= i,j <= Nとする。最初はa0〜ajは全てINF(= -1e+8)である。 // 単純に配列でシュミレーションすると、常にO(NQ),累積和を使うと、クエリ1はO(1),クエリ2はO(N)かかるので、最悪O(NQ) // 領域を2分割,2分割していって、塊で答えを覚えておけばクエリ1は木の深さ分でできる。 // 葉ノードの区間長が1ならば、葉ノードを変える→根まで木の深さ分更新(O(logN))でできる。 // ということで、セグメントツリー(初実装)で解く.(蛇足 : // 大きい区間の答えを持つ,ノードが便利なのはもちろん、葉ノードは1要素になってるから、区間長1の変更も簡単。 // RMQのペア(番号,数)バージョン。2この変数でソートされた平衡2分木でもできると思う。 #include <algorithm> #include <cmath> #include <iostream> #include <vector> #define rep(i, n) for (i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; // 完全2分木にしよう。(要素数によっては右側の要素を使わないかも…) class segtree { P *a; // 配列で表現。根 = 0,左の子のノード番号 = 親ノード番号*2 + // 1。なので、区間長についてはあまり意識しなくてよい。 int dep; // 根から葉までの距離 public: segtree(int depth, int x) { int i; dep = depth; a = new P[1 << (dep + 1)]; rep(i, 1 << (dep + 1)) a[i] = P(1, x); } ~segtree() { delete[] a; } void insert(int i, int x) // 根の左からi(>=0)番目にxを加算する { int num = i + (1 << dep); int E; // 左のノード(ノード番号が奇数)なら1,右のノードなら-1 // 値の追加 a[num] = P(i, a[num].second + x); // ツリーの更新 while (num > 0) { E = (num % 2) ? 1 : -1; if (a[num].second > a[num + E].second || (a[num].second == a[num + E].second && a[num].first < a[num + E].first)) a[(num - 1) >> 1] = a[num]; else a[(num - 1) >> 1] = a[num + E]; num = (num - 1) >> 1; } } P getmax(int i, int j) { P ans = a[i + (1 << dep)]; if (i == j) return ans; if (i > j) swap(i, j); // 遅延処理. // 葉から見ていく方法でやろう。a[num_i]とa[num_j]を見ている。num_i < // num_j.みたいな 閉区間 int num_i = i + (1 << dep); // 左の子ならその親、右の子ならその親+1に移動 int num_j = j + (1 << dep); // 左の子ならその親-1、右の子ならその親に移動 while (num_i <= num_j) { if ((ans.second < a[num_i].second) || (ans.second == a[num_i].second && ans.first > a[num_i].first)) ans = a[num_i]; if ((ans.second < a[num_j].second) || (ans.second == a[num_j].second && ans.first > a[num_j].first)) ans = a[num_j]; num_i = (num_i) % 2 ? ((num_i - 1) >> 1) : (((num_i - 1) >> 1) + 1); num_j = (num_j) % 2 ? (((num_j - 1) >> 1) - 1) : ((num_j - 1) >> 1); } return ans; } void print_a(int n) { for (int i = 0; i < n; i++) cout << "a[i + (1 << dep)] = " << a[i + (1 << dep)].first << " " << a[i + (1 << dep)].second << endl; } }; int main() { int i; int n, q; int a, b; P ans[50000]; segtree seg(18, 0); cin >> n >> q; for (i = 0; i < q; i++) { cin >> a >> b; seg.insert(a, b); // seg.print_a(n+1); ans[i] = seg.getmax(1, n); } for (i = 0; i < q; i++) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; }
// RMQ問題:次の2つのクエリがたくさん与えられる,高速に答えよ。 // 1.区間[i,j]内の要素ai〜ajの最大値をこたえる。2.要素aiにxを追加する。 // ただし、0 <= i,j <= Nとする。最初はa0〜ajは全てINF(= -1e+8)である。 // 単純に配列でシュミレーションすると、常にO(NQ),累積和を使うと、クエリ1はO(1),クエリ2はO(N)かかるので、最悪O(NQ) // 領域を2分割,2分割していって、塊で答えを覚えておけばクエリ1は木の深さ分でできる。 // 葉ノードの区間長が1ならば、葉ノードを変える→根まで木の深さ分更新(O(logN))でできる。 // ということで、セグメントツリー(初実装)で解く.(蛇足 : // 大きい区間の答えを持つ,ノードが便利なのはもちろん、葉ノードは1要素になってるから、区間長1の変更も簡単。 // RMQのペア(番号,数)バージョン。2この変数でソートされた平衡2分木でもできると思う。 #include <algorithm> #include <cmath> #include <iostream> #include <vector> #define rep(i, n) for (i = 0; i < n; i++) using namespace std; typedef pair<int, int> P; // 完全2分木にしよう。(要素数によっては右側の要素を使わないかも…) class segtree { P *a; // 配列で表現。根 = 0,左の子のノード番号 = 親ノード番号*2 + // 1。なので、区間長についてはあまり意識しなくてよい。 int dep; // 根から葉までの距離 public: segtree(int depth, int x) { int i; dep = depth; a = new P[1 << (dep + 1)]; rep(i, 1 << (dep + 1)) a[i] = P(1, x); } ~segtree() { delete[] a; } void insert(int i, int x) // 根の左からi(>=0)番目にxを加算する { int num = i + (1 << dep); int E; // 左のノード(ノード番号が奇数)なら1,右のノードなら-1 // 値の追加 a[num] = P(i, a[num].second + x); // ツリーの更新 while (num > 0) { E = (num % 2) ? 1 : -1; if (a[num].second > a[num + E].second || (a[num].second == a[num + E].second && a[num].first < a[num + E].first)) a[(num - 1) >> 1] = a[num]; else a[(num - 1) >> 1] = a[num + E]; num = (num - 1) >> 1; } } P getmax(int i, int j) { P ans = a[i + (1 << dep)]; if (i == j) return ans; if (i > j) swap(i, j); // 遅延処理. // 葉から見ていく方法でやろう。a[num_i]とa[num_j]を見ている。num_i < // num_j.みたいな 閉区間 int num_i = i + (1 << dep); // 左の子ならその親、右の子ならその親+1に移動 int num_j = j + (1 << dep); // 左の子ならその親-1、右の子ならその親に移動 while (num_i <= num_j) { if ((ans.second < a[num_i].second) || (ans.second == a[num_i].second && ans.first > a[num_i].first)) ans = a[num_i]; if ((ans.second < a[num_j].second) || (ans.second == a[num_j].second && ans.first > a[num_j].first)) ans = a[num_j]; num_i = (num_i) % 2 ? ((num_i - 1) >> 1) : (((num_i - 1) >> 1) + 1); num_j = (num_j) % 2 ? (((num_j - 1) >> 1) - 1) : ((num_j - 1) >> 1); } return ans; } void print_a(int n) { for (int i = 0; i < n; i++) cout << "a[i + (1 << dep)] = " << a[i + (1 << dep)].first << " " << a[i + (1 << dep)].second << endl; } }; int main() { int i; int n, q; int a, b; P ans[100000]; segtree seg(21, 0); cin >> n >> q; for (i = 0; i < q; i++) { cin >> a >> b; seg.insert(a, b); // seg.print_a(n+1); ans[i] = seg.getmax(1, n); } for (i = 0; i < q; i++) { cout << ans[i].first << " " << ans[i].second << endl; } return 0; }
replace
92
94
92
94
0
p00099
C++
Runtime Error
#include <iostream> #include <queue> using namespace std; typedef pair<int, int> P; int main() { int a, n, q, v, m_a = 0; cin >> n >> q; vector<int> fish(n, 0); priority_queue<P> pq; pq.push(P(1, 0)); for (int i = 0; i < q; i++) { cin >> a >> v; fish[a] += v; pq.push(P(fish[a], -a)); while (fish[-pq.top().second] != pq.top().first) pq.pop(); cout << -pq.top().second << ' ' << pq.top().first << endl; } return 0; }
#include <iostream> #include <queue> using namespace std; typedef pair<int, int> P; int main() { int a, n, q, v, m_a = 0; cin >> n >> q; vector<int> fish(n + 1, 0); priority_queue<P> pq; pq.push(P(1, 0)); for (int i = 0; i < q; i++) { cin >> a >> v; fish[a] += v; pq.push(P(fish[a], -a)); while (fish[-pq.top().second] != pq.top().first) pq.pop(); cout << -pq.top().second << ' ' << pq.top().first << endl; } return 0; }
replace
9
10
9
10
0
p00100
C++
Runtime Error
#include <memory.h> #include <stdio.h> int main() { int n, i, j, k, e[100], p[100], q[100]; int c[100], count = 0, count2 = 0; int gokei = 0; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { scanf("%d %d %d", &e[i], &p[i], &q[i]); gokei = p[i] * q[i]; for (j = 0; j < i; j++) { if (e[i] == e[j]) { gokei += p[j] * q[j]; } } for (k = 0; k < count; k++) { if (e[i] == c[k]) { goto a; } } if (gokei >= 1000000) { c[count] = e[i]; count++; } a: gokei = 0; } for (i = 0; i < count; i++) { printf("%d\n", c[i]); } if (count == 0) { printf("NA\n"); } count = 0; memset(c, 0, sizeof(c)); } return 0; }
#include <memory.h> #include <stdio.h> int main() { int n, i, j, k, e[1000], p[1000], q[1000]; int c[1000], count = 0, count2 = 0; int gokei = 0; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { scanf("%d %d %d", &e[i], &p[i], &q[i]); gokei = p[i] * q[i]; for (j = 0; j < i; j++) { if (e[i] == e[j]) { gokei += p[j] * q[j]; } } for (k = 0; k < count; k++) { if (e[i] == c[k]) { goto a; } } if (gokei >= 1000000) { c[count] = e[i]; count++; } a: gokei = 0; } for (i = 0; i < count; i++) { printf("%d\n", c[i]); } if (count == 0) { printf("NA\n"); } count = 0; memset(c, 0, sizeof(c)); } return 0; }
replace
3
5
3
5
0
p00100
C++
Runtime Error
// 2011/01/12 Tazoe #include <iostream> using namespace std; int main() { while (true) { int n; cin >> n; if (n == 0) break; int emp[4000][3]; for (int i = 0; i < 4000; i++) { emp[i][0] = i + 1; emp[i][1] = 0; emp[i][2] = 5000; } int ord = 1; for (int i = 0; i < n; i++) { int id, p, q; cin >> id >> p >> q; if (1000000 / p + 1 <= q) emp[id - 1][1] = 1000000; else if (emp[id - 1][1] < 1000000) emp[id - 1][1] += p * q; if (emp[id - 1][2] == 5000) { emp[id - 1][2] = ord; ord++; } } for (int i = 0; i < 3999; i++) for (int j = i + 1; j < 4000; j++) if (emp[i][2] > emp[j][2]) { int tmp1 = emp[i][0]; int tmp2 = emp[i][1]; int tmp3 = emp[i][2]; emp[i][0] = emp[j][0]; emp[i][1] = emp[j][1]; emp[i][2] = emp[j][2]; emp[j][0] = tmp1; emp[j][1] = tmp2; emp[j][2] = tmp3; } int cnt = 0; for (int i = 0; emp[i][2] != 5000 && i < 4000; i++) if (emp[i][1] >= 1000000) { cout << emp[i][0] << endl; cnt++; } if (cnt == 0) cout << "NA" << endl; } return 0; }
// 2011/01/12 Tazoe #include <iostream> using namespace std; int main() { while (true) { int n; cin >> n; if (n == 0) break; int emp[4000][3]; for (int i = 0; i < 4000; i++) { emp[i][0] = i + 1; emp[i][1] = 0; emp[i][2] = 5000; } int ord = 1; for (int i = 0; i < n; i++) { int id, p, q; cin >> id >> p >> q; if (p != 0 && 1000000 / p + 1 <= q) emp[id - 1][1] = 1000000; else if (emp[id - 1][1] < 1000000) emp[id - 1][1] += p * q; if (emp[id - 1][2] == 5000) { emp[id - 1][2] = ord; ord++; } } for (int i = 0; i < 3999; i++) for (int j = i + 1; j < 4000; j++) if (emp[i][2] > emp[j][2]) { int tmp1 = emp[i][0]; int tmp2 = emp[i][1]; int tmp3 = emp[i][2]; emp[i][0] = emp[j][0]; emp[i][1] = emp[j][1]; emp[i][2] = emp[j][2]; emp[j][0] = tmp1; emp[j][1] = tmp2; emp[j][2] = tmp3; } int cnt = 0; for (int i = 0; emp[i][2] != 5000 && i < 4000; i++) if (emp[i][1] >= 1000000) { cout << emp[i][0] << endl; cnt++; } if (cnt == 0) cout << "NA" << endl; } return 0; }
replace
23
24
23
24
0
p00100
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> #include <utility> #include <vector> typedef long long ll; using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n; while (scanf("%d\n", &n), n) { vector<pair<ll, ll>> v; rep(i, n) { ll x, y, z; cin >> x >> y >> z; bool f = false; for (int j = 0; j < v.size(); ++j) { if (v[j].first == x) { v[j].second += y * z; f = true; break; } } if (!f) { v.push_back(make_pair(x, y * z)); } } bool flag = false; for (int j = 0; j < v.size(); ++j) { if (v[j].second >= 1000000) { flag = true; cout << v[j].first << endl; } } if (!flag) cout << "NA" << endl; } return 0; }
#include <cstdio> #include <iostream> #include <utility> #include <vector> typedef long long ll; using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int n; while (scanf("%d\n", &n), n) { vector<pair<ll, ll>> v; rep(i, n) { ll x, y, z; cin >> x >> y >> z; bool f = false; for (int j = 0; j < v.size(); ++j) { if (v[j].first == x) { v[j].second += y * z; f = true; break; } } if (!f) { v.push_back(make_pair(x, y * z)); } } bool flag = false; for (int j = 0; j < v.size(); ++j) { if (v[j].second >= 1000000) { flag = true; cout << v[j].first << endl; } } if (!flag) cout << "NA" << endl; } return 0; }
replace
8
9
8
9
TLE
p00101
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string str; int n; cin >> n; getline(cin, str); for (int i = 0; i < n; i++) { getline(cin, str); for (int j = 0; j < str.size() - 6; j++) { if (str[j] == 'H') { if (str.substr(j + 1, 6) == "oshino") str.replace(j, 7, "Hoshina"); else if (str.substr(j + 1, 6) == "oshina") str.replace(j, 7, "Hoshino"); } } cout << str << endl; } }
#include <iostream> #include <string> using namespace std; int main() { string str; int n; cin >> n; getline(cin, str); for (int i = 0; i < n; i++) { getline(cin, str); for (int j = 0; j < int(str.size()) - 6; j++) { if (str.substr(j, 7) == "Hoshino") str.replace(j, 7, "Hoshina"); } cout << str << endl; } }
replace
11
18
11
14
0
p00101
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <typeinfo> #include <vector> #define INF 100000000 #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; typedef long long ll; int main() { int n; cin >> n; getchar(); rep(i, n) { string s; getline(cin, s); for (int i = 0; i < s.size() - 6; i++) { if (s[i] == 'H' && s[i + 1] == 'o' && s[i + 2] == 's' && s[i + 3] == 'h' && s[i + 4] == 'i' && s[i + 5] == 'n' && s[i + 6] == 'o') { s[i + 6] = 'a'; } } cout << s << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <string> #include <typeinfo> #include <vector> #define INF 100000000 #define rep(i, a) for (int i = 0; i < (a); i++) using namespace std; typedef long long ll; int main() { int n; cin >> n; getchar(); rep(i, n) { string s; getline(cin, s); for (int i = 0; i < s.size(); i++) { if (s[i] == 'H' && s[i + 1] == 'o' && s[i + 2] == 's' && s[i + 3] == 'h' && s[i + 4] == 'i' && s[i + 5] == 'n' && s[i + 6] == 'o') { s[i + 6] = 'a'; } } cout << s << endl; } return 0; }
replace
24
25
24
25
0
p00101
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string> using namespace std; void solve() { int n; scanf("%d\n", &n); string name = "Hoshino"; while (n--) { string s; getline(cin, s); for (int i = 0; i < s.length() - name.length() + 1; ++i) { bool flag = true; for (int j = 0; j < name.length(); ++j) { if (s[i + j] != name[j]) { flag = false; break; } } if (flag) { s[i + name.length() - 1] = 'a'; } else { continue; } } cout << s << endl; } } int main() { solve(); return (0); }
#include <iostream> #include <stdio.h> #include <string> using namespace std; void solve() { int n; scanf("%d\n", &n); string name = "Hoshino"; while (n--) { string s; getline(cin, s); int length = s.length() - name.length() + 1; for (int i = 0; i < length; ++i) { bool flag = true; for (int j = 0; j < name.length(); ++j) { if (s[i + j] != name[j]) { flag = false; break; } } if (flag) { s[i + name.length() - 1] = 'a'; } else { continue; } } cout << s << endl; } } int main() { solve(); return (0); }
replace
13
14
13
15
0
p00101
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string str; int n; cin >> n; cin.ignore(); while (n--) { getline(cin, str); for (int j = 0; j < (int)str.size(); j++) { string key = str.substr(j, 7), repl; if (key == "Hoshino") { repl = "Hoshina"; for (int k = 0; k < n; k++) { str[j + k] = repl[k]; } } } cout << str << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string str; int n; cin >> n; cin.ignore(); while (n--) { getline(cin, str); for (int j = 0; j < (int)str.size(); j++) { string key = str.substr(j, 7), repl; if (key == "Hoshino") { repl = "Hoshina"; for (int k = 0; k < 7; k++) { str[j + k] = repl[k]; } } } cout << str << endl; } return 0; }
replace
16
17
16
17
0
p00101
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) reep((i), 0, (n)) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI = 6 * asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } int main() { int n; cin >> n; string t; getline(cin, t); rep(i, n) { string s; getline(cin, s); // cout<<s.size()<<endl; rep(j, s.size() - 6) { if (s.substr(j, 7) == "Hoshino") { // cout<<"hoge"<<endl; // cout<<s[j+6]<<endl; s[j + 6] = 'a'; } } cout << s << endl; } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) reep((i), 0, (n)) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI = 6 * asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } int main() { int n; cin >> n; string t; getline(cin, t); rep(i, n) { string s; getline(cin, s); // cout<<s.size()<<endl; if (s.size() < 7) { cout << s << endl; continue; } rep(j, s.size() - 6) { if (s.substr(j, 7) == "Hoshino") { // cout<<"hoge"<<endl; // cout<<s[j+6]<<endl; s[j + 6] = 'a'; } } cout << s << endl; } return 0; }
insert
46
46
46
50
0
p00101
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; scanf("%d%*c", &n); for (int i = 0; i < n; ++i) { string s; getline(cin, s); regex re("Hoshino"); cout << regex_replace(s, re, "Hoshina") << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { int n; scanf("%d%*c", &n); for (int i = 0; i < n; ++i) { string s; getline(cin, s); regex re("Hoshino"); cout << regex_replace(s, re, "Hoshina") << endl; } return 0; }
delete
2
4
2
2
TLE
p00101
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; const double EPS = 1e-9; const double PI = 3.14159265359; typedef complex<double> P; typedef long long int li; int main() { int n; string hos = "Hoshino"; cin >> n; cin.ignore(); while (n--) { string s; getline(cin, s); for (int i = 0; i < s.size() + 1 - hos.size(); i++) { if (s.substr(i, hos.size()) == hos) { s[i + hos.size() - 1] = 'a'; } } cout << s << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; const double EPS = 1e-9; const double PI = 3.14159265359; typedef complex<double> P; typedef long long int li; int main() { int n; string hos = "Hoshino"; cin >> n; cin.ignore(); while (n--) { string s; getline(cin, s); int k = s.size() + 1 - hos.size(); for (int i = 0; i < k; i++) { if (s.substr(i, hos.size()) == hos) { s[i + hos.size() - 1] = 'a'; } } cout << s << endl; } return 0; }
replace
34
35
34
36
0
p00101
C++
Runtime Error
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::string text; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { getline(std::cin, text); u_int index = 0; while ((index = text.find(str_false, index)) != std::string::npos) text.replace(index, str_false.size(), str_true); std::cout << text << std::endl; } return 0; }
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::string text; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { getline(std::cin, text); int index = 0; while ((index = text.find(str_false, index)) != std::string::npos) text.replace(index, str_false.size(), str_true); std::cout << text << std::endl; } return 0; }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::replace: __pos (which is 4294967295) > this->size() (which is 7)
p00101
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define INF 100000000 #define MOD 1000000007 #define pb push_back #define mp make_pair #define fi first #define sec second #define lb lower_bound #define ub upper_bound #define SS stringstream #define rep(i, n) for (int i = 0; i < n; i++) #define sz(x) ((int)(x).size()) #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).begin(), (x).end(), greater<int>()) #define clr(a, b) memset((a), (b), sizeof(a)) typedef long long int ll; typedef pair<int, int> P; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<P> Vp; typedef priority_queue<P, vector<P>, greater<P>> PQ; int n; string str; int main() { cin >> n; cin.ignore(); rep(i, n) { getline(cin, str); rep(j, str.size() - 6) { if (str[j] == 'H' && str[j + 1] == 'o' && str[j + 2] == 's' && str[j + 3] == 'h' && str[j + 4] == 'i' && str[j + 5] == 'n' && str[j + 6] == 'o') { str[j + 6] = 'a'; } } cout << str << endl; } }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define INF 100000000 #define MOD 1000000007 #define pb push_back #define mp make_pair #define fi first #define sec second #define lb lower_bound #define ub upper_bound #define SS stringstream #define rep(i, n) for (int i = 0; i < n; i++) #define sz(x) ((int)(x).size()) #define SORT(x) sort((x).begin(), (x).end()) #define RSORT(x) sort((x).begin(), (x).end(), greater<int>()) #define clr(a, b) memset((a), (b), sizeof(a)) typedef long long int ll; typedef pair<int, int> P; typedef vector<int> Vi; typedef vector<ll> Vll; typedef vector<P> Vp; typedef priority_queue<P, vector<P>, greater<P>> PQ; int n; string str; int main() { cin >> n; cin.ignore(); rep(i, n) { getline(cin, str); if (str.size() < 7) { cout << str << endl; continue; } rep(j, str.size() - 6) { if (str[j] == 'H' && str[j + 1] == 'o' && str[j + 2] == 's' && str[j + 3] == 'h' && str[j + 4] == 'i' && str[j + 5] == 'n' && str[j + 6] == 'o') { str[j + 6] = 'a'; } } cout << str << endl; } }
insert
44
44
44
48
0
p00101
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; cin.get(); for (int i = 0; i < n; i++) { string s; getline(cin, s); for (int j = 0; j <= s.size() - 7; j++) { if (s.substr(j, 7) == "Hoshino") s[j + 6] = 'a'; } cout << s << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; cin.get(); for (int i = 0; i < n; i++) { string s; getline(cin, s); for (int j = 0; j < s.size(); j++) { if (s.substr(j, 7) == "Hoshino") s[j + 6] = 'a'; } cout << s << endl; } return 0; }
replace
11
12
11
12
0
p00101
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { string check = "Hoshino"; int n; cin >> n; for (int i = 0; i < n; i++) { string str; if (i == 0) cin.ignore(); getline(cin, str); for (int j = 0; j < str.length() - 6; j++) { for (int k = 0; k < 7; k++) { // printf("%c %c\n", check[k], str[j+k]); if (check[k] == str[j + k] && k < 6) continue; else if (check[k] == str[j + k] && k == 6) { str[j + k] = 'a'; } else break; } } cout << str << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { string check = "Hoshino"; int n; cin >> n; for (int i = 0; i < n; i++) { string str; if (i == 0) cin.ignore(); getline(cin, str); if (str.length() < 7) { cout << str << endl; continue; } for (int j = 0; j < str.length() - 6; j++) { for (int k = 0; k < 7; k++) { // printf("%c %c\n", check[k], str[j+k]); if (check[k] == str[j + k] && k < 6) continue; else if (check[k] == str[j + k] && k == 6) { str[j + k] = 'a'; } else break; } } cout << str << endl; } return 0; }
insert
13
13
13
17
0
p00101
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define CC puts("-------ok--------"); #define all(in) in.begin(), in.end() using namespace std; typedef pair<int, int> pii; #define MAX 99999999 int main() { int n; cin >> n; char c; scanf("%c", &c); rep(p, n) { string s; getline(cin, s); rep(i, s.length()) { int b = (int)s.find("Hoshino", i); if (b != -1) { s.replace(b + i, 7, "Hoshina"); i += 7; } } cout << s << endl; } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define CC puts("-------ok--------"); #define all(in) in.begin(), in.end() using namespace std; typedef pair<int, int> pii; #define MAX 99999999 int main() { int n; cin >> n; char c; scanf("%c", &c); rep(p, n) { string s; getline(cin, s); rep(i, s.length()) { int b = (int)s.find("Hoshino", i); if (b != -1) { s.replace(b, 7, "Hoshina"); i += 6; } } cout << s << endl; } }
replace
41
43
41
43
0
p00101
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main(void) { int n; string str; cin >> n; cin.ignore(); while (n--) { getline(cin, str); for (int i = 0; i < str.size() - 6; i++) { if (str.substr(i, 7) == "Hoshino") str[i + 6] = 'a'; } cout << str << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(void) { int n; string str; cin >> n; cin.ignore(); while (n--) { getline(cin, str); for (int i = 0; i < str.size(); i++) { if (str.substr(i, 7) == "Hoshino") str[i + 6] = 'a'; } cout << str << endl; } return 0; }
replace
12
13
12
13
0
p00101
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { char ho[8] = {'H', 'o', 's', 'h', 'i', 'n', 'o'}; int n; string s; cin >> n; cin.ignore(); while (n--) { getline(cin, s); rep(i, s.size() - 6) { // cout<<i<<endl; bool f = true; rep(j, 7) { if (s[i + j] != ho[j]) { f = false; break; } } if (f) { s[i + 1] = 'a'; } } cout << s << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { char ho[8] = {'H', 'o', 's', 'h', 'i', 'n', 'o'}; int n; string s; cin >> n; cin.ignore(); while (n--) { getline(cin, s); int a = s.length(); rep(i, a - 6) { if (s[i] == 'H' && s[i + 1] == 'o' && s[i + 2] == 's' && s[i + 3] == 'h' && s[i + 4] == 'i' && s[i + 5] == 'n' && s[i + 6] == 'o') { s[i + 6] = 'a'; i += 6; } } cout << s << endl; } }
replace
11
22
11
18
0
p00101
C++
Time Limit Exceeded
#include <stdio.h> #include <string.h> int main(void) { char sentence[1050]; int n; scanf("%d\n", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < 1050; j++) { sentence[j] = getchar(); if (sentence[j] == '\n') { sentence[j] = 0; break; } } for (int j = 0; j < 1025; i++) { if (sentence[j] == 0) break; if (!strncmp(sentence + j, "Hoshino", 7)) { sentence[j + 6] = 'a'; } } puts(sentence); } return 0; }
#include <stdio.h> #include <string.h> int main(void) { char sentence[1050]; int n; scanf("%d\n", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < 1050; j++) { sentence[j] = getchar(); if (sentence[j] == '\n') { sentence[j] = 0; break; } } for (int j = 0; j < 1025; j++) { if (sentence[j] == 0) break; if (!strncmp(sentence + j, "Hoshino", 7)) { sentence[j + 6] = 'a'; } } puts(sentence); } return 0; }
replace
15
16
15
16
TLE
p00101
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; cin.ignore(); while (n--) { string s; getline(cin, s); for (int i = 0; i < s.length() - 6; i++) { if (s.substr(i, 7) == "Hoshino") s.replace(i, 7, "Hoshina"); } cout << s << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n; cin >> n; cin.ignore(); while (n--) { string s; getline(cin, s); if (s.length() >= 7) { for (int i = 0; i < s.length() - 6; i++) { if (s.substr(i, 7) == "Hoshino") s.replace(i, 7, "Hoshina"); } } cout << s << endl; } return 0; }
replace
12
15
12
17
0
p00101
C++
Runtime Error
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { std::string text; getline(std::cin, text); u_int index = 0; while ((index = text.find(str_false, index)) != std::string::npos) { text.replace(index, str_false.size(), str_true); index += str_false.size(); } std::cout << text << std::endl; } return 0; }
#include <iostream> #include <string> int main() { const std::string str_false = "Hoshino"; const std::string str_true = "Hoshina"; u_int num_of_data; std::cin >> num_of_data; std::cin.ignore(); for (u_int i = 0; i < num_of_data; ++i) { std::string text; getline(std::cin, text); int index = 0; while ((index = text.find(str_false, index)) != std::string::npos) { text.replace(index, str_false.size(), str_true); index += str_false.size(); } std::cout << text << std::endl; } return 0; }
replace
15
16
15
16
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::replace: __pos (which is 4294967295) > this->size() (which is 7)
p00101
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main(void) { int n; string h = "Hoshino"; string s; cin >> n; getline(cin, s); stringstream ss(s); ss >> n; rep(loop, n) { getline(cin, s); rep(i, s.size() - h.size() + 1) { bool same = true; rep(j, h.size()) { if (s[i + j] != h[j]) { same = false; break; } } if (same) s[i + h.size() - 1] = 'a'; } cout << s << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main(void) { int n; string h = "Hoshino"; string s; cin >> n; getline(cin, s); stringstream ss(s); ss >> n; rep(loop, n) { getline(cin, s); rep(i, s.size()) { if (i + h.size() - 1 >= s.size()) break; bool same = true; rep(j, h.size()) { if (s[i + j] != h[j]) { same = false; break; } } if (same) s[i + h.size() - 1] = 'a'; } cout << s << endl; } }
replace
14
15
14
17
0
p00101
C++
Runtime Error
#include <iostream> #include <string.h> using namespace std; int main() { int n, i, j; ios::sync_with_stdio(); string s; scanf("%d", &n); cin.get(); for (i = 0; i < n; i++) { getline(cin, s); for (j = 0; s[j + 6] != '\0'; j++) { if (s.substr(j, 7) == "Hoshino") s[j + 6] = 'a'; } cout << s << endl; } return 0; }
#include <iostream> #include <string.h> using namespace std; int main() { int n, i, j; ios::sync_with_stdio(); string s; scanf("%d", &n); cin.get(); for (i = 0; i < n; i++) { getline(cin, s); for (j = 0; j + 6 < s.size(); j++) { if (s.substr(j, 7) == "Hoshino") s[j + 6] = 'a'; } cout << s << endl; } return 0; }
replace
15
16
15
16
0
p00101
C++
Runtime Error
#include <algorithm> #include <cfloat> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int n; string s; string d = "Hoshina"; cin >> n; cin.ignore(); while (n--) { getline(cin, s); while (1) { unsigned int loc = s.find("Hoshino"); if (loc != string::npos) s.replace(loc, d.size(), d); else break; } cout << s << endl; } }
#include <algorithm> #include <cfloat> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int main() { int n; string s; string d = "Hoshina"; cin >> n; cin.ignore(); while (n--) { getline(cin, s); for (int i = 6; i < s.size(); i++) { if (s.substr(i - 6, 7) == "Hoshino") s.at(i) = 'a'; } cout << s << endl; } }
replace
19
25
19
22
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::replace: __pos (which is 4294967295) > this->size() (which is 7)
p00101
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #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 it ::iterator #define all(in) in.begin(), in.end() const double PI = acos(-1); const double ESP = 1e-10; using namespace std; int main() { int n; string s; cin >> n; getline(cin, s); rep(i, n) { getline(cin, s); rep(j, s.size() - 6) { if (s.substr(j, 7) == "Hoshino") s[j + 6] = 'a'; } cout << s << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #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 it ::iterator #define all(in) in.begin(), in.end() const double PI = acos(-1); const double ESP = 1e-10; using namespace std; int main() { int n; string s; cin >> n; getline(cin, s); rep(i, n) { getline(cin, s); for (int j = 7; j <= s.size(); j++) { if (s.substr(j - 7, 7) == "Hoshino") s[j - 1] = 'a'; } cout << s << endl; } }
replace
25
28
25
28
0
p00102
C++
Time Limit Exceeded
#include <stdio.h> int main(void) { int matrix[10][10], i, j, dataset; while (scanf("%d", &dataset)) { if (dataset == 0) break; // init add total norm for (i = 0; i < dataset + 1; i++) { matrix[dataset][i] = 0; matrix[i][dataset] = 0; } // input and calc for (i = 0; i < dataset; i++) { for (j = 0; j < dataset; j++) { scanf("%d", &matrix[i][j]); matrix[i][dataset] += matrix[i][j]; } } // calc for (j = 0; j < dataset + 1; j++) { for (i = 0; i < dataset; i++) { matrix[dataset][j] += matrix[i][j]; } } // output for (i = 0; i < dataset + 1; i++) { for (j = 0; j < dataset + 1; j++) { printf("%5d", matrix[i][j]); } printf("\n"); } } }
#include <stdio.h> int main(void) { int matrix[11][11], i, j, dataset; while (scanf("%d", &dataset)) { if (dataset == 0) break; // init add total norm for (i = 0; i < dataset + 1; i++) { matrix[dataset][i] = 0; matrix[i][dataset] = 0; } // input and calc for (i = 0; i < dataset; i++) { for (j = 0; j < dataset; j++) { scanf("%d", &matrix[i][j]); matrix[i][dataset] += matrix[i][j]; } } // calc for (j = 0; j < dataset + 1; j++) { for (i = 0; i < dataset; i++) { matrix[dataset][j] += matrix[i][j]; } } // output for (i = 0; i < dataset + 1; i++) { for (j = 0; j < dataset + 1; j++) { printf("%5d", matrix[i][j]); } printf("\n"); } } }
replace
3
4
3
4
TLE
p00102
C++
Time Limit Exceeded
#include <cstring> #include <iomanip> #include <iostream> int main() { int n; while (std::cin >> n, n) { int data[10][10]; memset(data, 0, sizeof(data)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cin >> data[i][j]; data[i][n] += data[i][j]; data[n][j] += data[i][j]; data[n][n] += data[i][j]; } } for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) { std::cout << std::setw(5) << std::right << data[i][j]; } std::cout << std::endl; } } return 0; }
#include <cstring> #include <iomanip> #include <iostream> int main() { int n; while (std::cin >> n, n) { int data[11][11]; memset(data, 0, sizeof(data)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { std::cin >> data[i][j]; data[i][n] += data[i][j]; data[n][j] += data[i][j]; data[n][n] += data[i][j]; } } for (int i = 0; i < n + 1; i++) { for (int j = 0; j < n + 1; j++) { std::cout << std::setw(5) << std::right << data[i][j]; } std::cout << std::endl; } } return 0; }
replace
7
8
7
8
TLE
p00102
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 10000; int n, a[N][N]; signed main(void) { ios::sync_with_stdio(false); while (cin >> n && n) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> a[i][j]; for (int i = 1, sum; i <= n; i++) { sum = 0; for (int j = 1; j <= n; j++) sum += a[i][j]; a[i][n + 1] = sum; } for (int j = 1, sum; j <= n; j++) { sum = 0; for (int i = 1; i <= n; i++) sum += a[i][j]; a[n + 1][j] = sum; } int sum = 0; for (int i = 1; i <= n; i++) sum += a[i][n + 1]; a[n + 1][n + 1] = sum; for (int i = 1; i <= n + 1; i++, cout << endl) for (int j = 1; j <= n + 1; j++) cout << setw(5) << a[i][j]; } }
#include <bits/stdc++.h> using namespace std; const int N = 1000; int n, a[N][N]; signed main(void) { ios::sync_with_stdio(false); while (cin >> n && n) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> a[i][j]; for (int i = 1, sum; i <= n; i++) { sum = 0; for (int j = 1; j <= n; j++) sum += a[i][j]; a[i][n + 1] = sum; } for (int j = 1, sum; j <= n; j++) { sum = 0; for (int i = 1; i <= n; i++) sum += a[i][j]; a[n + 1][j] = sum; } int sum = 0; for (int i = 1; i <= n; i++) sum += a[i][n + 1]; a[n + 1][n + 1] = sum; for (int i = 1; i <= n + 1; i++, cout << endl) for (int j = 1; j <= n + 1; j++) cout << setw(5) << a[i][j]; } }
replace
2
3
2
3
MLE
p00102
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; void Solution() { int n; int a[10][10]; while (true) { cin >> n; if (n == 0) { break; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { a[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; a[i][n] += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= n; j++) { a[n][j] += a[i][j]; } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { cout << setw(5) << a[i][j]; } cout << endl; } } } int main() { Solution(); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; void Solution() { int n; int a[11][11]; while (true) { cin >> n; if (n == 0) { break; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { a[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; a[i][n] += a[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j <= n; j++) { a[n][j] += a[i][j]; } } for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { cout << setw(5) << a[i][j]; } cout << endl; } } } int main() { Solution(); return 0; }
replace
15
16
15
16
0
p00103
C++
Time Limit Exceeded
#include <fstream> #include <iostream> #include <string> int main() { int hit, out, score, data_set_num; std::string event, str; std::getline(std::cin, str); sscanf(str.c_str(), "%d ", &data_set_num); while (data_set_num) { std::cin >> event; if (event == "HIT") { ++hit; if (hit == 4) { ++score; hit = 3; } } else if (event == "HOMERUN") { score += (hit + 1); hit = 0; } else if (event == "OUT") { ++out; } if (out == 3) { std::cout << score << std::endl; hit = 0; score = 0; --data_set_num; } } return 0; }
#include <fstream> #include <iostream> #include <string> int main() { int hit, out, score, data_set_num; std::string event, str; std::getline(std::cin, str); sscanf(str.c_str(), "%d ", &data_set_num); while (data_set_num) { std::cin >> event; if (event == "HIT") { ++hit; if (hit == 4) { ++score; hit = 3; } } else if (event == "HOMERUN") { score += (hit + 1); hit = 0; } else if (event == "OUT") { ++out; } if (out == 3) { std::cout << score << std::endl; hit = 0; score = 0; out = 0; --data_set_num; } } return 0; }
insert
29
29
29
30
TLE
p00103
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ini = 0, out = 0, hit = 0, cnt = 0; while (ini <= n) { string s; cin >> s; if (s == "OUT") { out++; if (out == 3) { cout << cnt << endl; cnt = 0; hit = 0; out = 0; ini++; } } if (s == "HIT") { if (hit == 3) { cnt++; } else { hit++; } } if (s == "HOMERUN") { cnt += hit + 1; hit = 0; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int ini = 0, out = 0, hit = 0, cnt = 0; while (ini < n) { string s; cin >> s; if (s == "OUT") { out++; if (out == 3) { cout << cnt << endl; cnt = 0; hit = 0; out = 0; ini++; } } if (s == "HIT") { if (hit == 3) { cnt++; } else { hit++; } } if (s == "HOMERUN") { cnt += hit + 1; hit = 0; } } }
replace
7
8
7
8
TLE
p00103
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int o, i, out = 0, b = 0, p[10]; string ev; cin >> o; for (i = 0; i < o; i++) { p[i] = 0; while (1) { cin >> ev; if (ev == "HIT") { b++; if (b == 4) { b--; p[i]++; } } else if (ev == "HOMERUN") { p[i] += b + 1; b = 0; } else if (ev == "OUT") { out++; } if (out == 3) break; } out = 0; b = 0; } for (i = 0; i < o; i++) { cout << p[i] << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int o, i, out = 0, b = 0, p[100]; string ev; cin >> o; for (i = 0; i < o; i++) { p[i] = 0; while (1) { cin >> ev; if (ev == "HIT") { b++; if (b == 4) { b--; p[i]++; } } else if (ev == "HOMERUN") { p[i] += b + 1; b = 0; } else if (ev == "OUT") { out++; } if (out == 3) break; } out = 0; b = 0; } for (i = 0; i < o; i++) { cout << p[i] << endl; } return 0; }
replace
5
6
5
6
0