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
p00056
C++
Time Limit Exceeded
#include <algorithm> #include <deque> #include <iostream> #include <stdio.h> using namespace std; void MakePrimeArray(deque<bool> &A, int n) { A[0] = A[1] = false; for (int i = 2; i < n; i++) { A[i] = true; } for (int i = 2; i * i < n; i++) { if (A[i]) { for (int j = i * i; j < n; j += i) { A[j] = false; } } } } inline int GoldBach(const deque<int> &prime, int n) { int count = 0; deque<int> clear; bool ok = true; for (int i = 0; prime[i] < n; i++) { if (std::binary_search(clear.begin(), clear.end(), prime[i])) { break; } int num = n - prime[i]; if (std::binary_search(prime.begin(), prime.end(), num)) { count++; clear.insert(clear.begin(), num); } } return count; } int main() { int n = 50001; deque<bool> primearray; primearray.resize(n); MakePrimeArray(primearray, n); deque<int> prime; for (int i = 2; i < n; i++) { if (primearray[i]) { prime.push_back(i); } } while (true) { int innum; cin >> innum; // scanf("%d",&innum); if (innum == 0) break; int answer = GoldBach(prime, innum); // printf("%d \n",answer); cout << GoldBach(prime, innum) << endl; } return 0; }
#include <algorithm> #include <deque> #include <iostream> #include <stdio.h> using namespace std; void MakePrimeArray(deque<bool> &A, int n) { A[0] = A[1] = false; for (int i = 2; i < n; i++) { A[i] = true; } for (int i = 2; i * i < n; i++) { if (A[i]) { for (int j = i * i; j < n; j += i) { A[j] = false; } } } } inline int GoldBach(const deque<int> &prime, int n) { int count = 0; deque<int> clear; bool ok = true; for (int i = 0; prime[i] < n; i++) { if (std::binary_search(clear.begin(), clear.end(), prime[i])) { break; } int num = n - prime[i]; if (std::binary_search(prime.begin(), prime.end(), num)) { count++; clear.insert(clear.begin(), num); } } return count; } int main() { int n = 50001; deque<bool> primearray; primearray.resize(n); MakePrimeArray(primearray, n); deque<int> prime; for (int i = 2; i < n; i++) { if (primearray[i]) { prime.push_back(i); } } while (true) { int innum; cin >> innum; // scanf("%d",&innum); if (innum == 0) break; int answer = GoldBach(prime, innum); // printf("%d \n",answer); cout << answer << endl; } return 0; }
replace
72
73
72
73
TLE
p00056
C++
Time Limit Exceeded
#include <iostream> #define STA 50000 using namespace std; int prime[50001]; int main() { int n; int cnt; for (int i = 2; i <= STA / 2; i++) { for (int j = 2; i * j <= STA; j++) { prime[i * j] = 1; } } while (1) { cnt = 0; cin >> n; if (n == 0) break; for (int i = 2; i <= n / 2; i++) { if (prime[i] == 0) { for (int j = i; j <= n; j++) { if (i + j == n && prime[j] == 0) cnt++; } } } cout << cnt << endl; } }
#include <iostream> #define STA 50000 using namespace std; int prime[50001]; int main() { int n; int cnt; for (int i = 2; i <= STA / 2; i++) { for (int j = 2; i * j <= STA; j++) { prime[i * j] = 1; } } while (1) { cnt = 0; cin >> n; if (n == 0) break; for (int i = 2; i <= n / 2; i++) { if (prime[i] == 0 && prime[n - i] == 0) cnt++; } cout << cnt << endl; } }
replace
20
26
20
22
TLE
p00056
C++
Runtime Error
#include <cstdio> #include <cstring> #define N 50 using namespace std; int main(void) { int p[N + 1] = {0}; int n, ans; for (int i = 2; i < N; i++) { if (p[i] == -1) continue; p[i] = 1; for (int j = i * 2; j < N; j += i) { p[j] = -1; } } while (scanf("%d", &n), n) { ans = 0; for (int i = 2; i <= n / 2; i++) { if (p[i] == 1 && p[n - i] == 1) { ans++; } } printf("%d\n", ans); } return 0; }
#include <cstdio> #include <cstring> #define N 50000 using namespace std; int main(void) { int p[N + 1] = {0}; int n, ans; for (int i = 2; i < N; i++) { if (p[i] == -1) continue; p[i] = 1; for (int j = i * 2; j < N; j += i) { p[j] = -1; } } while (scanf("%d", &n), n) { ans = 0; for (int i = 2; i <= n / 2; i++) { if (p[i] == 1 && p[n - i] == 1) { ans++; } } printf("%d\n", ans); } return 0; }
replace
3
4
3
4
0
p00056
C++
Time Limit Exceeded
#include <iostream> #define MAX 50000 using namespace std; bool is_prime[MAX]; void tenes(void) { for (int i = 0; i < MAX; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (is_prime[i]) { for (int j = i + i; j < MAX; j += i) { is_prime[j] = false; } } } } int main(void) { tenes(); int n; while (cin >> n) { if (n == 0) break; int cnt = 0; int N; for (int i = 2; i < MAX / 2; i++) { if (is_prime[i]) { if (n - i > 0) { N = n - i; if (is_prime[N] && N >= n / 2) { cout << N << endl; cnt++; } } } } cout << cnt << endl; } return 0; }
#include <iostream> #define MAX 50000 using namespace std; bool is_prime[MAX]; void tenes(void) { for (int i = 0; i < MAX; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (is_prime[i]) { for (int j = i + i; j < MAX; j += i) { is_prime[j] = false; } } } } int main(void) { tenes(); int n; while (cin >> n) { if (n == 0) break; int cnt = 0; for (int i = 2; i <= n / 2; i++) { if (is_prime[i] && is_prime[n - i]) { cnt++; } } cout << cnt << endl; } return 0; }
replace
33
43
33
36
TLE
p00056
C++
Time Limit Exceeded
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { bool p[50001]; memset(p, 1, sizeof(p)); p[0] = p[1] = 0; for (int i = 0; i < 50001; i++) { if (p[i]) { for (int j = 2 * i; j < 50001; j += i) { p[j] = 0; } } } int n, sum; while (cin >> n, n) { int cnt = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (p[i] == 1 && p[j] == 1) { sum = i + j; if (sum == n) cnt++; } } } cout << cnt << endl; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { bool p[50001]; memset(p, 1, sizeof(p)); p[0] = p[1] = 0; for (int i = 0; i < 50001; i++) { if (p[i]) { for (int j = 2 * i; j < 50001; j += i) { p[j] = 0; } } } int n, sum; while (cin >> n, n) { int cnt = 0; for (int i = 0; i <= n / 2; i++) { if (p[i] == 1 && p[n - i] == 1) cnt++; } cout << cnt << endl; } return 0; }
replace
19
27
19
22
TLE
p00056
C++
Runtime Error
#include <bitset> #include <stdio.h> int main() { const int N = 5001; int i, j, n, c; std::bitset<N> p(3); p.flip(); for (i = 2; i * i < N; ++i) if (p[i]) for (j = i * 2; j < N; j += i) p[j] = 0; while (scanf("%d", &n), n) { for (c = i = 0, j = n; i <= j; ++i, --j) if (p[i] && p[j]) ++c; printf("%d\n", c); } return 0; }
#include <bitset> #include <stdio.h> int main() { const int N = 50001; int i, j, n, c; std::bitset<N> p(3); p.flip(); for (i = 2; i * i < N; ++i) if (p[i]) for (j = i * 2; j < N; j += i) p[j] = 0; while (scanf("%d", &n), n) { for (c = i = 0, j = n; i <= j; ++i, --j) if (p[i] && p[j]) ++c; printf("%d\n", c); } return 0; }
replace
3
4
3
4
0
p00056
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; const int MAX = 1000100; bool prime[MAX]; void sieve() { fill(prime, prime + MAX, true); prime[0] = prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (!prime[i]) continue; for (int j = i * i; j < MAX; j += i) prime[j] = false; } } int main() { sieve(); int n; while (cin >> n, n) { int ret = 0; for (int i = 0; i < n; i++) for (int j = i; j < n; j++) if (prime[i] && prime[j] && i + j == n) ret++; cout << ret << endl; } }
#include <iostream> #include <string> using namespace std; const int MAX = 1000100; bool prime[MAX]; void sieve() { fill(prime, prime + MAX, true); prime[0] = prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (!prime[i]) continue; for (int j = i * i; j < MAX; j += i) prime[j] = false; } } int main() { sieve(); int n; while (cin >> n, n) { int ret = 0; for (int i = 0; i <= n / 2; i++) if (prime[i] && prime[n - i]) { ret++; } cout << ret << endl; } }
replace
25
29
25
29
TLE
p00056
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MAX = 1000100; bool prime[MAX]; void sieve() { fill(prime, prime + MAX, true); prime[0] = prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (!prime[i]) continue; for (int j = i * i; j < MAX; j += i) prime[j] = false; } } int main() { sieve(); int n; while (cin >> n, n) { int ret = 0; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) if (prime[i] && prime[j] && i + j == n) ret++; } cout << ret << endl; } }
#include <bits/stdc++.h> using namespace std; const int MAX = 1000100; bool prime[MAX]; void sieve() { fill(prime, prime + MAX, true); prime[0] = prime[1] = false; for (int i = 2; i * i < MAX; i++) { if (!prime[i]) continue; for (int j = i * i; j < MAX; j += i) prime[j] = false; } } int main() { sieve(); int n; while (cin >> n, n) { int ret = 0; for (int i = 0; i <= n / 2; i++) { if (prime[i] && prime[n - i]) ret++; } cout << ret << endl; } }
replace
24
28
24
27
TLE
p00056
C++
Time Limit Exceeded
#include <iostream> using namespace std; const int max_lim = 50001; bool prime[max_lim]; void init() { for (int i = 0; i < max_lim; i++) prime[i] = true; prime[0] = prime[1] = false; for (int i = 2; i * i < max_lim; i++) for (int j = 2 * i; j < max_lim; j += i) prime[j] = false; } int main() { int n; init(); while (cin >> n, n) { int ans = 0; for (int i = 2; i <= n; i++) for (int j = i; j <= n; j++) if (i + j == n && prime[i] && prime[j]) ans++; cout << ans << endl; } return 0; }
#include <iostream> using namespace std; const int max_lim = 50001; bool prime[max_lim]; void init() { for (int i = 0; i < max_lim; i++) prime[i] = true; prime[0] = prime[1] = false; for (int i = 2; i * i < max_lim; i++) for (int j = 2 * i; j < max_lim; j += i) prime[j] = false; } int main() { int n; init(); while (cin >> n, n) { int ans = 0; for (int i = 2; 2 * i <= n; i++) if (n - i > 0 && prime[i] && prime[n - i]) ans++; cout << ans << endl; } return 0; }
replace
23
27
23
26
TLE
p00056
C++
Time Limit Exceeded
#include <algorithm> #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++) #define MAX 1000000 #define pb push_back using namespace std; int prime[MAX]; int main() { prime[0] = prime[1] = 0; REP(i, 2, MAX) { prime[i] = 1; } REP(i, 2, MAX) { if (prime[i]) { for (int j = i * 2; j < MAX; j += i) { prime[j] = 0; } } } int n; while (cin >> n && n) { int count = 0; vector<int> a; rep(i, n) { rep(j, n) { if (prime[i] == 1 && prime[j] == 1 && i + j == n) { if (a.empty()) { a.pb(i); a.pb(j); count++; } else { vector<int>::iterator ite = find(a.begin(), a.end(), i); vector<int>::iterator ite2 = find(a.begin(), a.end(), j); if (ite == a.end() && ite == a.end()) { a.pb(i); a.pb(j); count++; } } } } } cout << count << endl; } return 0; }
#include <algorithm> #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++) #define MAX 1000000 #define pb push_back using namespace std; int prime[MAX]; int main() { prime[0] = prime[1] = 0; REP(i, 2, MAX) { prime[i] = 1; } REP(i, 2, MAX) { if (prime[i]) { for (int j = i * 2; j < MAX; j += i) { prime[j] = 0; } } } int n; while (cin >> n && n) { int count = 0; rep(i, (n / 2) + 1) { if (prime[i] == 1 && prime[n - i] == 1) { count++; } } cout << count << endl; } return 0; }
replace
30
49
30
33
TLE
p00056
C++
Runtime Error
#include <iostream> using namespace std; #define MAX 50004 #define MAXL 3000 int dp[MAX], d[MAX]; int main() { int n, m = 0; static bool c[MAX] = {true, true}; for (int i = 2; m < MAXL; i++) { if (!c[i]) { for (int j = 2; i * j < MAX; j++) c[i * j] = true; d[m++] = i; } } for (int i = 0; i < MAXL; i++) for (int j = i; d[i] + d[j] < MAX - 3; j++) dp[d[i] + d[j]]++; while (cin >> n, n) cout << dp[n] << endl; return 0; }
#include <iostream> using namespace std; #define MAX 50004 #define MAXL 3000 int dp[MAX], d[MAX]; int main() { int n, m = 0; static bool c[MAX] = {true, true}; for (int i = 2; i < MAX; i++) { if (!c[i]) { for (int j = 2; i * j < MAX; j++) c[i * j] = true; d[m++] = i; } } for (int i = 0; i < MAXL; i++) for (int j = i; d[i] + d[j] < MAX - 3; j++) dp[d[i] + d[j]]++; while (cin >> n, n) cout << dp[n] << endl; return 0; }
replace
9
10
9
10
-11
p00057
C++
Time Limit Exceeded
#include <iostream> #include <stdio.h> using namespace std; int keisan(int a) { if (a == 1) { return 2; } else { return a + keisan(a - 1); } } int main() { int n; while (1) { cin >> n; cout << keisan(n) << endl; } return 0; }
#include <iostream> #include <stdio.h> using namespace std; int keisan(int a) { if (a == 1) { return 2; } else { return a + keisan(a - 1); } } int main() { int n; while (cin >> n) { cout << keisan(n) << endl; } return 0; }
replace
15
17
15
16
TLE
p00057
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main(void) { while (1) { int n; cin >> n; if (n == 0) break; cout << 1 + n * (n + 1) / 2 << endl; } }
#include <iostream> using namespace std; int main(void) { while (1) { int n; if (!(cin >> n)) break; cout << 1 + n * (n + 1) / 2 << endl; } }
replace
7
9
7
8
TLE
p00057
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { vector<ll> vec; vec[0] = 1; for (int i = 1; i <= 10000; i++) { vec[i] = vec[i - 1] + i; } int n; while (cin >> n) { cout << vec[n] << endl; } return 0; } // int main(){ // int n; // while(cin >> n){ // cout << n*(n-1)/2 +1 << endl; // } // return 0; // }
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { vector<ll> vec(10001); vec[0] = 1; for (int i = 1; i <= 10000; i++) { vec[i] = vec[i - 1] + i; } int n; while (cin >> n) { cout << vec[n] << endl; } return 0; } // int main(){ // int n; // while(cin >> n){ // cout << n*(n-1)/2 +1 << endl; // } // return 0; // }
replace
8
9
8
9
-11
p00057
C++
Time Limit Exceeded
#include <iostream> int heimen(int nn) { int a; a = ((nn * nn) + nn + 2) / 2; return a; } using namespace std; int main() { int n, ans; while (cin >> n, n) { ans = heimen(n); cout << ans << endl; } }
#include <iostream> int heimen(int nn) { int a; a = ((nn * nn) + nn + 2) / 2; return a; } using namespace std; int main() { int n, ans; while (cin >> n) { ans = heimen(n); cout << ans << endl; } }
replace
11
12
11
12
TLE
p00058
C++
Runtime Error
#include <cstdio> int main() { float xA, yA, xB, yB, xC, yC, xD, yD; while (scanf("%f%f%f%f%f%f%f%f", xA, yA, xB, yB, xC, yC, xD, yD) != EOF) { if ((xA == xB && yC == yD) || (yA == yB && xC == xD)) { puts("YES"); continue; } else if (xA == xB || yC == yD || yA == yB || xC == xD) { puts("NO"); continue; } double AB = (yA - yB) / (xA - xB); double CD = (yC - yD) / (xC - xD); if (-1 * AB == CD) { puts("YES"); } else { puts("NO"); } } }
#include <cstdio> int main() { double xA, yA, xB, yB, xC, yC, xD, yD; while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &xA, &yA, &xB, &yB, &xC, &yC, &xD, &yD) != EOF) { if ((xA - xB) * (xC - xD) + (yA - yB) * (yC - yD) == 0) { puts("YES"); } else { puts("NO"); } } }
replace
2
14
2
6
-11
p00058
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int inf = 1e9; int main() { vector<double> x(4); vector<double> y(4); while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) { double ax = x[1] - x[0]; double ay = y[1] - y[0]; double bx = x[3] - x[2]; double by = y[3] - y[2]; cerr << ax * bx + ay * by << endl; if (ax * bx + ay * by < 1e-10) { cout << "YES" << endl; } else cout << "NO" << endl; } return 0; } // EOF
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int inf = 1e9; int main() { vector<double> x(4); vector<double> y(4); while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]) { double ax = x[1] - x[0]; double ay = y[1] - y[0]; double bx = x[3] - x[2]; double by = y[3] - y[2]; if (fabs(ax * bx + ay * by) < 1e-10) { cout << "YES" << endl; } else cout << "NO" << endl; } return 0; } // EOF
replace
25
27
25
26
0
0 6 22.42 0
p00059
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rep(i, n) range(i, 0, n) using namespace std; typedef complex<double> P; int main(void) { P p[4]; while (1) { rep(i, 4) { double x, y; cin >> x >> y; p[i] = {x, y}; } bool ok = true; if (p[1].real() < p[2].real()) ok = false; if (p[3].real() < p[0].real()) ok = false; if (p[1].imag() < p[2].imag()) ok = false; if (p[3].imag() < p[0].imag()) ok = false; if (ok) puts("YES"); else puts("NO"); } return 0; }
#include <bits/stdc++.h> #define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rep(i, n) range(i, 0, n) using namespace std; typedef complex<double> P; int main(void) { P p[4]; while (1) { rep(i, 4) { double x, y; cin >> x >> y; p[i] = {x, y}; } if (cin.eof()) break; bool ok = true; if (p[1].real() < p[2].real()) ok = false; if (p[3].real() < p[0].real()) ok = false; if (p[1].imag() < p[2].imag()) ok = false; if (p[3].imag() < p[0].imag()) ok = false; if (ok) puts("YES"); else puts("NO"); } return 0; }
insert
15
15
15
17
TLE
p00059
C++
Time Limit Exceeded
#include <iostream> using namespace std; typedef struct { double x, y; } _z; int main() { _z p[4]; while (1) { for (int i = 0; i < 4; i++) { cin >> p[i].x >> p[i].y; } if (p[3].x < p[0].x || p[2].x > p[1].x || p[2].y > p[1].y || p[3].y < p[0].y) { cout << "NO" << endl; } else cout << "YES" << endl; } return 0; }
#include <iostream> using namespace std; typedef struct { double x, y; } _z; int main() { _z p[4]; while (cin >> p[0].x >> p[0].y) { for (int i = 1; i < 4; i++) { cin >> p[i].x >> p[i].y; } if (p[3].x < p[0].x || p[2].x > p[1].x || p[2].y > p[1].y || p[3].y < p[0].y) { cout << "NO" << endl; } else cout << "YES" << endl; } return 0; }
replace
12
14
12
14
TLE
p00060
C++
Time Limit Exceeded
#include <stdio.h> int main(void) { char buf; int buf_cnt = 0; int c[3]; int my_cards; int ok = 0; int cnt = 0; double probability; for (int i = 0; i < 3; i++) { c[i] = 0; } while ((buf = getchar()) != EOF) { if (buf >= '0' && buf <= '9') { buf -= '0'; c[buf_cnt] = c[buf_cnt] * 10 + buf; continue; } else if (buf != '\n') { if (c[buf_cnt] != 0) { buf_cnt++; continue; } else if (buf_cnt < 3) { continue; } } else { if (c[2] == 0) { for (int i = 0; i < 3; i++) { c[i] = 0; } continue; } } my_cards = c[0] + c[1]; for (int i = 1; i <= 10; i++) { // c[0],2,c3??¨?¢??????´??????????????? if (i == c[0] || i == c[1] || i == c[2]) { continue; } if (my_cards + i <= 20) { ok++; } cnt++; } probability = (double)ok / (double)cnt; if (probability >= 0.5) { printf("YES\n"); } else { printf("NO\n"); } for (int i = 0; i < 3; i++) { c[i] = 0; } ok = 0; cnt = 0; buf_cnt = 0; rewind(stdin); } return 0; }
#include <stdio.h> int main(void) { char buf; int buf_cnt = 0; int c[3]; int my_cards; int ok = 0; int cnt = 0; double probability; for (int i = 0; i < 3; i++) { c[i] = 0; } while ((buf = getchar()) != EOF) { if (buf >= '0' && buf <= '9') { buf -= '0'; c[buf_cnt] = c[buf_cnt] * 10 + buf; continue; } else if (buf != '\n') { if (c[buf_cnt] != 0) { buf_cnt++; continue; } else if (buf_cnt < 3) { continue; } } else { if (c[2] == 0) { for (int i = 0; i < 3; i++) { c[i] = 0; } continue; } } my_cards = c[0] + c[1]; for (int i = 1; i <= 10; i++) { // c[0],2,c3??¨?¢??????´??????????????? if (i == c[0] || i == c[1] || i == c[2]) { continue; } if (my_cards + i <= 20) { ok++; } cnt++; } probability = (double)ok / (double)cnt; if (probability >= 0.5) { printf("YES\n"); } else { printf("NO\n"); } for (int i = 0; i < 3; i++) { c[i] = 0; } ok = 0; cnt = 0; buf_cnt = 0; } return 0; }
delete
61
62
61
61
TLE
p00061
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <functional> #include <iostream> #include <map> #include <set> using namespace std; int main() { int number, suu, in; // result = 整理番号と正解数の対応 map<int, int> result; // rank = 順位表 need to include <functional> set<int, greater<int>> rank; while (scanf("%d,%d", &number, &suu), number && suu) { result.insert(std::pair<int, int>(number, suu)); rank.insert(suu); } while (cin >> in, !cin.eof()) { // 整理番号が入力されるのでresultで正解数調べてrankを参照する. int place = 0; set<int>::iterator it = rank.begin(); // set<int> rank; のときに // set<int>::reverse_iretator it = rank.rbegin();とする方法もある. int thisSuu = result[in]; // mapは[]使える. 以下は[]じゃなくiterator使う方法. // map<int, int>::iterator it_map = result.find(in); // int thisSuu = (*it_map).second; while (it != rank.end()) { place++; if (thisSuu == *it) { cout << place << endl; break; } it++; } } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <functional> #include <iostream> #include <map> #include <set> using namespace std; int main() { int number, suu, in; // result = 整理番号と正解数の対応 map<int, int> result; // rank = 順位表 need to include <functional> set<int, greater<int>> rank; while (scanf("%d,%d", &number, &suu), number || suu) { result.insert(std::pair<int, int>(number, suu)); rank.insert(suu); } while (cin >> in, !cin.eof()) { // 整理番号が入力されるのでresultで正解数調べてrankを参照する. int place = 0; set<int>::iterator it = rank.begin(); // set<int> rank; のときに // set<int>::reverse_iretator it = rank.rbegin();とする方法もある. int thisSuu = result[in]; // mapは[]使える. 以下は[]じゃなくiterator使う方法. // map<int, int>::iterator it_map = result.find(in); // int thisSuu = (*it_map).second; while (it != rank.end()) { place++; if (thisSuu == *it) { cout << place << endl; break; } it++; } } return 0; }
replace
15
16
15
16
TLE
p00061
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <vector> using namespace std; int main() { map<int, int> M; vector<pair<int, int>> V; int a, b; while (scanf("%d,%d", &a, &b), a && b) { V.push_back(make_pair(b, a)); } sort(V.begin(), V.end()); reverse(V.begin(), V.end()); int buf = 100, cnt = 0; for (int i = 0; i < V.size(); i++) { if (buf > V[i].first) { buf = V[i].first; cnt++; } M[buf] = cnt; } int n; while (cin >> n) { int p; for (int j = 0; j < V.size(); j++) { if (V[j].second == n) { p = j; break; } } cout << M[V[p].first] << endl; } }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <vector> using namespace std; int main() { map<int, int> M; vector<pair<int, int>> V; int a, b; while (scanf("%d,%d", &a, &b), a || b) { V.push_back(make_pair(b, a)); } sort(V.begin(), V.end()); reverse(V.begin(), V.end()); int buf = 100, cnt = 0; for (int i = 0; i < V.size(); i++) { if (buf > V[i].first) { buf = V[i].first; cnt++; } M[buf] = cnt; } int n; while (cin >> n) { int p; for (int j = 0; j < V.size(); j++) { if (V[j].second == n) { p = j; break; } } cout << M[V[p].first] << endl; } }
replace
10
11
10
11
0
p00061
C++
Time Limit Exceeded
#include <iostream> using namespace std; int a, b, x[1000], y[1000], p, sum, ok; char c; int main() { while (cin >> a >> c >> b) { if (a + b == 0) { break; } x[a] = b; p++; } sum = 1; for (int i = 30; i >= 0; i++) { ok = 0; for (int j = 1; j <= p; j++) { if (x[j] == i) { y[j] = sum; ok = 1; } } if (ok) { sum++; } } while (cin >> a) { cout << y[a] << endl; } }
#include <iostream> using namespace std; int a, b, x[1000], y[1000], p, sum, ok; char c; int main() { while (cin >> a >> c >> b) { if (a + b == 0) { break; } x[a] = b; p++; } sum = 1; for (int i = 30; i >= 0; i--) { ok = 0; for (int j = 1; j <= p; j++) { if (x[j] == i) { y[j] = sum; ok = 1; } } if (ok) { sum++; } } while (cin >> a) { cout << y[a] << endl; } }
replace
13
14
13
14
TLE
p00061
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> a[1000]; int c = 0, t[1000]; char cc; while (1) { scanf("%d,%d", &a[c].second, &a[c].first); c++; if (a[c - 1].first == 0 && a[c - 1].second == 0) goto L; } L: c--; stable_sort(a, a + c); int r = 1; t[a[c - 1].second] = 1; for (int i = c - 2; i >= 0; i--) { if (a[i + 1].first != a[i].first) { t[a[i].second] = (++r); } else { t[a[i].second] = r; } } while (cin >> c, c) cout << t[c] << endl; }
#include <bits/stdc++.h> using namespace std; int main() { pair<int, int> a[1000]; int c = 0, t[1000]; char cc; while (1) { scanf("%d,%d", &a[c].second, &a[c].first); c++; if (a[c - 1].first == 0 && a[c - 1].second == 0) goto L; } L: c--; stable_sort(a, a + c); int r = 1; t[a[c - 1].second] = 1; for (int i = c - 2; i >= 0; i--) { if (a[i + 1].first != a[i].first) { t[a[i].second] = (++r); } else { t[a[i].second] = r; } } while (cin >> c) cout << t[c] << endl; }
replace
24
25
24
25
TLE
p00061
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int id, num; map<int, int> m; vector<int> v; while (1) { scanf("%d,%d", &id, &num); if (id | num) ; else break; m[id] = num; v.push_back(-num); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); while (scanf("%d", &id)) { cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int id, num; map<int, int> m; vector<int> v; while (1) { scanf("%d,%d", &id, &num); if (id | num) ; else break; m[id] = num; v.push_back(-num); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); while (scanf("%d", &id) != EOF) { cout << lower_bound(v.begin(), v.end(), -m[id]) - v.begin() + 1 << endl; } return 0; }
replace
22
23
22
23
TLE
p00061
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <map> #include <vector> typedef std::pair<int, int> Entrant; bool descending_Entrant(const Entrant &e1, const Entrant &e2) { return e1.second > e2.second; } int main() { int num, points; std::vector<Entrant> v; std::map<int, int> m; while (scanf("%d,%d", &num, &points), num && points) { v.push_back(Entrant(num, points)); } std::sort(v.begin(), v.end(), descending_Entrant); int rank = 1; for (int i = 0; i < v.size(); i++) { m[v[i].first] = rank; if (i + 1 < v.size() && v[i].second != v[i + 1].second) rank++; } int n; while (~scanf("%d", &n)) { printf("%d\n", m[n]); } }
#include <algorithm> #include <cstdio> #include <map> #include <vector> typedef std::pair<int, int> Entrant; bool descending_Entrant(const Entrant &e1, const Entrant &e2) { return e1.second > e2.second; } int main() { int num, points; std::vector<Entrant> v; std::map<int, int> m; while (scanf("%d,%d", &num, &points), num) { v.push_back(Entrant(num, points)); } std::sort(v.begin(), v.end(), descending_Entrant); int rank = 1; for (int i = 0; i < v.size(); i++) { m[v[i].first] = rank; if (i + 1 < v.size() && v[i].second != v[i + 1].second) rank++; } int n; while (~scanf("%d", &n)) { printf("%d\n", m[n]); } }
replace
15
16
15
16
TLE
p00062
C++
Runtime Error
#include <stdio.h> int hoge(int x[]) { for (int j = 9; j >= 0; j++) { for (int i = 0; i < j; i++) { x[i] = (x[i] + x[i + 1]) % 10; } } return x[0]; } int main() { char a[15]; while (~scanf("%s", a)) { int c[10]; for (int i = 0; i < 10; i++) { c[i] = a[i] - '0'; } c[0] = hoge(c); printf("%d\n", c[0]); } return 0; }
#include <stdio.h> int hoge(int x[]) { for (int j = 9; j > 0; j--) { for (int i = 0; i < j; i++) { x[i] = (x[i] + x[i + 1]) % 10; } } return x[0]; } int main() { char a[15]; while (~scanf("%s", a)) { int c[10]; for (int i = 0; i < 10; i++) { c[i] = a[i] - '0'; } c[0] = hoge(c); printf("%d\n", c[0]); } return 0; }
replace
4
5
4
5
-11
p00062
C++
Runtime Error
#include <cstdio> int main() { char top[10]; while (scanf("%s", top) != EOF) { int nums[10]; for (int i = 0; i < 10; i++) nums[i] = top[i] - '0'; int res = nums[0] + nums[1] * 9 + nums[2] * 36 + nums[3] * 84 + nums[4] * 126 + nums[5] * 126 + nums[6] * 84 + nums[7] * 36 + nums[8] * 9 + nums[9]; res %= 10; printf("%d\n", res); } }
#include <iostream> using namespace std; int main(void) { char tmp[10]; char buf; while (cin >> buf) { tmp[0] = buf - '0'; for (int i = 1; i < 10; i++) { cin >> buf; tmp[i] = buf - '0'; } for (int i = 8; i >= 0; i--) { for (int j = 0; j <= i; j++) { tmp[j] = (tmp[j] + tmp[j + 1]) % 10; } } cout << (int)tmp[0] << endl; } }
replace
0
12
0
17
0
p00062
C++
Runtime Error
#include <stdio.h> int main() { char b[10]; while (~scanf("%s", b)) { int c[10]; for (int i = 0; i < 10; i++) c[i] = b[i] - '0'; for (int i = 9; i > 0; i--) for (int j = 0; j < i; j++) c[j] = (c[j] + c[j + 1]) % 10; printf("%d\n", c[0]); } }
#include <stdio.h> int main() { char b[15]; while (~scanf("%s", b)) { int c[10]; for (int i = 0; i < 10; i++) c[i] = b[i] - '0'; for (int i = 9; i > 0; i--) for (int j = 0; j < i; j++) c[j] = (c[j] + c[j + 1]) % 10; printf("%d\n", c[0]); } }
replace
3
4
3
4
0
p00062
C++
Time Limit Exceeded
#include <stdio.h> int main() { char a[10]; while (scanf("%s", a) != 0) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9 - i; j++) { a[j] = a[j] + a[j + 1] - '0'; if (a[j] - '0' > 9) a[j] -= 10; } } printf("%c\n", a[0]); } }
#include <stdio.h> int main() { char a[10]; while (scanf("%s", a) != EOF) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9 - i; j++) { a[j] = a[j] + a[j + 1] - '0'; if (a[j] - '0' > 9) a[j] -= 10; } } printf("%c\n", a[0]); } }
replace
3
4
3
4
TLE
p00062
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; int main(void) { char num1[10]; int num[10]; int ans[10]; int a, b; while (cin >> num1) { for (a = 0; a < 10; a++) { num[a] = num1[a] - '0'; } for (a = 0; a < 10; a++) { for (b = 0; b < 9 - a; b++) { ans[b] = (num[b] + num[b + 1]) % 10; } for (b = 0; b < 9 - a; b++) { num[b] = ans[b]; } } printf("%d\n", ans[0]); } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <typeinfo> #include <utility> #include <vector> using namespace std; int main(void) { string num1; int num[10]; int ans[10]; int a, b; while (cin >> num1) { for (a = 0; a < 10; a++) { num[a] = num1[a] - '0'; } for (a = 0; a < 10; a++) { for (b = 0; b < 9 - a; b++) { ans[b] = (num[b] + num[b + 1]) % 10; } for (b = 0; b < 9 - a; b++) { num[b] = ans[b]; } } printf("%d\n", ans[0]); } return 0; }
replace
29
30
29
30
0
p00062
C++
Runtime Error
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { char input[10]; int field[9][9]; while (scanf("%s", input) != EOF) { memset(field, 0, sizeof(field)); for (int i = 0; i < 9; i++) { field[0][i] = (input[i] - '0' + input[i + 1] - '0') % 10; } for (int i = 1; i < 9; i++) { for (int j = 0; j <= 8 - i; j++) { if (j < 0) break; field[i][j] = (field[i - 1][j] + field[i - 1][j + 1]) % 10; } } /*for(int i = 0 ; i < 9 ; i++) { for(int j = 0 ; j <= 8-i ; j++) { cout << field[i][j] << ' '; } cout << endl; } cout << endl;*/ cout << field[8][0] << endl; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { char input[20]; int field[20][20]; while (scanf("%s", input) != EOF) { memset(field, 0, sizeof(field)); for (int i = 0; i < 9; i++) { field[0][i] = (input[i] - '0' + input[i + 1] - '0') % 10; } for (int i = 1; i < 9; i++) { for (int j = 0; j <= 8 - i; j++) { if (j < 0) break; field[i][j] = (field[i - 1][j] + field[i - 1][j + 1]) % 10; } } /*for(int i = 0 ; i < 9 ; i++) { for(int j = 0 ; j <= 8-i ; j++) { cout << field[i][j] << ' '; } cout << endl; } cout << endl;*/ cout << field[8][0] << endl; } return 0; }
replace
5
7
5
7
0
p00063
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int main() { char str[51]; int count = 0; while (cin >> str) { int len = strlen(str); bool isPal = true; for (int i = 0; i < len / 2; i++) { if (str[i] != str[len - i - 1]) { isPal = false; break; } } if (isPal) count++; } cout << count << endl; return 0; }
#include <cstring> #include <iostream> using namespace std; int main() { char str[101]; int count = 0; while (cin >> str) { int len = strlen(str); bool isPal = true; for (int i = 0; i < len / 2; i++) { if (str[i] != str[len - i - 1]) { isPal = false; break; } } if (isPal) count++; } cout << count << endl; return 0; }
replace
6
7
6
7
0
p00063
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; int main() { string str, inv; int cnt = 0; while (cin >> str, str.length()) { inv.resize(str.length()); for (int i = 0; i < str.length(); i++) { inv[i] = str[str.length() - 1 - i]; } if (str == inv) { cnt++; } } cout << cnt << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string str, inv; int cnt = 0; while (getline(cin, str), str.length() != 0) { inv.resize(str.length()); for (int i = 0; i < str.length(); i++) { inv[i] = str[str.length() - 1 - i]; } if (str == inv) { cnt++; } } cout << cnt << endl; return 0; }
replace
7
8
7
8
TLE
p00063
C++
Runtime Error
#include <stdio.h> #include <string.h> int main(void) { char str[100]; int cnt = 0; while (scanf("%s", str) != EOF) { int i, j; for (i = 0, j = strlen(str) - 1; i <= j; i++, j--) { if (str[i] != str[j]) break; } if (i > j) cnt++; } printf("%d\n", cnt); return 0; }
#include <stdio.h> #include <string.h> int main(void) { char str[200]; int cnt = 0; while (scanf("%s", str) != EOF) { int i, j; for (i = 0, j = strlen(str) - 1; i <= j; i++, j--) { if (str[i] != str[j]) break; } if (i > j) cnt++; } printf("%d\n", cnt); return 0; }
replace
4
5
4
5
0
p00063
C++
Runtime Error
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char ss[100]; int i, c; c = 0; while (0 <= scanf("%s", ss)) { for (i = 0; i <= strlen(ss) - 1; i++) { if (ss[i] != ss[strlen(ss) - i - 1]) break; } if (i == strlen(ss)) ++c; } printf("%d\n", c); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char ss[110]; int i, c; c = 0; while (0 <= scanf("%s", ss)) { for (i = 0; i <= strlen(ss) - 1; i++) { if (ss[i] != ss[strlen(ss) - i - 1]) break; } if (i == strlen(ss)) ++c; } printf("%d\n", c); return 0; }
replace
5
6
5
6
0
p00064
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, a) REP(i, 0, a) #define REP(i, a, b) for (int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> P; typedef std::pair<P, int> PP; struct edge { int to, time, cost; }; const double eps = 1e-9; const int infi = (int)1e+9 + 10; const ll infll = (ll)1e+17 + 10; const double infd = (double)1e+9; int sum = 0; std::string str; std::string::iterator it; int number() { int ret = 0; while (isdigit(*it)) { ret *= 10; ret += (*it - '0'); ++it; } return ret; } int main() { while (std::cin >> str) { it = str.begin(); while (it != str.end()) { if (isdigit(*it)) sum += number(); ++it; } } std::cout << sum << std::endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, a) REP(i, 0, a) #define REP(i, a, b) for (int i = a; i < b; ++i) typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> P; typedef std::pair<P, int> PP; struct edge { int to, time, cost; }; const double eps = 1e-9; const int infi = (int)1e+9 + 10; const ll infll = (ll)1e+17 + 10; const double infd = (double)1e+9; int sum = 0; std::string str; std::string::iterator it; int number() { int ret = 0; while (isdigit(*it)) { ret *= 10; ret += (*it - '0'); ++it; } return ret; } int main() { while (std::cin >> str) { str += "."; it = str.begin(); while (it != str.end()) { if (isdigit(*it)) sum += number(); ++it; } } std::cout << sum << std::endl; return 0; }
insert
45
45
45
46
0
p00064
C++
Runtime Error
#include <cctype> #include <iostream> using namespace std; string sentence; typedef string::const_iterator State; int parse(State &it) { int ret = 0; while (isdigit(*it)) { ret = ret * 10; ret = ret + *it - '0'; it++; } return ret; } int main(void) { int sum = 0; while (cin >> sentence) { for (State it = sentence.begin(); it != sentence.end(); it++) { if (isdigit(*it)) { sum += parse(it); } } } cout << sum << endl; return 0; }
#include <cctype> #include <iostream> using namespace std; string sentence; typedef string::const_iterator State; int parse(State &it) { int ret = 0; while (isdigit(*it)) { ret = ret * 10; ret = ret + *it - '0'; it++; } return ret; } int main(void) { int sum = 0; while (cin >> sentence) { for (State it = sentence.begin(); it != sentence.end(); it++) { if (isdigit(*it)) { sum += parse(it); it--; } } } cout << sum << endl; return 0; }
insert
23
23
23
24
0
p00064
C++
Time Limit Exceeded
#include <cstdio> using namespace std; int main() { int n; int ans = 0; while (scanf("%[0-9]", &n) != EOF) { ans += n; } printf("%d\n", ans); return (0); }
#include <cstdio> using namespace std; int main() { int n; int ans = 0; while (~scanf("%*[^0-9]%d", &n)) { ans += n; } printf("%d\n", ans); return (0); }
replace
7
8
7
8
TLE
p00064
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using db = double; using ll = long long; using vi = vector<int>; #define op operator #define pb push_back int main() { cout << fixed << setprecision(9); ios ::sync_with_stdio(0); int ans = 0; for (string s; getline(cin, s);) { s += ' '; string t = ""; for (char c : s) if (isdigit(c)) t += c; else { ans += stoi(t); t = ""; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using db = double; using ll = long long; using vi = vector<int>; #define op operator #define pb push_back int main() { cout << fixed << setprecision(9); ios ::sync_with_stdio(0); int ans = 0; for (string s; getline(cin, s);) { s += ' '; string t = ""; for (char c : s) if (isdigit(c)) t += c; else if (t.size()) { ans += stoi(t); t = ""; } } cout << ans << '\n'; return 0; }
replace
20
21
20
21
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoi
p00064
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <iostream> // #include<algorithm> // #include<cmath> // #include<string> // #include<cctype> // #include <vector> using namespace std; int main() { int s, a = 0; while (scanf("%*[^0-9]%d", &s) != 0) a += s; cout << a << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <iostream> // #include<algorithm> // #include<cmath> // #include<string> // #include<cctype> // #include <vector> using namespace std; int main() { int s, a = 0; while (~scanf("%*[^0-9]%d", &s)) a += s; cout << a << endl; return 0; }
replace
10
11
10
11
TLE
p00064
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, sum = 0; char c; while ((c = getchar())) { if (c >= '0' && c <= '9') { n *= 10; n += (c - ('0')); } else { sum += n; n = 0; } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, sum = 0; char c; while ((c = getchar()) != EOF) { if (c >= '0' && c <= '9') { n *= 10; n += (c - ('0')); } else { sum += n; n = 0; } } cout << sum << endl; }
replace
5
6
5
6
TLE
p00065
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, l, n) for (int i = l; i < n; i++) #define rer(i, l, n) for (int i = l; i <= n; i++) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define pb(a) push_back(a) #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pii; vector<string> split(const string &s, char c) { vector<string> ret; stringstream ss(s); string t; while (getline(ss, t, c)) { ret.pb(t); } return ret; } int main() { map<int, int> m; set<int> s1, s2; bool f = 0; string s; while (getline(cin, s)) { if (s.end() - s.begin() == 1) { // o("ok"); f = 1; continue; } vector<string> v = split(s, ','); int a = atoi(v[0].c_str()); // o(a); m[a]++; if (!f) s1.insert(a); else s2.insert(a); } for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) { // cout<<1<<endl; if (s1.count(it->fi) && s2.count(it->fi)) cout << it->fi << " " << it->se << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, l, n) for (int i = l; i < n; i++) #define rer(i, l, n) for (int i = l; i <= n; i++) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define pb(a) push_back(a) #define fi first #define se second using namespace std; typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pii; vector<string> split(const string &s, char c) { vector<string> ret; stringstream ss(s); string t; while (getline(ss, t, c)) { ret.pb(t); } return ret; } int main() { map<int, int> m; set<int> s1, s2; bool f = 0; string s; while (getline(cin, s)) { if (/*s.end() - s.begin() == 1*/ s == "") { // o("ok"); f = 1; continue; } vector<string> v = split(s, ','); int a = atoi(v[0].c_str()); // o(a); m[a]++; if (!f) s1.insert(a); else s2.insert(a); } for (map<int, int>::iterator it = m.begin(); it != m.end(); it++) { // cout<<1<<endl; if (s1.count(it->fi) && s2.count(it->fi)) cout << it->fi << " " << it->se << endl; } }
replace
42
43
42
43
-11
p00065
C++
Runtime Error
#include <iostream> #include <string> using namespace std; string S; int x[100000][2]; int c = 0; int main() { while (getline(cin, S)) { if (S.size() == 0) { c++; } string T[2]; int ok = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == ',') { ok++; } else { T[ok] += S[i]; } } x[stoi(T[0])][c]++; } for (int i = 0; i < 99999; i++) { if (x[i][0] >= 1 && x[i][1] >= 1) { cout << i << ' ' << x[i][0] + x[i][1] << endl; } } return 0; }
#include <iostream> #include <string> using namespace std; string S; int x[100000][2]; int c = 0; int main() { while (getline(cin, S)) { if (S.size() == 0) { c++; continue; } string T[2]; int ok = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == ',') { ok++; } else { T[ok] += S[i]; } } x[stoi(T[0])][c]++; } for (int i = 0; i < 99999; i++) { if (x[i][0] >= 1 && x[i][1] >= 1) { cout << i << ' ' << x[i][0] + x[i][1] << endl; } } return 0; }
insert
10
10
10
11
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoi
p00066
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { string s; while (true) { cin >> s; for (int i = 0; i < 3; ++i) { if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] && s[2 + 3 * i] == 'o') { cout << "o" << endl; goto end; } if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] && s[2 + 3 * i] == 'x') { cout << "x" << endl; goto end; } } for (int i = 0; i < 3; ++i) { if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'o') { cout << "o" << endl; goto end; } if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'x') { cout << "x" << endl; goto end; } } for (int i = 0; i < 2; ++i) { if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'o') { cout << "o" << endl; goto end; } if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'x') { cout << "x" << endl; goto end; } } cout << "d" << endl; end:; if (s[9] == EOF) break; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { string s; while (true) { cin >> s; if (cin.fail()) break; for (int i = 0; i < 3; ++i) { if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] && s[2 + 3 * i] == 'o') { cout << "o" << endl; goto end; } if (s[0 + 3 * i] == s[1 + 3 * i] && s[1 + 3 * i] == s[2 + 3 * i] && s[2 + 3 * i] == 'x') { cout << "x" << endl; goto end; } } for (int i = 0; i < 3; ++i) { if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'o') { cout << "o" << endl; goto end; } if (s[0 + i] == s[3 + i] && s[3 + i] == s[6 + i] && s[6 + i] == 'x') { cout << "x" << endl; goto end; } } for (int i = 0; i < 2; ++i) { if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'o') { cout << "o" << endl; goto end; } if (s[0 + 2 * i] == s[4] && s[4] == s[8 - 2 * i] && s[4] == 'x') { cout << "x" << endl; goto end; } } cout << "d" << endl; end:; if (s[9] == EOF) break; } return 0; }
replace
7
8
7
9
TLE
p00066
C++
Time Limit Exceeded
#include <iostream> using namespace std; char table[3][3]; int main(void) { while (true) { for (int y = 0; y < 3; y++) for (int x = 0; x < 3; x++) cin >> table[x][y]; int judge = 0; for (int y = 0; y < 3; y++) { if (table[0][y] == table[1][y] && table[1][y] == table[2][y] && table[2][y] == 'o') judge = 1; if (table[0][y] == table[1][y] && table[1][y] == table[2][y] && table[2][y] == 'x') judge = 2; } for (int x = 0; x < 3; x++) { if (table[x][0] == table[x][1] && table[x][1] == table[x][2] && table[x][2] == 'o') judge = 1; if (table[x][0] == table[x][1] && table[x][1] == table[x][2] && table[x][2] == 'x') judge = 2; } if (table[0][0] == table[1][1] && table[1][1] == table[2][2] && table[2][2] == 'o') judge = 1; if (table[0][0] == table[1][1] && table[1][1] == table[2][2] && table[2][2] == 'x') judge = 2; if (table[0][2] == table[1][1] && table[1][1] == table[2][0] && table[2][0] == 'o') judge = 1; if (table[0][2] == table[1][1] && table[1][1] == table[2][0] && table[2][0] == 'x') judge = 2; if (judge == 1) cout << 'o' << endl; else if (judge == 2) cout << 'x' << endl; else cout << 'd' << endl; } return 0; }
#include <iostream> using namespace std; char table[3][3]; int main(void) { while (true) { for (int y = 0; y < 3; y++) for (int x = 0; x < 3; x++) cin >> table[x][y]; if (cin.eof()) break; int judge = 0; for (int y = 0; y < 3; y++) { if (table[0][y] == table[1][y] && table[1][y] == table[2][y] && table[2][y] == 'o') judge = 1; if (table[0][y] == table[1][y] && table[1][y] == table[2][y] && table[2][y] == 'x') judge = 2; } for (int x = 0; x < 3; x++) { if (table[x][0] == table[x][1] && table[x][1] == table[x][2] && table[x][2] == 'o') judge = 1; if (table[x][0] == table[x][1] && table[x][1] == table[x][2] && table[x][2] == 'x') judge = 2; } if (table[0][0] == table[1][1] && table[1][1] == table[2][2] && table[2][2] == 'o') judge = 1; if (table[0][0] == table[1][1] && table[1][1] == table[2][2] && table[2][2] == 'x') judge = 2; if (table[0][2] == table[1][1] && table[1][1] == table[2][0] && table[2][0] == 'o') judge = 1; if (table[0][2] == table[1][1] && table[1][1] == table[2][0] && table[2][0] == 'x') judge = 2; if (judge == 1) cout << 'o' << endl; else if (judge == 2) cout << 'x' << endl; else cout << 'd' << endl; } return 0; }
insert
11
11
11
13
TLE
p00066
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { while (1) { string s; cin >> s; char a[3][3]; a[0][0] = s[0]; a[0][1] = s[1]; a[0][2] = s[2]; a[1][0] = s[3]; a[1][1] = s[4]; a[1][2] = s[5]; a[2][0] = s[6]; a[2][1] = s[7]; a[2][2] = s[8]; char S = 's'; bool ok = false; for (int i = 0; i < 3; i++) { if (a[i][0] != S && a[i][0] == a[i][1] && a[i][1] == a[i][2]) { cout << a[i][0] << endl; ok = true; break; } } for (int j = 0; j < 3; j++) { if (ok) break; if (a[0][j] != S && a[0][j] == a[1][j] && a[1][j] == a[2][j]) { cout << a[0][j] << endl; ok = true; break; } } if (!ok) { if (a[0][0] != S && a[0][0] == a[1][1] && a[1][1] == a[2][2]) { cout << a[0][0] << endl; ok = true; } else if (a[0][2] != S && a[0][2] == a[1][1] && a[1][1] == a[2][0]) { cout << a[1][1] << endl; ok = true; } } if (!ok) cout << "d" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { char a[3][3]; a[0][0] = s[0]; a[0][1] = s[1]; a[0][2] = s[2]; a[1][0] = s[3]; a[1][1] = s[4]; a[1][2] = s[5]; a[2][0] = s[6]; a[2][1] = s[7]; a[2][2] = s[8]; char S = 's'; bool ok = false; for (int i = 0; i < 3; i++) { if (a[i][0] != S && a[i][0] == a[i][1] && a[i][1] == a[i][2]) { cout << a[i][0] << endl; ok = true; break; } } for (int j = 0; j < 3; j++) { if (ok) break; if (a[0][j] != S && a[0][j] == a[1][j] && a[1][j] == a[2][j]) { cout << a[0][j] << endl; ok = true; break; } } if (!ok) { if (a[0][0] != S && a[0][0] == a[1][1] && a[1][1] == a[2][2]) { cout << a[0][0] << endl; ok = true; } else if (a[0][2] != S && a[0][2] == a[1][1] && a[1][1] == a[2][0]) { cout << a[1][1] << endl; ok = true; } } if (!ok) cout << "d" << endl; } return 0; }
replace
5
8
5
8
TLE
p00067
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; char a[12][12]; void irand(int i, int j) { a[i][j] == '0'; if (i > 0 && a[i - 1][j] == '1') irand(i - 1, j); if (j > 0 && a[i][j - 1] == '1') irand(i, j - 1); if (i < 11 && a[i + 1][j] == '1') irand(i + 1, j); if (j < 11 && a[i][j + 1] == '1') irand(i, j + 1); return; } int main() { while (scanf("%s", a[0]) != EOF) { int cnt = 0; for (int i = 1; i < 12; i++) scanf("%s", a[i]); for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (a[i][j] == '1') { cnt++; irand(i, j); } } } printf("%d\n", cnt); } }
#include <cstdio> #include <iostream> using namespace std; char a[12][12]; void irand(int i, int j) { a[i][j] = '0'; if (i > 0 && a[i - 1][j] == '1') irand(i - 1, j); if (j > 0 && a[i][j - 1] == '1') irand(i, j - 1); if (i < 11 && a[i + 1][j] == '1') irand(i + 1, j); if (j < 11 && a[i][j + 1] == '1') irand(i, j + 1); return; } int main() { while (scanf("%s", a[0]) != EOF) { int cnt = 0; for (int i = 1; i < 12; i++) scanf("%s", a[i]); for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (a[i][j] == '1') { cnt++; irand(i, j); } } } printf("%d\n", cnt); } }
replace
5
6
5
6
-11
p00067
C++
Time Limit Exceeded
#include <iostream> using namespace std; char nyuryoku[12][12]; void fun(int y, int x, char masume) { if ((x < 0) || (12 <= x) || (y < 0) || (12 <= y)) { return; } if (masume != nyuryoku[y][x]) return; else nyuryoku[y][x] = '+'; fun(y + 1, x, masume); fun(y - 1, x, masume); fun(y, x + 1, masume); fun(y, x - 1, masume); } int main() { while (1) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { cin >> nyuryoku[i][j]; } } int count = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (nyuryoku[i][j] != '+') { if (nyuryoku[i][j] == '1') count++; fun(i, j, nyuryoku[i][j]); } } } cout << count << endl; } }
#include <iostream> using namespace std; char nyuryoku[12][12]; void fun(int y, int x, char masume) { if ((x < 0) || (12 <= x) || (y < 0) || (12 <= y)) { return; } if (masume != nyuryoku[y][x]) return; else nyuryoku[y][x] = '+'; fun(y + 1, x, masume); fun(y - 1, x, masume); fun(y, x + 1, masume); fun(y, x - 1, masume); } int main() { while (cin >> nyuryoku[0][0]) { for (int j = 1; j < 12; j++) cin >> nyuryoku[0][j]; for (int i = 1; i < 12; i++) { for (int j = 0; j < 12; j++) { cin >> nyuryoku[i][j]; } } int count = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (nyuryoku[i][j] != '+') { if (nyuryoku[i][j] == '1') count++; fun(i, j, nyuryoku[i][j]); } } } cout << count << endl; } }
replace
20
22
20
24
TLE
p00067
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; bool isLand[12][12]; bool deleteOneLand(int x, int y) { if (!isLand[y][x]) return false; isLand[y][x] = false; if (x > 0) deleteOneLand(x - 1, y); if (y > 0) deleteOneLand(x, y - 1); if (x < 11) deleteOneLand(x + 1, y); if (y < 11) deleteOneLand(x, y + 1); return true; } int main() { int x, y, ans; while (!cin.eof()) { ans = 0; for (y = 0; y < 12; y++) { for (x = 0; x < 12; x++) isLand[y][x] = getchar() == '1'; getchar(); } for (y = 0; y < 12; y++) for (x = 0; x < 12; x++) if (deleteOneLand(x, y)) ans++; cout << ans << endl; getchar(); } return 0; }
#include <cstdio> #include <iostream> using namespace std; bool isLand[12][12]; bool deleteOneLand(int x, int y) { if (!isLand[y][x]) return false; isLand[y][x] = false; if (x > 0) deleteOneLand(x - 1, y); if (y > 0) deleteOneLand(x, y - 1); if (x < 11) deleteOneLand(x + 1, y); if (y < 11) deleteOneLand(x, y + 1); return true; } int main() { int x, y, ans; while (!cin.eof()) { ans = 0; for (y = 0; y < 12; y++) { for (x = 0; x < 12; x++) isLand[y][x] = getchar() == '1'; getchar(); } for (y = 0; y < 12; y++) for (x = 0; x < 12; x++) if (deleteOneLand(x, y)) ans++; cout << ans << endl; if (getchar() != '\n') break; } return 0; }
replace
35
36
35
37
TLE
p00067
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> #define MAX_L 12 using namespace std; char table[MAX_L][MAX_L]; int fdx[] = {1, 0, -1, 0}, fdy[] = {0, 1, 0, -1}; void dfs(int y, int x) { if (x < 0 || x >= MAX_L || y < 0 || y >= MAX_L || table[y][x] == '0') return; table[y][x]--; for (int r = 0; r < 4; r++) { dfs(y + fdy[r], x + fdx[r]); } return; } int main(void) { while (true) { for (int r = 0; r < MAX_L; r++) { scanf("%s", table[r]); } int cnt = 0; for (int r = 0; r < MAX_L; r++) { for (int c = 0; c < MAX_L; c++) { if (table[r][c] == '1') { dfs(r, c); cnt++; } } } cout << cnt << endl; } return (0); }
#include <cstdio> #include <iostream> #define MAX_L 12 using namespace std; char table[MAX_L][MAX_L]; int fdx[] = {1, 0, -1, 0}, fdy[] = {0, 1, 0, -1}; void dfs(int y, int x) { if (x < 0 || x >= MAX_L || y < 0 || y >= MAX_L || table[y][x] == '0') return; table[y][x]--; for (int r = 0; r < 4; r++) { dfs(y + fdy[r], x + fdx[r]); } return; } int main(void) { while (true) { for (int r = 0; r < MAX_L; r++) { if (scanf("%s", table[r]) == EOF) return (0); } int cnt = 0; for (int r = 0; r < MAX_L; r++) { for (int c = 0; c < MAX_L; c++) { if (table[r][c] == '1') { dfs(r, c); cnt++; } } } cout << cnt << endl; } return (0); }
replace
20
21
20
22
TLE
p00067
C++
Time Limit Exceeded
#include <iostream> using namespace std; int cnt; char field[13][13]; void solve(int x, int y) { field[y][x] = '0'; if (x + 1 < 12) if (field[y][x + 1] == '1') solve(x + 1, y); if (x - 1 >= 0) if (field[y][x - 1] == '1') solve(x - 1, y); if (y + 1 < 12) if (field[y + 1][x] == '1') solve(x, y + 1); if (y - 1 >= 0) if (field[y - 1][x] == '1') solve(x, y - 1); } int main() { while (1) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { cin >> field[i][j]; } } cnt = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (field[i][j] == '1') { cnt++; solve(j, i); } } } cout << cnt << endl; } return 0; }
#include <iostream> using namespace std; int cnt; char field[13][13]; void solve(int x, int y) { field[y][x] = '0'; if (x + 1 < 12) if (field[y][x + 1] == '1') solve(x + 1, y); if (x - 1 >= 0) if (field[y][x - 1] == '1') solve(x - 1, y); if (y + 1 < 12) if (field[y + 1][x] == '1') solve(x, y + 1); if (y - 1 >= 0) if (field[y - 1][x] == '1') solve(x, y - 1); } int main() { while (1) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { cin >> field[i][j]; if (cin.eof()) return 0; } } cnt = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (field[i][j] == '1') { cnt++; solve(j, i); } } } cout << cnt << endl; } return 0; }
insert
27
27
27
29
TLE
p00067
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, init, n) for (int i = init; i < (n); i++) using namespace std; using ll = long long int; using P = pair<int, int>; using T = tuple<int, int, int>; using edge = struct { int to, cost; }; const int MOD = 1e9 + 7; const int iINF = 1e9; const long long int llINF = 1e18; const double PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; vector<string> mp(12); bool visited[12][12]; int bfs(int x, int y) { queue<P> que; que.push(P{x, y}); while (!que.empty()) { P p = que.front(); que.pop(); rep(i, 4) { int nx = p.first + dx[i], ny = p.second + dy[i]; if (nx < 0 || ny < 0 || 12 <= nx || 12 <= ny) continue; if (visited[ny][nx] || mp[ny][nx] == '0') continue; visited[ny][nx] = true; que.push(P{nx, ny}); } } return 1; } int main() { for (;;) { rep(i, 12) cin >> mp[i]; rep(i, 12) rep(j, 12) visited[i][j] = false; int ans = 0; rep(y, 12) rep(x, 12) { if (visited[y][x] || mp[y][x] == '0') continue; ans += bfs(x, y); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, init, n) for (int i = init; i < (n); i++) using namespace std; using ll = long long int; using P = pair<int, int>; using T = tuple<int, int, int>; using edge = struct { int to, cost; }; const int MOD = 1e9 + 7; const int iINF = 1e9; const long long int llINF = 1e18; const double PI = acos(-1.0); const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; vector<string> mp(12); bool visited[12][12]; int bfs(int x, int y) { queue<P> que; que.push(P{x, y}); while (!que.empty()) { P p = que.front(); que.pop(); rep(i, 4) { int nx = p.first + dx[i], ny = p.second + dy[i]; if (nx < 0 || ny < 0 || 12 <= nx || 12 <= ny) continue; if (visited[ny][nx] || mp[ny][nx] == '0') continue; visited[ny][nx] = true; que.push(P{nx, ny}); } } return 1; } int main() { while (cin >> mp[0]) { rep(i, 11) cin >> mp[i + 1]; rep(i, 12) rep(j, 12) visited[i][j] = false; int ans = 0; rep(y, 12) rep(x, 12) { if (visited[y][x] || mp[y][x] == '0') continue; ans += bfs(x, y); } cout << ans << endl; } return 0; }
replace
50
52
50
52
TLE
p00067
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int masu[14][14]; int cont; void saiki(int x, int y) { masu[x][y] = 0; if (masu[x + 1][y] == 1) saiki(x + 1, y); if (masu[x][y + 1] == 1) saiki(x, y + 1); if (masu[x - 1][y] == 1) saiki(x, y - 1); if (masu[x][y - 1] == 1) saiki(x, y - 1); } int main() { while (1) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 14; j++) { masu[i][j] = 0; } } for (int i = 1; i <= 12; i++) { char st[13]; scanf("%s", st); if (st[0] == EOF) { goto A; } for (int j = 0; j < 12; j++) { if (st[j] == '0') { masu[i][j + 1] = 0; } else { masu[i][j + 1] = 1; } } } cont = 0; for (int i = 1; i <= 12; i++) { for (int j = 1; j <= 12; j++) { if (masu[i][j] == 1) { cont++; saiki(i, j); } } } printf("%d\n", cont); } A:; }
#include <algorithm> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; int masu[14][14]; int cont; void saiki(int x, int y) { masu[x][y] = 0; if (masu[x + 1][y] == 1) saiki(x + 1, y); if (masu[x][y + 1] == 1) saiki(x, y + 1); if (masu[x - 1][y] == 1) saiki(x, y - 1); if (masu[x][y - 1] == 1) saiki(x, y - 1); } int main() { while (1) { for (int i = 0; i < 14; i++) { for (int j = 0; j < 14; j++) { masu[i][j] = 0; } } for (int i = 1; i <= 12; i++) { char st[13]; if (scanf("%s", st) == EOF) { goto A; } for (int j = 0; j < 12; j++) { if (st[j] == '0') { masu[i][j + 1] = 0; } else { masu[i][j + 1] = 1; } } } cont = 0; for (int i = 1; i <= 12; i++) { for (int j = 1; j <= 12; j++) { if (masu[i][j] == 1) { cont++; saiki(i, j); } } } printf("%d\n", cont); } A:; }
replace
34
36
34
35
TLE
p00067
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; string str; int xs[] = {0, 1, 0, -1}, ys[] = {1, 0, -1, 0}; bool m[10][10]; void dfs(int x, int y) { for (int i = 0; i < 4; i++) { int tx = x + xs[i], ty = y + ys[i]; if (tx < 0 || tx >= 12 || ty < 0 || ty >= 12) continue; if (m[tx][ty]) { m[tx][ty] = false; dfs(tx, ty); } } } int main() { while (true) { int res = 0; for (int i = 0; i < 12; i++) { if (cin >> str) { for (int j = 0; j < str.size(); j++) { m[i][j] = str[j] == '1'; } } else return 0; } for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (m[i][j]) { res++; dfs(i, j); } } } cout << res << endl; } }
#include <algorithm> #include <iostream> #include <string> using namespace std; string str; int xs[] = {0, 1, 0, -1}, ys[] = {1, 0, -1, 0}; bool m[20][20]; void dfs(int x, int y) { for (int i = 0; i < 4; i++) { int tx = x + xs[i], ty = y + ys[i]; if (tx < 0 || tx >= 12 || ty < 0 || ty >= 12) continue; if (m[tx][ty]) { m[tx][ty] = false; dfs(tx, ty); } } } int main() { while (true) { int res = 0; for (int i = 0; i < 12; i++) { if (cin >> str) { for (int j = 0; j < str.size(); j++) { m[i][j] = str[j] == '1'; } } else return 0; } for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (m[i][j]) { res++; dfs(i, j); } } } cout << res << endl; } }
replace
6
7
6
7
0
p00067
C++
Runtime Error
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; char shima[13][13]; void tansaku(int x, int y) { if (x < 0 || x > 11 || y < 0 || y > 11 || shima[y][x] == '0') return; if (shima[y][x] == '1') { shima[y][x] = '0'; } tansaku(x + 1, y); tansaku(x - 1, y); tansaku(x, y + 1); tansaku(x, y - 1); } int main() { while (cin >> shima[0][0]) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (i != 0 && j != 0) cin >> shima[i][j]; } } int a = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (shima[i][j] == '1') { tansaku(j, i); a++; } } } cout << a << endl; } }
#define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; char shima[13][13]; void tansaku(int x, int y) { if (x < 0 || x > 11 || y < 0 || y > 11 || shima[y][x] == '0') return; if (shima[y][x] == '1') { shima[y][x] = '0'; } tansaku(x + 1, y); tansaku(x - 1, y); tansaku(x, y + 1); tansaku(x, y - 1); } int main() { while (cin >> shima[0][0]) { for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (i == 0 && j == 0) continue; else cin >> shima[i][j]; } } int a = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (shima[i][j] == '1') { tansaku(j, i); a++; } } } cout << a << endl; } }
replace
32
33
32
35
-11
p00067
C++
Time Limit Exceeded
#include "bits/stdc++.h" #include <sstream> #include <string> using namespace std; int data[12][12]; vector<string> s(12); int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; void dfs(int x, int y) { s[y][x] = '0'; for (int i = 0; i < 4; ++i) { int px = x + dx[i]; int py = y + dy[i]; if (px < 0 || px >= 12 || py < 0 || py >= 12) continue; if (s[py][px] == '0') continue; dfs(px, py); } } int main() { while (1) { int ans = 0; for (int i = 0; i < 12; ++i) { cin >> s[i]; if (cin.eof()) break; } for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (s[i][j] == '0') continue; dfs(j, i); ans++; } } cout << ans << endl; } }
#include "bits/stdc++.h" #include <sstream> #include <string> using namespace std; int data[12][12]; vector<string> s(12); int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; void dfs(int x, int y) { s[y][x] = '0'; for (int i = 0; i < 4; ++i) { int px = x + dx[i]; int py = y + dy[i]; if (px < 0 || px >= 12 || py < 0 || py >= 12) continue; if (s[py][px] == '0') continue; dfs(px, py); } } int main() { while (1) { int ans = 0; for (int i = 0; i < 12; ++i) { cin >> s[i]; if (cin.eof()) return 0; } for (int i = 0; i < 12; ++i) { for (int j = 0; j < 12; ++j) { if (s[i][j] == '0') continue; dfs(j, i); ans++; } } cout << ans << endl; } }
replace
29
30
29
30
TLE
p00067
C++
Time Limit Exceeded
//============================================================================ // Name : aoj0067.cpp // Author : afterCmidday // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <string> using namespace std; const int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1}; void dfs(string s[], int y, int x) { s[y][x] = '0'; for (int i = 0; i < 4; i++) { if (0 <= y + dy[i] && y + dy[i] < 12 && 0 <= x + dx[i] && x + dx[i] < 12 && s[y + dy[i]][x + dx[i]] == '1') { dfs(s, y + dy[i], x + dx[i]); } } } int main() { string str[12]; int ans; while (true) { for (int i = 0; i < 12; i++) { getline(cin, str[i]); } ans = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (str[i][j] == '1') { dfs(str, i, j); ans++; } } } cout << ans << endl; getline(cin, str[0]); } return 0; }
//============================================================================ // Name : aoj0067.cpp // Author : afterCmidday // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <string> using namespace std; const int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, 1, 0, -1}; void dfs(string s[], int y, int x) { s[y][x] = '0'; for (int i = 0; i < 4; i++) { if (0 <= y + dy[i] && y + dy[i] < 12 && 0 <= x + dx[i] && x + dx[i] < 12 && s[y + dy[i]][x + dx[i]] == '1') { dfs(s, y + dy[i], x + dx[i]); } } } int main() { string str[12]; int ans; while (!cin.eof()) { for (int i = 0; i < 12; i++) { getline(cin, str[i]); } ans = 0; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { if (str[i][j] == '1') { dfs(str, i, j); ans++; } } } cout << ans << endl; getline(cin, str[0]); } return 0; }
replace
27
28
27
28
TLE
p00068
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define np string::npos #define all(r) (r).begin(), (r).end() #define gsort(st, en) sort((st), (en), greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout << #x << ": " << x << endl #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repc(i, a, b) for (int i = (a); i < (int)(b); ++i) #define repi(it, array) \ for (auto it = array.begin(), end = array.end(); it != end; ++it) #define repa(n, array) for (auto n : (array)) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef map<string, int> dict; constexpr int imax = ((1 << 30) - 1) * 2 + 1; constexpr int inf = 100000000; double eps = 1e-10; template <typename T> void out(vector<T> v) { for (size_t i = 0; i < v.size(); i++) { debug(v[i]); } } template <typename T> string ntos(T i) { ostringstream s; s << i; return s.str(); } template <typename T> T ston(string str, T n) { istringstream sin(str); T num; sin >> num; return num; } double EPS = 1e-10; double add(double a, double b) { if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0; return a + b; } struct P { double x, y; P() {} P(double _x, double _y) : x(_x), y(_y) {} P operator+(P p) { return P(add(x, p.x), add(y, p.y)); } P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); } P operator*(double d) { return P(x * d, y * d); } double dot(P p) { return add(x * p.x, y * p.y); } double det(P p) { return add(x * p.y, -y * p.x); } }; //???????????????????????¨????????? bool on_seg(P p1, P p2, P q) { return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0; } //???????°???? P intersection(P p1, P p2, P q1, P q2) { return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1)); } bool cmp_x(const P &p, const P &q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } int ans = 0; vector<P> convex_hull(P *ps, int n) { sort(ps, ps + n, cmp_x); int k = 0; vector<P> qs(n * 2); rep(i, n) { while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) { k--; } qs[k++] = ps[i]; } for (int i = n - 2, t = k; i >= 0; i--) { while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) { k--; } qs[k++] = ps[i]; } qs.resize(k - 1); cout << n - qs.size() << endl; return qs; } double dist(P p, P q) { return (p - q).dot(p - q); } constexpr int MAX_N = 100000; int N; P ps[MAX_N]; void Solve() { vector<P> qs = convex_hull(ps, N); double res = 0; rep(i, qs.size()) { rep(j, i) { res = max(res, dist(qs[i], qs[j])); } } cout << res << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); double x, y; char c; while (cin >> N) { rep(i, N) { cin >> x >> c >> y; ps[i] = P(x, y); } convex_hull(ps, N); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define np string::npos #define all(r) (r).begin(), (r).end() #define gsort(st, en) sort((st), (en), greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout << #x << ": " << x << endl #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define repc(i, a, b) for (int i = (a); i < (int)(b); ++i) #define repi(it, array) \ for (auto it = array.begin(), end = array.end(); it != end; ++it) #define repa(n, array) for (auto n : (array)) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef map<string, int> dict; constexpr int imax = ((1 << 30) - 1) * 2 + 1; constexpr int inf = 100000000; double eps = 1e-10; template <typename T> void out(vector<T> v) { for (size_t i = 0; i < v.size(); i++) { debug(v[i]); } } template <typename T> string ntos(T i) { ostringstream s; s << i; return s.str(); } template <typename T> T ston(string str, T n) { istringstream sin(str); T num; sin >> num; return num; } double EPS = 1e-10; double add(double a, double b) { if (abs(a + b) < EPS * (abs(a) + abs(b))) return 0; return a + b; } struct P { double x, y; P() {} P(double _x, double _y) : x(_x), y(_y) {} P operator+(P p) { return P(add(x, p.x), add(y, p.y)); } P operator-(P p) { return P(add(x, -p.x), add(y, -p.y)); } P operator*(double d) { return P(x * d, y * d); } double dot(P p) { return add(x * p.x, y * p.y); } double det(P p) { return add(x * p.y, -y * p.x); } }; //???????????????????????¨????????? bool on_seg(P p1, P p2, P q) { return (p1 - q).det(p2 - q) == 0 && (p1 - q).dot(p2 - q) <= 0; } //???????°???? P intersection(P p1, P p2, P q1, P q2) { return p1 + (p2 - p1) * ((q2 - q1).det(q1 - p1) / (q2 - q1).det(p2 - p1)); } bool cmp_x(const P &p, const P &q) { if (p.x != q.x) return p.x < q.x; return p.y < q.y; } int ans = 0; vector<P> convex_hull(P *ps, int n) { sort(ps, ps + n, cmp_x); int k = 0; vector<P> qs(n * 2); rep(i, n) { while (k > 1 && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) { k--; } qs[k++] = ps[i]; } for (int i = n - 2, t = k; i >= 0; i--) { while (k > t && (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <= 0) { k--; } qs[k++] = ps[i]; } qs.resize(k - 1); cout << n - qs.size() << endl; return qs; } double dist(P p, P q) { return (p - q).dot(p - q); } constexpr int MAX_N = 100000; int N; P ps[MAX_N]; void Solve() { vector<P> qs = convex_hull(ps, N); double res = 0; rep(i, qs.size()) { rep(j, i) { res = max(res, dist(qs[i], qs[j])); } } cout << res << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); double x, y; char c; while (cin >> N) { if (N == 0) { break; } rep(i, N) { cin >> x >> c >> y; ps[i] = P(x, y); } convex_hull(ps, N); } return 0; }
insert
133
133
133
136
-6
terminate called after throwing an instance of 'std::length_error' what(): vector::_M_default_append
p00068
C++
Time Limit Exceeded
#include <iostream> using namespace std; struct point { double x; double y; bool operator!=(point &p) { return (x != p.x || y != p.y); } bool operator==(point &p) { return (x == p.x && y == p.y); } }; point getLeftPoint(int n, point *points); double getCrossProduct(const point &a, const point &b, const point &o); point operator-(const point &a, const point &b); istream &operator>>(istream &s, point &p); int main(void) { point points[100]; int n; int ans; while (1) { cin >> n; if (cin.eof()) { break; } for (int i = 0; i < n; i++) { cin >> points[i]; } point leftPoint = getLeftPoint(n, points); point stdPoint = leftPoint; point outsideLeftPoint; int vertexCounter = 0; while (1) { for (int i = 0; i < n; i++) { int flag = 0; if (points[i] != stdPoint) { for (int j = 0; j < n; j++) { if (points[j] != stdPoint) { if (getCrossProduct(points[i], points[j], stdPoint) > 0) { flag = 1; break; } } } if (flag == 0) { outsideLeftPoint = points[i]; break; } } } stdPoint = outsideLeftPoint; vertexCounter++; if (outsideLeftPoint == leftPoint) { break; } } ans = n - vertexCounter; std::cout << ans << endl; } return 0; } point getLeftPoint(int n, point *points) { point leftPoint = points[0]; for (int i = 1; i < n; i++) { if (points[i].x < leftPoint.x) { leftPoint = points[i]; } } return leftPoint; } double getCrossProduct(const point &a, const point &b, const point &o) { point ao = a - o; point bo = b - o; return (ao.x * bo.y) - (ao.y * bo.x); } point operator-(const point &a, const point &b) { point p; p.x = a.x - b.x; p.y = a.y - b.y; return p; } istream &operator>>(istream &s, point &p) { char c; return s >> p.x >> c >> p.y; }
#include <iostream> using namespace std; struct point { double x; double y; bool operator!=(point &p) { return (x != p.x || y != p.y); } bool operator==(point &p) { return (x == p.x && y == p.y); } }; point getLeftPoint(int n, point *points); double getCrossProduct(const point &a, const point &b, const point &o); point operator-(const point &a, const point &b); istream &operator>>(istream &s, point &p); int main(void) { point points[100]; int n; int ans; while (1) { cin >> n; if (n == 0) { break; } for (int i = 0; i < n; i++) { cin >> points[i]; } point leftPoint = getLeftPoint(n, points); point stdPoint = leftPoint; point outsideLeftPoint; int vertexCounter = 0; while (1) { for (int i = 0; i < n; i++) { int flag = 0; if (points[i] != stdPoint) { for (int j = 0; j < n; j++) { if (points[j] != stdPoint) { if (getCrossProduct(points[i], points[j], stdPoint) > 0) { flag = 1; break; } } } if (flag == 0) { outsideLeftPoint = points[i]; break; } } } stdPoint = outsideLeftPoint; vertexCounter++; if (outsideLeftPoint == leftPoint) { break; } } ans = n - vertexCounter; std::cout << ans << endl; } return 0; } point getLeftPoint(int n, point *points) { point leftPoint = points[0]; for (int i = 1; i < n; i++) { if (points[i].x < leftPoint.x) { leftPoint = points[i]; } } return leftPoint; } double getCrossProduct(const point &a, const point &b, const point &o) { point ao = a - o; point bo = b - o; return (ao.x * bo.y) - (ao.y * bo.x); } point operator-(const point &a, const point &b) { point p; p.x = a.x - b.x; p.y = a.y - b.y; return p; } istream &operator>>(istream &s, point &p) { char c; return s >> p.x >> c >> p.y; }
replace
24
25
24
25
TLE
p00068
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; // #define int long long #define DBG 1 #define dump(o) \ if (DBG) { \ cerr << #o << " " << (o) << endl; \ } #define dumpc(o) \ if (DBG) { \ cerr << #o; \ for (auto &e : (o)) \ cerr << " " << e; \ cerr << endl; \ } #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9 + 7); #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) // 0?¬? class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } // Vector????????¢ Point rotate(double rad) { return Point(x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad)); } }; inline ostream &operator<<(ostream &os, const Point &p) { os << p.x << " " << p.y; return os; } inline istream &operator>>(istream &is, Point &p) { double x, y; is >> x >> y; p = Point(x, y); return is; } // 1?¬? using Vector = Point; class Segment { public: Point p1, p2; Segment(Point p1 = Point(), Point p2 = Point(1, 1)) : p1(p1), p2(p2) {} Vector vec() { return p2 - p1; } }; using Line = Segment; // 2?¬? class Circle { public: Point c; // center double r; // radius Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {} }; using Polygon = vector<Point>; //?????? dot product double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } //?????? cross product double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } //????????¢??? radian ??? ??? degree double rad(double deg) { return acos(-1) * deg / 180; } //????§? argument double arg(Vector p) { return atan2(p.y, p.x); } //?\???¢??? polar form Vector polar(double r, double a) { return Point(cos(a) * r, sin(a) * r); } //??´????????? bool is_orthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); } bool is_orthogonal(Point a1, Point a2, Point b1, Point b2) { return is_orthogonal(a1 - a2, b1 - b2); } bool is_orthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //???????????? bool is_parallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); } bool is_parallel(Point a1, Point a2, Point b1, Point b2) { return is_parallel(a1 - a2, b1 - b2); } bool is_parallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //?°???± Point project(Segment s, Point p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / base.norm(); return s.p1 + base * r; } //????°? Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } //??????(p0,p1)????????????p2???????????¢??? enum { ONLINE_FRONT = -2, CLOCKWISE, ON_SEGMENT, COUNTER_CLOCKWISE, ONLINE_BACK }; int ccw(Point p0, Point p1, Point p2) { Vector a = p1 - p0, b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; // p2 p0 p1 if (a.norm() < b.norm()) return ONLINE_FRONT; // p0 p1 p2 return ON_SEGMENT; } //??´?????¨??´?????????????????? bool intersect(Point p1, Point p2, Point p3, Point p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } bool intersect(Segment s1, Segment s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } //(?????????????¶????) // 2??????????????¢ double get_distance(Point a, Point b) { return (a - b).abs(); } //??´?????¨???????????¢ double get_distance_LP(Line l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / (l.p2 - l.p1).abs()); } //????????¨???????????¢ double get_distance_SP(Segment s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return (p - s.p1).abs(); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return (p - s.p2).abs(); return get_distance_LP(s, p); } //????????¨??????????????¢ double get_distance(Segment s1, Segment s2) { if (intersect(s1, s2)) return 0.0; return min(min(get_distance_SP(s1, s2.p1), get_distance_SP(s1, s2.p2)), min(get_distance_SP(s2, s1.p1), get_distance_SP(s2, s1.p2))); } //?????¨??´?????????????????? bool intersect(Circle c, Line l) { return get_distance_LP(l, c.c) <= c.r; } //?????¨?????????????????? ??±?????\????????° int intersect(Circle c1, Circle c2) { double d = get_distance(c1.c, c2.c); if (d > c1.r + c2.r) return 4; if (d == c1.r + c2.r) return 3; if (d + c1.r == c2.r || d + c2.r == c1.r) return 1; if (d + c1.r < c2.r || d + c2.r < c1.r) return 0; return 2; } //????????¨??????????????? Point get_cross_point(Segment s1, Segment s2) { assert(intersect(s1, s2)); Vector base = s2.p2 - s2.p1; double a1 = abs(cross(base, s1.p1 - s2.p1)); // area1 double a2 = abs(cross(base, s1.p2 - s2.p1)); // area2 double t = a1 / (a1 + a2); return s1.p1 + (s1.p2 - s1.p1) * t; } //??´?????¨??´???????????? // Point getCrossPointLL(Line l1, Line l2) {} //?????¨??´???????????? pair<Point, Point> get_cross_points(Circle c, Line l) { assert(intersect(c, l)); Vector pr = project(l, c.c); Vector e = (l.p2 - l.p1) / (l.p2 - l.p1).abs(); double base = sqrt(c.r * c.r - (pr - c.c).norm()); return make_pair(pr + e * base, pr - e * base); } //?????¨???????????? pair<Point, Point> get_cross_points(Circle c1, Circle c2) { int m = intersect(c1, c2); assert(m != 4 && m != 0); double d = (c1.c - c2.c).abs(); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)); } //???????????? enum { OUT = 0, ON, IN }; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; for (int i = 0; i < n; i++) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return ON; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return (x ? IN : OUT); } //????§???¢?????¢??? double area(Polygon g) { double a = 0; for (size_t i = 0; i < g.size(); i++) a += cross(g[i], g[(i + 1) % g.size()]); return a / 2.0; } //?????§????????????????¨?????????? bool is_convex(Polygon g) { for (size_t i = 0; i < g.size(); i++) if (ccw(g[i], g[(i + 1) % g.size()], g[(i + 2) % g.size()]) == CLOCKWISE) return false; return true; } // Graham scan // https://en.wikipedia.org/wiki/Graham_scan Polygon convex_hull(Polygon P) { sort(P.begin(), P.end()); Polygon up; for (Point &p : P) { while (up.size() > 1 && ccw(up[up.size() - 2], up[up.size() - 1], p) > 0) up.pop_back(); up.emplace_back(p); } Polygon down; for (Point &p : P) { while (down.size() > 1 && ccw(down[down.size() - 2], down[down.size() - 1], p) < 0) down.pop_back(); down.emplace_back(p); } down.insert(down.end(), up.begin() + 1, up.end() - 1); //???????¨?????????? return down; } signed main() { for (int n; cin >> n && n;) { Polygon P(n); char c; rep(i, 0, n) cin >> P[i].x >> c >> P[i].y; Polygon CH = convex_hull(P); dumpc(CH); cout << (n - CH.size()) << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; // #define int long long #define DBG 0 #define dump(o) \ if (DBG) { \ cerr << #o << " " << (o) << endl; \ } #define dumpc(o) \ if (DBG) { \ cerr << #o; \ for (auto &e : (o)) \ cerr << " " << e; \ cerr << endl; \ } #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9 + 7); #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) // 0?¬? class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point &p) const { return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS; } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } // Vector????????¢ Point rotate(double rad) { return Point(x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad)); } }; inline ostream &operator<<(ostream &os, const Point &p) { os << p.x << " " << p.y; return os; } inline istream &operator>>(istream &is, Point &p) { double x, y; is >> x >> y; p = Point(x, y); return is; } // 1?¬? using Vector = Point; class Segment { public: Point p1, p2; Segment(Point p1 = Point(), Point p2 = Point(1, 1)) : p1(p1), p2(p2) {} Vector vec() { return p2 - p1; } }; using Line = Segment; // 2?¬? class Circle { public: Point c; // center double r; // radius Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {} }; using Polygon = vector<Point>; //?????? dot product double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; } //?????? cross product double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; } //????????¢??? radian ??? ??? degree double rad(double deg) { return acos(-1) * deg / 180; } //????§? argument double arg(Vector p) { return atan2(p.y, p.x); } //?\???¢??? polar form Vector polar(double r, double a) { return Point(cos(a) * r, sin(a) * r); } //??´????????? bool is_orthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); } bool is_orthogonal(Point a1, Point a2, Point b1, Point b2) { return is_orthogonal(a1 - a2, b1 - b2); } bool is_orthogonal(Segment s1, Segment s2) { return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //???????????? bool is_parallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); } bool is_parallel(Point a1, Point a2, Point b1, Point b2) { return is_parallel(a1 - a2, b1 - b2); } bool is_parallel(Segment s1, Segment s2) { return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0); } //?°???± Point project(Segment s, Point p) { Vector base = s.p2 - s.p1; double r = dot(p - s.p1, base) / base.norm(); return s.p1 + base * r; } //????°? Point reflect(Segment s, Point p) { return p + (project(s, p) - p) * 2.0; } //??????(p0,p1)????????????p2???????????¢??? enum { ONLINE_FRONT = -2, CLOCKWISE, ON_SEGMENT, COUNTER_CLOCKWISE, ONLINE_BACK }; int ccw(Point p0, Point p1, Point p2) { Vector a = p1 - p0, b = p2 - p0; if (cross(a, b) > EPS) return COUNTER_CLOCKWISE; if (cross(a, b) < -EPS) return CLOCKWISE; if (dot(a, b) < -EPS) return ONLINE_BACK; // p2 p0 p1 if (a.norm() < b.norm()) return ONLINE_FRONT; // p0 p1 p2 return ON_SEGMENT; } //??´?????¨??´?????????????????? bool intersect(Point p1, Point p2, Point p3, Point p4) { return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0); } bool intersect(Segment s1, Segment s2) { return intersect(s1.p1, s1.p2, s2.p1, s2.p2); } //(?????????????¶????) // 2??????????????¢ double get_distance(Point a, Point b) { return (a - b).abs(); } //??´?????¨???????????¢ double get_distance_LP(Line l, Point p) { return abs(cross(l.p2 - l.p1, p - l.p1) / (l.p2 - l.p1).abs()); } //????????¨???????????¢ double get_distance_SP(Segment s, Point p) { if (dot(s.p2 - s.p1, p - s.p1) < 0.0) return (p - s.p1).abs(); if (dot(s.p1 - s.p2, p - s.p2) < 0.0) return (p - s.p2).abs(); return get_distance_LP(s, p); } //????????¨??????????????¢ double get_distance(Segment s1, Segment s2) { if (intersect(s1, s2)) return 0.0; return min(min(get_distance_SP(s1, s2.p1), get_distance_SP(s1, s2.p2)), min(get_distance_SP(s2, s1.p1), get_distance_SP(s2, s1.p2))); } //?????¨??´?????????????????? bool intersect(Circle c, Line l) { return get_distance_LP(l, c.c) <= c.r; } //?????¨?????????????????? ??±?????\????????° int intersect(Circle c1, Circle c2) { double d = get_distance(c1.c, c2.c); if (d > c1.r + c2.r) return 4; if (d == c1.r + c2.r) return 3; if (d + c1.r == c2.r || d + c2.r == c1.r) return 1; if (d + c1.r < c2.r || d + c2.r < c1.r) return 0; return 2; } //????????¨??????????????? Point get_cross_point(Segment s1, Segment s2) { assert(intersect(s1, s2)); Vector base = s2.p2 - s2.p1; double a1 = abs(cross(base, s1.p1 - s2.p1)); // area1 double a2 = abs(cross(base, s1.p2 - s2.p1)); // area2 double t = a1 / (a1 + a2); return s1.p1 + (s1.p2 - s1.p1) * t; } //??´?????¨??´???????????? // Point getCrossPointLL(Line l1, Line l2) {} //?????¨??´???????????? pair<Point, Point> get_cross_points(Circle c, Line l) { assert(intersect(c, l)); Vector pr = project(l, c.c); Vector e = (l.p2 - l.p1) / (l.p2 - l.p1).abs(); double base = sqrt(c.r * c.r - (pr - c.c).norm()); return make_pair(pr + e * base, pr - e * base); } //?????¨???????????? pair<Point, Point> get_cross_points(Circle c1, Circle c2) { int m = intersect(c1, c2); assert(m != 4 && m != 0); double d = (c1.c - c2.c).abs(); double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d)); double t = arg(c2.c - c1.c); return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a)); } //???????????? enum { OUT = 0, ON, IN }; int contains(Polygon g, Point p) { int n = g.size(); bool x = false; for (int i = 0; i < n; i++) { Point a = g[i] - p, b = g[(i + 1) % n] - p; if (abs(cross(a, b)) < EPS && dot(a, b) < EPS) return ON; if (a.y > b.y) swap(a, b); if (a.y < EPS && EPS < b.y && cross(a, b) > EPS) x = !x; } return (x ? IN : OUT); } //????§???¢?????¢??? double area(Polygon g) { double a = 0; for (size_t i = 0; i < g.size(); i++) a += cross(g[i], g[(i + 1) % g.size()]); return a / 2.0; } //?????§????????????????¨?????????? bool is_convex(Polygon g) { for (size_t i = 0; i < g.size(); i++) if (ccw(g[i], g[(i + 1) % g.size()], g[(i + 2) % g.size()]) == CLOCKWISE) return false; return true; } // Graham scan // https://en.wikipedia.org/wiki/Graham_scan Polygon convex_hull(Polygon P) { sort(P.begin(), P.end()); Polygon up; for (Point &p : P) { while (up.size() > 1 && ccw(up[up.size() - 2], up[up.size() - 1], p) > 0) up.pop_back(); up.emplace_back(p); } Polygon down; for (Point &p : P) { while (down.size() > 1 && ccw(down[down.size() - 2], down[down.size() - 1], p) < 0) down.pop_back(); down.emplace_back(p); } down.insert(down.end(), up.begin() + 1, up.end() - 1); //???????¨?????????? return down; } signed main() { for (int n; cin >> n && n;) { Polygon P(n); char c; rep(i, 0, n) cin >> P[i].x >> c >> P[i].y; Polygon CH = convex_hull(P); dumpc(CH); cout << (n - CH.size()) << endl; } return 0; }
replace
4
5
4
5
0
CH 0 1 1 0 2 1 1 2 CH -940.2 -877.2 -361.62 -970 667.54 430.49 -859.32 -64.84 -509.94 892.63 551.12 828.21
p00068
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define vci vector<int> #define vcs vector<string> #define pb push_back #define sz size() #define mapii map<int, int> #define mapci map<char, int> #define mapsi map<string, int> #define all(x) x.begin(), x.end() #define minit(a, i) memset(a, i, sizeof(a)); #define for_(i, a, b) for (int i = (int)a; i < (int)b; i++) #define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--) #define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c) #define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) typedef long long ll; typedef double D; const int iINF = 2147483647; const ll lINF = 9223372036854775807; template <class T> inline void dbg(T t) { cout << t << endl; } // define eps double EPS = 1e-10; struct Point2D { double x, y; Point2D(double a = 0, double b = 0) : x(a), y(b) {} }; typedef Point2D Vector2D; // Point2D's and Vector2D's operator Point2D operator+(Point2D a, Point2D b) { return Point2D(a.x + b.x, a.y + b.y); } Point2D operator-(Point2D a, Point2D b) { return Point2D(a.x - b.x, a.y - b.y); } Point2D operator*(Point2D a, double d) { return Point2D(a.x * d, a.y * d); } Point2D operator/(Point2D a, double d) { return Point2D(a.x / d, a.y / d); } bool operator<(const Point2D &a, const Point2D &b) { return a.x != b.x ? a.x < b.x : a.y < b.y; } bool operator>(const Point2D &a, const Point2D &b) { return b.x != a.x ? b.x < a.x : b.y < a.y; } bool operator==(const Point2D &a, const Point2D &b) { return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS; } double norm(Point2D a) { return a.x * a.x + a.y * a.y; } double dot2D(const Vector2D &a, const Vector2D &b) { return a.x * b.x + a.y * b.y; } double cross2D(const Vector2D &a, const Vector2D &b) { return a.x * b.y - a.y * b.x; } // 点の進行方向 a -> b -> c int ccw(Point2D a, Point2D b, Point2D c) { b = b - a; c = c - a; if (cross2D(b, c) > 0) return +1; // counter clockwise if (cross2D(b, c) < 0) return -1; // clockwise if (dot2D(b, c) < 0) return +2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; // } vector<Point2D> convexHull(vector<Point2D> ps) { int n = (int)ps.size(), k = 0; sort(ps.begin(), ps.end()); vector<Point2D> ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; } int main() { int n; while (cin >> n) { vector<Point2D> ps(n); for_(i, 0, n) { D x, y; scanf("%lf,%lf", &x, &y); ps[i].x = x; ps[i].y = y; } vector<Point2D> ch = convexHull(ps); int k = (int)ch.sz; cout << n - k << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define vci vector<int> #define vcs vector<string> #define pb push_back #define sz size() #define mapii map<int, int> #define mapci map<char, int> #define mapsi map<string, int> #define all(x) x.begin(), x.end() #define minit(a, i) memset(a, i, sizeof(a)); #define for_(i, a, b) for (int i = (int)a; i < (int)b; i++) #define for_d(i, a, b) for (int i = (int)a - 1; i >= b; i--) #define for_r(i, a, b, c) for (int i = (int)a; i < (int)b; i += c) #define for_dr(i, a, b, c) for (int i = (int)a - 1; i >= b; i -= c) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) typedef long long ll; typedef double D; const int iINF = 2147483647; const ll lINF = 9223372036854775807; template <class T> inline void dbg(T t) { cout << t << endl; } // define eps double EPS = 1e-10; struct Point2D { double x, y; Point2D(double a = 0, double b = 0) : x(a), y(b) {} }; typedef Point2D Vector2D; // Point2D's and Vector2D's operator Point2D operator+(Point2D a, Point2D b) { return Point2D(a.x + b.x, a.y + b.y); } Point2D operator-(Point2D a, Point2D b) { return Point2D(a.x - b.x, a.y - b.y); } Point2D operator*(Point2D a, double d) { return Point2D(a.x * d, a.y * d); } Point2D operator/(Point2D a, double d) { return Point2D(a.x / d, a.y / d); } bool operator<(const Point2D &a, const Point2D &b) { return a.x != b.x ? a.x < b.x : a.y < b.y; } bool operator>(const Point2D &a, const Point2D &b) { return b.x != a.x ? b.x < a.x : b.y < a.y; } bool operator==(const Point2D &a, const Point2D &b) { return fabs(a.x - b.x) < EPS && fabs(a.y - b.y) < EPS; } double norm(Point2D a) { return a.x * a.x + a.y * a.y; } double dot2D(const Vector2D &a, const Vector2D &b) { return a.x * b.x + a.y * b.y; } double cross2D(const Vector2D &a, const Vector2D &b) { return a.x * b.y - a.y * b.x; } // 点の進行方向 a -> b -> c int ccw(Point2D a, Point2D b, Point2D c) { b = b - a; c = c - a; if (cross2D(b, c) > 0) return +1; // counter clockwise if (cross2D(b, c) < 0) return -1; // clockwise if (dot2D(b, c) < 0) return +2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; // } vector<Point2D> convexHull(vector<Point2D> ps) { int n = (int)ps.size(), k = 0; sort(ps.begin(), ps.end()); vector<Point2D> ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]) // upper-hull while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; } int main() { int n; while (cin >> n) { if (n == 0) break; vector<Point2D> ps(n); for_(i, 0, n) { D x, y; scanf("%lf,%lf", &x, &y); ps[i].x = x; ps[i].y = y; } vector<Point2D> ch = convexHull(ps); int k = (int)ch.sz; cout << n - k << endl; } return 0; }
insert
114
114
114
117
-6
terminate called after throwing an instance of 'std::length_error' what(): vector::_M_default_append
p00069
C++
Runtime Error
#include <cassert> #include <iostream> #include <utility> #include <vector> using namespace std; int n, m, h, d; vector<string> F; bool judge(vector<string> f) { int now = m; for (int i = 0; i < f.size(); i++) { assert(now != 0); if (f[i][now - 1] == '1') { now = now - 1; } else if (f[i][now] == '1') { now = now + 1; } // cout<<F[i]<<" "<<f[i]<<" "<<now<<endl; } return now == h; } pair<int, int> solve() { if (judge(F)) return make_pair(0, 0); for (int i = 0; i < F.size(); i++) { for (int j = 1; j < F.size() - 1; j++) { vector<string> tmp = F; if (tmp[i][j - 1] != '1' && tmp[i][j + 1] != '1') { tmp[i][j] = '1'; if (judge(tmp)) { return make_pair(i + 1, j); } } } } return make_pair(-1, 0); } int main() { while (cin >> n, n != 0) { cin >> m >> h >> d; F.clear(); for (int i = 0; i < d; i++) { string s; cin >> s; s = "*" + s + "*"; F.push_back(s); } pair<int, int> ans = solve(); if (ans.first == 0) { cout << 0 << endl; } else if (ans.first == -1) { cout << 1 << endl; } else { cout << ans.first << " " << ans.second << endl; } } }
#include <cassert> #include <iostream> #include <utility> #include <vector> using namespace std; int n, m, h, d; vector<string> F; bool judge(vector<string> f) { int now = m; for (int i = 0; i < f.size(); i++) { assert(now != 0); if (f[i][now - 1] == '1') { now = now - 1; } else if (f[i][now] == '1') { now = now + 1; } // cout<<F[i]<<" "<<f[i]<<" "<<now<<endl; } return now == h; } pair<int, int> solve() { if (judge(F)) return make_pair(0, 0); for (int i = 0; i < F.size(); i++) { for (int j = 1; j < F[i].size() - 1; j++) { vector<string> tmp = F; if (tmp[i][j - 1] != '1' && tmp[i][j + 1] != '1') { tmp[i][j] = '1'; if (judge(tmp)) { return make_pair(i + 1, j); } } } } return make_pair(-1, 0); } int main() { while (cin >> n, n != 0) { cin >> m >> h >> d; F.clear(); for (int i = 0; i < d; i++) { string s; cin >> s; s = "*" + s + "*"; F.push_back(s); } pair<int, int> ans = solve(); if (ans.first == 0) { cout << 0 << endl; } else if (ans.first == -1) { cout << 1 << endl; } else { cout << ans.first << " " << ans.second << endl; } } }
replace
27
28
27
28
0
p00069
C++
Time Limit Exceeded
#include <stdio.h> bool Simulation(char line[][15], int start, int goal, int m) { int pos = start; for (int i = 0; i < m; i++) { if (line[i][pos] == '1') { pos++; } else if (line[i][pos - 1] == '1') { pos--; } } return (pos == goal); } int main(void) { int n, m; int start; int goal; char line[30][15]; while (1) { scanf("%d", &n); scanf("%d", &start); scanf("%d", &goal); scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%s", line[i] + 1); line[i][0] = '0'; line[i][n] = '0'; } if (Simulation(line, start, goal, m) == true) { puts("0"); continue; } bool flag = false; for (int i = 0; i < m; i++) { for (int j = 1; j < n; j++) { if (line[i][j - 1] == '0' && line[i][j + 1] == '0' && line[i][j] == '0') { line[i][j] = '1'; if (Simulation(line, start, goal, m) == true) { printf("%d %d\n", i + 1, j); flag = true; break; } line[i][j] = '0'; } } if (flag == true) { break; } } if (flag == false) { puts("1"); } } return (0); }
#include <stdio.h> bool Simulation(char line[][15], int start, int goal, int m) { int pos = start; for (int i = 0; i < m; i++) { if (line[i][pos] == '1') { pos++; } else if (line[i][pos - 1] == '1') { pos--; } } return (pos == goal); } int main(void) { int n, m; int start; int goal; char line[30][15]; while (1) { scanf("%d", &n); if (n == 0) { break; } scanf("%d", &start); scanf("%d", &goal); scanf("%d", &m); for (int i = 0; i < m; i++) { scanf("%s", line[i] + 1); line[i][0] = '0'; line[i][n] = '0'; } if (Simulation(line, start, goal, m) == true) { puts("0"); continue; } bool flag = false; for (int i = 0; i < m; i++) { for (int j = 1; j < n; j++) { if (line[i][j - 1] == '0' && line[i][j + 1] == '0' && line[i][j] == '0') { line[i][j] = '1'; if (Simulation(line, start, goal, m) == true) { printf("%d %d\n", i + 1, j); flag = true; break; } line[i][j] = '0'; } } if (flag == true) { break; } } if (flag == false) { puts("1"); } } return (0); }
insert
23
23
23
26
TLE
p00069
C++
Runtime Error
#include <iostream> #include <vector> class level { int num; int size; int to_b(const int &n) { if (n == 0) return 0; else return (to_b(n / 10) << 1) + (n % 10); } public: int test(const int &n) { return (((num << (n + 1)) >> size) & 1) - (((num << n) >> size) & 1); } level(const int &n = 0, const int &d = 0) : size(d) { num = to_b(n); }; }; class Lot { std::vector<level> levels; std::vector<int> down; std::vector<int> up; void solve() { for (auto i = 0; i < down.size() - 1; ++i) { down.at(i + 1) = down.at(i) + levels.at(i).test(down.at(i)); } } void solve_inv() { for (auto i = up.size() - 1; i > 0; --i) { up.at(i - 1) = up.at(i) + levels.at(i - 1).test(up.at(i)); } } public: const int choice; const int hit; Lot(const int &n, const int &m, const int &h, const int &d) : choice(m), hit(h), levels(d), down(d + 1, 0), up(d + 1, 0) { for (auto &l : levels) { int i; std::cin >> i; l = level(i, n); } down.at(0) = m; up.at(d) = h; solve(); solve_inv(); } void show() { if (down.at(0) == up.at(0)) { std::cout << 0 << std::endl; } else { bool flag = true; for (auto i = 0; i < down.size(); ++i) { if ((down.at(i) - up.at(i)) * (down.at(i) - up.at(i)) == 1) { if ((levels.at(i).test(down.at(i)) == 0) && (levels.at(i).test(up.at(i)) == 0)) { std::cout << i + 1 << " " << ((down.at(i) < up.at(i)) ? down.at(i) : up.at(i)) << std::endl; i = down.size(); flag = false; } } } if (flag) { std::cout << 1 << std::endl; } } } void inspect() { std::cout << "down" << std::endl; for (const auto &d : down) { std::cout << d << '\n'; } std::cout << "up" << std::endl; for (const auto &u : up) { std::cout << u << '\n'; } } }; int main() { int n; std::cin >> n; while (n != 0) { int m, h, d; std::cin >> m >> h >> d; Lot lot(n, m, h, d); lot.show(); std::cin >> n; } return 0; }
#include <iostream> #include <vector> class level { int num; int size; int to_b(const int &n) { if (n == 0) return 0; else return (to_b(n / 10) << 1) + (n % 10); } public: int test(const int &n) { return (((num << (n + 1)) >> size) & 1) - (((num << n) >> size) & 1); } level(const int &n = 0, const int &d = 0) : size(d) { num = to_b(n); }; }; class Lot { std::vector<level> levels; std::vector<int> down; std::vector<int> up; void solve() { for (auto i = 0; i < down.size() - 1; ++i) { down.at(i + 1) = down.at(i) + levels.at(i).test(down.at(i)); } } void solve_inv() { for (auto i = up.size() - 1; i > 0; --i) { up.at(i - 1) = up.at(i) + levels.at(i - 1).test(up.at(i)); } } public: const int choice; const int hit; Lot(const int &n, const int &m, const int &h, const int &d) : choice(m), hit(h), levels(d), down(d + 1, 0), up(d + 1, 0) { for (auto &l : levels) { int i; std::cin >> i; l = level(i, n); } down.at(0) = m; up.at(d) = h; solve(); solve_inv(); } void show() { if (down.at(0) == up.at(0)) { std::cout << 0 << std::endl; } else { bool flag = true; for (auto i = 0; i < down.size() - 1; ++i) { if (((down.at(i) - up.at(i)) * (down.at(i) - up.at(i)) == 1) && (down.at(i) == down.at(i + 1)) && (up.at(i) == up.at(i + 1))) { std::cout << i + 1 << " " << ((down.at(i) < up.at(i)) ? down.at(i) : up.at(i)) << std::endl; i = down.size(); flag = false; } } if (flag) { std::cout << 1 << std::endl; } } } void inspect() { std::cout << "down" << std::endl; for (const auto &d : down) { std::cout << d << '\n'; } std::cout << "up" << std::endl; for (const auto &u : up) { std::cout << u << '\n'; } } }; int main() { int n; std::cin >> n; while (n != 0) { int m, h, d; std::cin >> m >> h >> d; Lot lot(n, m, h, d); lot.show(); std::cin >> n; } return 0; }
replace
53
63
53
61
0
p00069
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int N, M, G, D; bool c(vector<string> m) { int y = M - 1; for (int x = 0; x < D + 1; x++) { if (y < N - 1 && m[x][y] == '1') { y++; } else if (0 < y && m[x][y - 1] == '1') { y--; } } if (y == G - 1) return true; else return false; } bool t(string g) { for (int i = 0; i < g.size() - 1; i++) { if (g[i] == '1' && g[i + 1] == '1') return false; } return true; } int main() { while (cin >> N, N) { cin >> M >> G >> D; vector<string> v(D); for (int i = 0; i < D; i++) { cin >> v[i]; } if (c(v)) { cout << 0 << endl; goto escape; } for (int i = 0; i < D; i++) { for (int j = 0; j < N - 1; j++) { if (v[i][j] != '1') { v[i][j] = '1'; if (t(v[i])) { if (c(v)) { cout << i + 1 << " " << j + 1 << endl; goto escape; }; } v[i][j] = '0'; } } } cout << 1 << endl; escape:; } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int N, M, G, D; bool c(vector<string> m) { int y = M - 1; for (int x = 0; x < D; x++) { if (y < N - 1 && m[x][y] == '1') { y++; } else if (0 < y && m[x][y - 1] == '1') { y--; } } if (y == G - 1) return true; else return false; } bool t(string g) { for (int i = 0; i < g.size() - 1; i++) { if (g[i] == '1' && g[i + 1] == '1') return false; } return true; } int main() { while (cin >> N, N) { cin >> M >> G >> D; vector<string> v(D); for (int i = 0; i < D; i++) { cin >> v[i]; } if (c(v)) { cout << 0 << endl; goto escape; } for (int i = 0; i < D; i++) { for (int j = 0; j < N - 1; j++) { if (v[i][j] != '1') { v[i][j] = '1'; if (t(v[i])) { if (c(v)) { cout << i + 1 << " " << j + 1 << endl; goto escape; }; } v[i][j] = '0'; } } } cout << 1 << endl; escape:; } return 0; }
replace
10
11
10
11
-11
p00070
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <unordered_map> #include <vector> using namespace std; bool used[10]; int sum; int dp[11][1000]; void saiki(int c, int d) { // c?????§??§d dp[c][d]++; if (c == 10) { return; } for (int e = 0; e < 10; e++) { if (!used[e]) { used[e] = true; saiki(c + 1, d + (c + 1) * e); used[e] = false; } } } int main() { saiki(0, 0); int a, b; while (cin >> a >> b) { cout << dp[a][b] << endl; } }
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <unordered_map> #include <vector> using namespace std; bool used[10]; int sum; int dp[11][10005]; void saiki(int c, int d) { // c?????§??§d dp[c][d]++; if (c == 10) { return; } for (int e = 0; e < 10; e++) { if (!used[e]) { used[e] = true; saiki(c + 1, d + (c + 1) * e); used[e] = false; } } } int main() { saiki(0, 0); int a, b; while (cin >> a >> b) { cout << dp[a][b] << endl; } }
replace
11
12
11
12
0
p00070
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; int n, s; bool used[10]; ll total[12][1000]; void dfs(int curr, int sum) { if (curr == n) { total[n][sum]++; return; } // end if int res = 0; rep(i, 10) { if (!used[i]) { used[i] = true; dfs(curr + 1, sum + (curr + 1) * i); used[i] = false; } // end if } // end rep } int main() { // cut here before submit // freopen ("testcase.CNS", "r", stdin ); memset(total, 0, sizeof(total)); for (n = 1; n <= 10; n++) { memset(used, 0, sizeof(used)); dfs(0, 0); } // end for while (scanf("%d %d", &n, &s) != EOF) { printf("%d\n", total[n][s]); } // 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; int n, s; bool used[10]; ll total[12][10000]; void dfs(int curr, int sum) { if (curr == n) { total[n][sum]++; return; } // end if int res = 0; rep(i, 10) { if (!used[i]) { used[i] = true; dfs(curr + 1, sum + (curr + 1) * i); used[i] = false; } // end if } // end rep } int main() { // cut here before submit // freopen ("testcase.CNS", "r", stdin ); memset(total, 0, sizeof(total)); for (n = 1; n <= 10; n++) { memset(used, 0, sizeof(used)); dfs(0, 0); } // end for while (scanf("%d %d", &n, &s) != EOF) { printf("%d\n", total[n][s]); } // end loop return 0; }
replace
32
33
32
33
0
p00070
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; //--------------------------------------------------- //???????????????????????????????????? #define int long long #define str string typedef long long ll; typedef long double ld; const ll inf = 999999999999999999; struct P { ll pos, cost; }; bool operator<(P a, P b) { return a.cost < b.cost; } bool operator>(P a, P b) { return a.cost > b.cost; } struct B { ll to, cost; }; ll gcm(ll i, ll j) { //?????§??¬?´???° if (i > j) swap(i, j); if (i == 0) return j; return gcm(j % i, i); } //--------------------------------------------------- //+++++++++++++++++++++++++++++++++++++++++++++++++++ int n, s; int dp[11][331][1024]; signed main() { dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j < 331; j++) { for (int z = 0; z < 1024; z++) { for (int x = 0; x < 10; x++) { if (!(z & (1 << x))) { dp[i + 1][j + x * (i + 1)][z | 1 << x] += dp[i][j][z]; } } } } } while (cin >> n >> s) { if (s > 330) { cout << 0 << endl; continue; } int ans = 0; for (int i = 0; i < 1024; i++) ans += dp[n][s][i]; cout << ans << endl; } // getchar(); getchar(); }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; //--------------------------------------------------- //???????????????????????????????????? #define int long long #define str string typedef long long ll; typedef long double ld; const ll inf = 999999999999999999; struct P { ll pos, cost; }; bool operator<(P a, P b) { return a.cost < b.cost; } bool operator>(P a, P b) { return a.cost > b.cost; } struct B { ll to, cost; }; ll gcm(ll i, ll j) { //?????§??¬?´???° if (i > j) swap(i, j); if (i == 0) return j; return gcm(j % i, i); } //--------------------------------------------------- //+++++++++++++++++++++++++++++++++++++++++++++++++++ int n, s; int dp[11][331][1024]; signed main() { dp[0][0][0] = 1; for (int i = 0; i < 10; i++) for (int j = 0; j < 331; j++) for (int z = 0; z < 1024; z++) if (dp[i][j][z] > 0) for (int x = 0; x < 10; x++) if (!((1 << x) & z)) dp[i + 1][j + x * (i + 1)][z | (1 << x)] += dp[i][j][z]; while (cin >> n >> s) { if (s > 330) { cout << 0 << endl; continue; } int ans = 0; for (int i = 0; i < 1024; i++) ans += dp[n][s][i]; cout << ans << endl; } // getchar(); getchar(); }
replace
43
54
43
50
-11
p00070
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> #define f first #define s second #define mp make_pair #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(c) (c).begin(), (c).end() using namespace std; typedef unsigned int uint; typedef long long ll; int memo[1 << 10][1000]; int ans(int cnt, int f, int s) { if (s < 0) return 0; if (memo[f][s] != -1) return memo[f][s]; if ((cnt == 1) && (s < 10) && ((f & (1 << s)) != 0)) return memo[f][s] = 1; int ret = 0; for (int i = 9; i >= 0; i--) if ((f & (1 << i)) != 0) ret += ans(cnt - 1, f ^ (1 << i), s - i * cnt); return memo[f][s] = ret; } int main() { int n, s; while (cin >> n >> s) { memset(memo, -1, sizeof(memo)); cout << ans(n, (1 << 10) - 1, s) << endl; } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> #define f first #define s second #define mp make_pair #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(c) (c).begin(), (c).end() using namespace std; typedef unsigned int uint; typedef long long ll; int memo[1 << 10][1000]; int ans(int cnt, int f, int s) { if (s < 0) return 0; if (memo[f][s] != -1) return memo[f][s]; if ((cnt == 1) && (s < 10) && ((f & (1 << s)) != 0)) return memo[f][s] = 1; int ret = 0; for (int i = 9; i >= 0; i--) if ((f & (1 << i)) != 0) ret += ans(cnt - 1, f ^ (1 << i), s - i * cnt); return memo[f][s] = ret; } int main() { int n, s; while (cin >> n >> s) { memset(memo, -1, sizeof(memo)); if (s >= 1000 || n > 10) cout << 0 << endl; else cout << ans(n, (1 << 10) - 1, s) << endl; } return 0; }
replace
45
46
45
49
0
p00070
C++
Runtime Error
#include <bits/stdc++.h> #define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rep(i, n) range(i, 0, n) using namespace std; int n, s; int memo[11][1010]; void rec(int index, int sum, int mask) { memo[index][sum]++; if (index == 10) return; rep(i, 10) { if (mask & (1 << i)) continue; int nmask = mask | (1 << i); int nsum = sum + (index + 1) * i; rec(index + 1, nsum, nmask); } } int main(void) { rec(0, 0, 0); while (cin >> n >> s) { if (cin.eof()) break; cout << memo[n][s] << endl; } return 0; }
#include <bits/stdc++.h> #define range(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rep(i, n) range(i, 0, n) using namespace std; int n, s; int memo[11][1010]; void rec(int index, int sum, int mask) { memo[index][sum]++; if (index == 10) return; rep(i, 10) { if (mask & (1 << i)) continue; int nmask = mask | (1 << i); int nsum = sum + (index + 1) * i; rec(index + 1, nsum, nmask); } } int main(void) { rec(0, 0, 0); while (cin >> n >> s) { if (cin.eof()) break; if (s < 1010) cout << memo[n][s] << endl; else cout << 0 << endl; } return 0; }
replace
26
27
26
30
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int dp[11][1 << 10][331]; int ans(int n, int x, int s); int main() { int n, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> m) { if (n > 10 || 330 < m) { cout << "0" << endl; } else { cout << ans(n, 0, m) << endl; } } return 0; } int ans(int n, int x, int s) { int y = 0; if (dp[n][x][s] >= 0) { return dp[n][x][s]; } if (s < 0) { return 0; } if (n == 1 && s < 10) { if (!(x & (1 << s))) { y = 1; } } else { for (int i = 0; i < 10; i++) { if (!(x & (1 << i))) { y += ans(n - 1, x | (1 << i), s - i * n); } } } dp[n][x][s] = y; return y; }
#include <cstring> #include <iostream> using namespace std; int dp[11][1 << 10][331]; int ans(int n, int x, int s); int main() { int n, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> m) { if (n > 10 || 330 < m) { cout << "0" << endl; } else { cout << ans(n, 0, m) << endl; } } return 0; } int ans(int n, int x, int s) { int y = 0; if (dp[n][x][s] >= 0) { return dp[n][x][s]; } if (s < 0) { return 0; } if (n == 1) { if (s < 10 && !(x & (1 << s))) { y = 1; } } else { for (int i = 0; i < 10; i++) { if (!(x & (1 << i))) { y += ans(n - 1, x | (1 << i), s - i * n); } } } dp[n][x][s] = y; return y; }
replace
25
27
25
27
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int dp[11][1 << 10][331]; int ans(int n, int x, int s); int main() { int n, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> m) { if (n > 10 || 330 < m) { cout << "0" << endl; } else { cout << ans(n, 0, m) << endl; } } return 0; } int ans(int n, int x, int s) { int y = 0; if (dp[n][x][s] >= 0) { return dp[n][x][s]; } if (s < 0) { return 0; } if (n == 1 && s < 10) { if (!(x & (1 << s))) { y = 1; } } else { for (int i = 0; i < 10; i++) { if (!(x & (1 << i))) { y += ans(n - 1, x | (1 << i), s - i * n); } } } dp[n][x][s] = y; return y; }
#include <cstring> #include <iostream> using namespace std; int dp[11][1 << 10][331]; int ans(int n, int x, int s); int main() { int n, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> m) { if (n > 10 || 330 < m) { cout << "0" << endl; } else { cout << ans(n, 0, m) << endl; } } return 0; } int ans(int n, int x, int s) { int y = 0; if (dp[n][x][s] >= 0) { return dp[n][x][s]; } if (s < 0) { return 0; } if (n == 1) { if (s < 10) { if (!(x & (1 << s))) { y = 1; } } } else { for (int i = 0; i < 10; i++) { if (!(x & (1 << i))) { y += ans(n - 1, x | (1 << i), s - i * n); } } } dp[n][x][s] = y; return y; }
replace
25
28
25
30
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int dp[11][1 << 10][331]; int ans(int n, int x, int s); int main() { int n, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> m) { if (n > 10 || 330 < m) { cout << "0" << endl; } else { cout << ans(n, 0, m) << endl; } } return 0; } int ans(int n, int x, int s) { int y = 0; if (dp[n][x][s] >= 0) { return dp[n][x][s]; } if (s < 0) { return 0; } if (s < 10) { if (n == 1) { if (!(x & (1 << s))) { y = 1; } } } else { for (int i = 0; i < 10; i++) { if (!(x & (1 << i))) { y += ans(n - 1, x | (1 << i), s - i * n); } } } dp[n][x][s] = y; return y; }
#include <cstring> #include <iostream> using namespace std; int dp[11][1 << 10][331]; int ans(int n, int x, int s); int main() { int n, m; memset(dp, -1, sizeof(dp)); while (cin >> n >> m) { if (n > 10 || 330 < m) { cout << "0" << endl; } else { cout << ans(n, 0, m) << endl; } } return 0; } int ans(int n, int x, int s) { int y = 0; if (dp[n][x][s] >= 0) { return dp[n][x][s]; } if (s < 0) { return 0; } if (n == 1) { if (s < 10) { if (!(x & (1 << s))) { y = 1; } } } else { for (int i = 0; i < 10; i++) { if (!(x & (1 << i))) { y += ans(n - 1, x | (1 << i), s - i * n); } } } dp[n][x][s] = y; return y; }
replace
25
27
25
27
0
p00070
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int number[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; long long int dp[10][10001]; long long int factorial(int x) { long long int ret = 1; for (int i = 1; i <= x; i++) ret *= i; return ret; } int main() { do { int sum = 0; for (int i = 0; i < 10; i++) { sum += number[i] * (i + 1); dp[i][sum]++; } } while (next_permutation(number, number + 10)); int n, s; while (cin >> n >> s, n + s) { cout << dp[n - 1][s] / factorial(10 - n) << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int number[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; long long int dp[10][10001]; long long int factorial(int x) { long long int ret = 1; for (int i = 1; i <= x; i++) ret *= i; return ret; } int main() { do { int sum = 0; for (int i = 0; i < 10; i++) { sum += number[i] * (i + 1); dp[i][sum]++; } } while (next_permutation(number, number + 10)); int n, s; while (cin >> n >> s) { cout << dp[n - 1][s] / factorial(10 - n) << endl; } return 0; }
replace
24
25
24
25
TLE
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; const int N_MAX = 10; const int S_MAX = 330; int results[N_MAX + 1][S_MAX + 1]; bool used[10 + 1]; int i; void permutations(int p, int sum) { if (p == 0) { results[i][sum]++; } else { for (int i = 0; i < 10; i++) { if (used[i]) continue; used[i] = true; permutations(p - 1, sum + i * p); used[i] = false; } } } int main() { for (i = 1; i <= 10; i++) { memset(results, 0, sizeof(0)); permutations(i, 0); } int n, s; while (cin >> n >> s) { cout << results[n][s] << endl; } return 0; }
#include <cstring> #include <iostream> using namespace std; const int N_MAX = 10; const int S_MAX = 330; int results[N_MAX + 1][S_MAX + 1]; bool used[10 + 1]; int i; void permutations(int p, int sum) { if (p == 0) { results[i][sum]++; } else { for (int i = 0; i < 10; i++) { if (used[i]) continue; used[i] = true; permutations(p - 1, sum + i * p); used[i] = false; } } } int main() { for (i = 1; i <= 10; i++) { memset(results, 0, sizeof(0)); permutations(i, 0); } int n, s; while (cin >> n >> s) { if (s > S_MAX) cout << 0 << endl; else cout << results[n][s] << endl; } return 0; }
replace
30
31
30
34
0
p00070
C++
Runtime Error
// 23 #include <iostream> #include <map> using namespace std; int m[11][1000]; void calc(int p, int d, int u) { if (d <= 10) { for (int i = 0; i <= 9; i++) { if (!(u & 1 << i)) { int cs = p + i * d; m[d][cs]++; calc(cs, d + 1, u | 1 << i); } } } } int main() { calc(0, 1, 0); for (int n, s; cin >> n >> s;) { cout << m[n][s] << endl; } return 0; }
// 23 #include <iostream> #include <map> using namespace std; int m[11][1000]; void calc(int p, int d, int u) { if (d <= 10) { for (int i = 0; i <= 9; i++) { if (!(u & 1 << i)) { int cs = p + i * d; m[d][cs]++; calc(cs, d + 1, u | 1 << i); } } } } int main() { calc(0, 1, 0); for (int n, s; cin >> n >> s;) { cout << ((s < 1000) ? m[n][s] : 0) << endl; } return 0; }
replace
23
24
23
24
0
p00070
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define all(c) ((c).begin()), ((c).end()) #define debug(c) cerr << "> " << #c << " = " << (c) << endl; #define iter(c) __typeof((c).begin()) #define present(c, e) ((c).find((e)) != (c).end()) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++) #define mp make_pair #define fst first #define snd second #define pb push_back const double EPS = 1e-10; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef complex<double> P; int go(int n, int s, int used) { if (n == 0) { return s == 0; } if (s < 0) return 0; int res = 0; rep(i, 10) if (!(used & 1 << i)) { res += go(n - 1, s - n * i, used | 1 << i); } return res; } int main() { for (int n, s; cin >> n >> s;) { cout << go(n, s, 0) << endl; } return 0; }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <memory.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define all(c) ((c).begin()), ((c).end()) #define debug(c) cerr << "> " << #c << " = " << (c) << endl; #define iter(c) __typeof((c).begin()) #define present(c, e) ((c).find((e)) != (c).end()) #define cpresent(c, e) (find(all(c), (e)) != (c).end()) #define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++) #define mp make_pair #define fst first #define snd second #define pb push_back const double EPS = 1e-10; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef complex<double> P; int go(int n, int s, int used) { if (n == 0) { return s == 0; } if (s < 0) return 0; if (s - 9 * n * n > 0) return 0; int res = 0; rep(i, 10) if (!(used & 1 << i)) { res += go(n - 1, s - n * i, used | 1 << i); } return res; } int main() { for (int n, s; cin >> n >> s;) { cout << go(n, s, 0) << endl; } return 0; }
insert
47
47
47
49
TLE
p00070
C++
Runtime Error
// AOJ 0070 #include <algorithm> #include <iostream> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) typedef long long int integer; const integer NMAX = 11, SMAX = 1000; integer dp[NMAX][SMAX], factorial[NMAX]; void solve() { factorial[0] = 1; for (int i = 1; i <= 10; i++) { factorial[i] = i * factorial[i - 1]; } int nums[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; do { integer sum = 0; REP(i, 10) { sum += nums[i] * (i + 1); dp[i + 1][sum]++; } } while (next_permutation(nums, nums + 10)); } int main() { solve(); int n, s; while (cin >> n >> s) { cout << dp[n][s] / factorial[10 - n] << endl; } }
// AOJ 0070 #include <algorithm> #include <iostream> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) typedef long long int integer; const integer NMAX = 20, SMAX = 1000; integer dp[NMAX][SMAX], factorial[NMAX]; void solve() { factorial[0] = 1; for (int i = 1; i <= 10; i++) { factorial[i] = i * factorial[i - 1]; } int nums[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; do { integer sum = 0; REP(i, 10) { sum += nums[i] * (i + 1); dp[i + 1][sum]++; } } while (next_permutation(nums, nums + 10)); } int main() { solve(); int n, s; while (cin >> n >> s) { cout << dp[n][s] / factorial[10 - n] << endl; } }
replace
7
8
7
8
0
p00070
C++
Runtime Error
#include <iostream> using namespace std; int bit_one(int b) { int r = 0; while (b) { r += b % 2; b >>= 1; } return r; } int dp[400][1 << 10]; void set() { for (int i = 0; i < 300; i++) { for (int j = 0; j < (1 << 10); j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 0; i < 300; i++) { for (int j = 0; j < (1 << 10); j++) { for (int k = 0; k < 10; k++) { if (dp[i][j] && (j >> k) % 2 == 0) { dp[i + k * (bit_one(j) + 1)][j | (1 << k)] += dp[i][j]; } } } } } int main() { set(); int n, s; while (cin >> n >> s) { int ans = 0; for (int i = 0; i < (1 << 10); i++) { if (bit_one(i) == n) { ans += dp[s][i]; } } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int bit_one(int b) { int r = 0; while (b) { r += b % 2; b >>= 1; } return r; } int dp[400][1 << 10]; void set() { for (int i = 0; i < 300; i++) { for (int j = 0; j < (1 << 10); j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int i = 0; i < 300; i++) { for (int j = 0; j < (1 << 10); j++) { for (int k = 0; k < 10; k++) { if (dp[i][j] && (j >> k) % 2 == 0) { dp[i + k * (bit_one(j) + 1)][j | (1 << k)] += dp[i][j]; } } } } } int main() { set(); int n, s; while (cin >> n >> s) { if (s >= 400) { cout << 0 << endl; continue; } int ans = 0; for (int i = 0; i < (1 << 10); i++) { if (bit_one(i) == n) { ans += dp[s][i]; } } cout << ans << endl; } return 0; }
insert
36
36
36
40
0
p00070
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin(a), end(a) #define MS(m, v) memset(m, v, sizeof(m)) #define D10 fixed << setprecision(5) typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> P; typedef complex<double> Point; typedef long long ll; const int INF = 114514810; const int MOD = 1000000007; const double EPS = 1e-8; const double PI = acos(-1.0); struct edge { int from, to, cost; bool operator<(const edge &e) const { return cost < e.cost; } bool operator>(const edge &e) const { return cost > e.cost; } }; ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// int n, s; int memo[100][1000][1 << 10]; int solve(int i, int j, int v) { if (memo[i][j][v] >= 0) return memo[i][j][v]; if (i == n) { if (j == s) return 1; else return 0; } int res = 0; REP(k, 10) { if ((v >> k) & 1) continue; if (j + k * (i + 1) > s) break; res += solve(i + 1, j + (i + 1) * k, v | (1 << k)); } return memo[i][j][v] = res; } int main() { while (cin >> n >> s) { MS(memo, -1); cout << solve(0, 0, 0) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin(a), end(a) #define MS(m, v) memset(m, v, sizeof(m)) #define D10 fixed << setprecision(5) typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> P; typedef complex<double> Point; typedef long long ll; const int INF = 114514810; const int MOD = 1000000007; const double EPS = 1e-8; const double PI = acos(-1.0); struct edge { int from, to, cost; bool operator<(const edge &e) const { return cost < e.cost; } bool operator>(const edge &e) const { return cost > e.cost; } }; ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// int n, s; int memo[11][800][1 << 10]; int solve(int i, int j, int v) { if (memo[i][j][v] >= 0) return memo[i][j][v]; if (i == n) { if (j == s) return 1; else return 0; } int res = 0; REP(k, 10) { if ((v >> k) & 1) continue; if (j + k * (i + 1) > s) break; res += solve(i + 1, j + (i + 1) * k, v | (1 << k)); } return memo[i][j][v] = res; } int main() { while (cin >> n >> s) { MS(memo, -1); cout << solve(0, 0, 0) << endl; } return 0; }
replace
26
27
26
27
MLE
p00070
C++
Memory Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin(a), end(a) #define MS(m, v) memset(m, v, sizeof(m)) #define D10 fixed << setprecision(5) typedef vector<int> vi; typedef vector<string> vs; typedef pair<short, short> P; typedef complex<double> Point; typedef long long ll; const int INF = 114514810; const int MOD = 100000007; const double EPS = 1e-10; const double PI = acos(-1.0); struct edge { int from, to, cost; bool operator<(const edge &e) const { return cost < e.cost; } bool operator>(const edge &e) const { return cost > e.cost; } }; ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// int n, s; int dp[20][1000][1100]; int solve(int i, int sum, int used) { if (dp[i][sum][used] >= 0) return dp[i][sum][used]; if (i == n + 1 && sum == s) return 1; if (i > n || sum > s) return 0; int res = 0; REP(j, 10) { if (((used >> j) & 1) == 0 && sum + i * j <= s) { res += solve(i + 1, sum + i * j, used | (1 << j)); } } return dp[i][sum][used] = res; } int main() { while (cin >> n >> s) { MS(dp, -1); cout << solve(1, 0, 0) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(a) begin(a), end(a) #define MS(m, v) memset(m, v, sizeof(m)) #define D10 fixed << setprecision(5) typedef vector<int> vi; typedef vector<string> vs; typedef pair<short, short> P; typedef complex<double> Point; typedef long long ll; const int INF = 114514810; const int MOD = 100000007; const double EPS = 1e-10; const double PI = acos(-1.0); struct edge { int from, to, cost; bool operator<(const edge &e) const { return cost < e.cost; } bool operator>(const edge &e) const { return cost > e.cost; } }; ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// int n, s; int dp[20][500][1100]; int solve(int i, int sum, int used) { if (dp[i][sum][used] >= 0) return dp[i][sum][used]; if (i == n + 1 && sum == s) return 1; if (i > n || sum > s) return 0; int res = 0; REP(j, 10) { if (((used >> j) & 1) == 0 && sum + i * j <= s) { res += solve(i + 1, sum + i * j, used | (1 << j)); } } return dp[i][sum][used] = res; } int main() { while (cin >> n >> s) { MS(dp, -1); cout << solve(1, 0, 0) << endl; } return 0; }
replace
26
27
26
27
MLE
p00070
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #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; int n, s, memo[1024][500]; int search(int stat, int sum, int dep) { if (dep == n) return memo[stat][sum] = (s == sum); // if(~memo[stat][sum]) return memo[stat][sum]; if (sum > s) return 0; int cnt = 0; for (int i = 0; i < 10; i++) { if ((stat & (1 << i)) == 0) { stat |= 1 << i; cnt += search(stat, sum + i * (n - dep), dep + 1); stat &= ~(1 << i); } } return memo[stat][sum] = cnt; } int main() { while (cin >> n >> s) { if (n == 0 || s >= 1000) { puts("0"); continue; } memset(memo, -1, sizeof(memo)); cout << search(0, 0, 0) << endl; } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #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; int n, s, memo[1024][500]; int search(int stat, int sum, int dep) { if (dep == n) return memo[stat][sum] = (s == sum); if (~memo[stat][sum]) return memo[stat][sum]; if (sum > s) return 0; int cnt = 0; for (int i = 0; i < 10; i++) { if ((stat & (1 << i)) == 0) { stat |= 1 << i; cnt += search(stat, sum + i * (n - dep), dep + 1); stat &= ~(1 << i); } } return memo[stat][sum] = cnt; } int main() { while (cin >> n >> s) { if (n == 0 || s >= 1000) { puts("0"); continue; } memset(memo, -1, sizeof(memo)); cout << search(0, 0, 0) << endl; } return 0; }
replace
33
34
33
35
TLE
p00070
C++
Runtime Error
#include <iostream> #define INF 99999999 using namespace std; int n, s, cnt; int dp[(1 << 10) + 1][1000][11]; int rec(int S, int sum, int cnt) { if (sum < 0 || cnt < 0) return 0; if (dp[S][sum][cnt] != INF) return dp[S][sum][cnt]; if (cnt == 0) { if (sum == 0) return 1; else return 0; } int res = 0, x = 0; for (int i = 0; i < 10; i++) { if ((S >> i) & 1) x++; } for (int i = 0; i < 10; i++) { if ((S >> i) & 1) continue; res += rec(S + (1 << i), sum - (x + 1) * i, cnt - 1); } return dp[S][sum][cnt] = res; } int main() { for (int i = 0; i < (1 << 10) + 1; i++) { for (int j = 0; j < 1000; j++) for (int k = 0; k < 11; k++) dp[i][j][k] = INF; } while (cin >> n >> s) { cout << rec(0, s, n) << endl; } return 0; }
#include <iostream> #define INF 99999999 using namespace std; int n, s, cnt; int dp[(1 << 10) + 1][1000][11]; int rec(int S, int sum, int cnt) { if (sum < 0 || sum > 1000 || cnt < 0 || cnt > 10) return 0; if (dp[S][sum][cnt] != INF) return dp[S][sum][cnt]; if (cnt == 0) { if (sum == 0) return 1; else return 0; } int res = 0, x = 0; for (int i = 0; i < 10; i++) { if ((S >> i) & 1) x++; } for (int i = 0; i < 10; i++) { if ((S >> i) & 1) continue; res += rec(S + (1 << i), sum - (x + 1) * i, cnt - 1); } return dp[S][sum][cnt] = res; } int main() { for (int i = 0; i < (1 << 10) + 1; i++) { for (int j = 0; j < 1000; j++) for (int k = 0; k < 11; k++) dp[i][j][k] = INF; } while (cin >> n >> s) { cout << rec(0, s, n) << endl; } return 0; }
replace
8
9
8
9
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9696]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9697]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
replace
8
9
8
9
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9690]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9699]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
replace
8
9
8
9
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9600]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9700]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
replace
8
9
8
9
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][9000]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
#include <cstring> #include <iostream> using namespace std; // http://d.hatena.ne.jp/Nekonyan/20110508 // Nekonyanツつウツづアツづ個コツーツドツづーツ参ツ考ツづ可つオツづ慊つオツつスツ。 int table[10 + 1][10000]; int memo[10]; void numnum(int size, int depth, int sum) { if (size + 1 == depth) { table[size][sum]++; } else { for (int i = 0; i <= 9; ++i) { if (memo[i] == 0) { memo[i] = 1; numnum(size, depth + 1, sum + i * depth); memo[i] = 0; } // end if } // end for } // end if } int main() { memset(table, 0, sizeof(table)); for (int i = 1; i <= 10; ++i) { memset(memo, 0, sizeof(memo)); numnum(i, 1, 0); } // end for int n, s; while (cin >> n >> s) { cout << table[n][s] << endl; } // end while return 0; }
replace
8
9
8
9
0
p00070
C++
Runtime Error
#include <cstdio> using namespace std; int ans[11][410]; void dfs(int dpt, int sum, int bit) { ++ans[dpt][sum]; for (int i = 0; i < 10; ++i) { if (bit >> i & 1) { dfs(dpt + 1, sum + i * (dpt + 1), bit ^ (1 << i)); } } } int main() { dfs(0, 0, 0x3ff); int n, s; while (scanf("%d%d", &n, &s) != EOF) { int x = 0; x = ans[n][s]; if (n <= 10 && s <= 400) { x = ans[n][s]; } printf("%d\n", x); } }
#include <cstdio> using namespace std; int ans[11][410]; void dfs(int dpt, int sum, int bit) { ++ans[dpt][sum]; for (int i = 0; i < 10; ++i) { if (bit >> i & 1) { dfs(dpt + 1, sum + i * (dpt + 1), bit ^ (1 << i)); } } } int main() { dfs(0, 0, 0x3ff); int n, s; while (scanf("%d%d", &n, &s) != EOF) { int x = 0; if (n <= 10 && s <= 400) { x = ans[n][s]; } printf("%d\n", x); } }
delete
19
20
19
19
0
p00070
C++
Runtime Error
#include <bits/stdc++.h> #define range(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; int n, s; vector<int> used(10); int memo[11][1000]; int sum; void dfs(int d) { memo[d][sum]++; if (d == 10) return; rep(i, 10) { if (used[i]) continue; used[i] = true; sum += (d + 1) * i; dfs(d + 1); used[i] = false; sum -= (d + 1) * i; } } int main(void) { dfs(0); while (cin >> n >> s) { cout << memo[n][s] << endl; } return 0; }
#include <bits/stdc++.h> #define range(i, a, n) for (int(i) = (a); (i) < (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; int n, s; vector<int> used(10); int memo[11][1000]; int sum; void dfs(int d) { memo[d][sum]++; if (d == 10) return; rep(i, 10) { if (used[i]) continue; used[i] = true; sum += (d + 1) * i; dfs(d + 1); used[i] = false; sum -= (d + 1) * i; } } int main(void) { dfs(0); while (cin >> n >> s) { if (s >= 1000) cout << 0 << endl; else cout << memo[n][s] << endl; } return 0; }
replace
30
31
30
34
0
p00070
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int n, s, dp[12][331][1030]; int solve(int now, int sum, int a) { int ans = 0; if (dp[now][sum][a] != -1) return dp[now][sum][a]; if (sum > s) return dp[now][sum][a] = 0; if (now == n + 1) { if (sum == s) return dp[now][sum][a] = 1; } now++; for (int i = 0; i < 10; i++) { if (!((a >> i) & 1)) ans += solve(now, sum + i * (now - 1), a | (1 << i)); } return dp[now - 1][sum][a] = ans; } int main() { while (cin >> n >> s) { int a[10]; for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n * 9 * 9; j++) for (int k = 0; k < 1 << 10; k++) dp[i][j][k] = -1; // now sum cout << solve(1, 0, 0) << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int n, s, dp[12][331][1030]; int solve(int now, int sum, int a) { int ans = 0; if (dp[now][sum][a] != -1) return dp[now][sum][a]; if (sum > s) return dp[now][sum][a] = 0; if (now == n + 1) { if (sum == s) return dp[now][sum][a] = 1; } now++; for (int i = 0; i < 10; i++) { if (!((a >> i) & 1)) ans += solve(now, sum + i * (now - 1), a | (1 << i)); } return dp[now - 1][sum][a] = ans; } int main() { while (cin >> n >> s) { int a[10]; for (int i = 0; i < 12; i++) for (int j = 0; j < 331; j++) for (int k = 0; k < 1030; k++) dp[i][j][k] = -1; // now sum cout << solve(1, 0, 0) << endl; } return 0; }
replace
25
28
25
28
0
p00070
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int dp[10][331][2048]; int main() { dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j <= 330; j++) { for (int k = 0; k < 2048; k++) { if (dp[i][j][k]) { for (int l = 0; l <= 9; l++) { if ((~k) & (1 << l)) { dp[i + 1][j + (i + 1) * l][k | (1 << l)] += dp[i][j][k]; } } } } } } int n, s; while (scanf("%d %d", &n, &s) != EOF) { if (s > 330) { puts("0"); continue; } int sum = 0; for (int i = 0; i < 2048; i++) { sum += dp[n][s][i]; } printf("%d\n", sum); } return 0; }
#include <bits/stdc++.h> using namespace std; int dp[20][500][2048]; int main() { dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j <= 330; j++) { for (int k = 0; k < 2048; k++) { if (dp[i][j][k]) { for (int l = 0; l <= 9; l++) { if ((~k) & (1 << l)) { dp[i + 1][j + (i + 1) * l][k | (1 << l)] += dp[i][j][k]; } } } } } } int n, s; while (scanf("%d %d", &n, &s) != EOF) { if (s > 330) { puts("0"); continue; } int sum = 0; for (int i = 0; i < 2048; i++) { sum += dp[n][s][i]; } printf("%d\n", sum); } return 0; }
replace
3
4
3
4
-11
p00070
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #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)); } // v.erase(unique(v.begin(),v.end()),v.end()); vint v(10, 0); ll dp[10 + 5][331 + 10][(1 << 10) + 10] = {0}; ll foo(int n, int s, int a) { // cout<<n<<" "<<s<<" "<< static_cast<std::bitset<10> >(a)<<endl; if (s < 0) return 0; if (dp[n][s][a]) return dp[n][s][a]; if (n == 1) { if (s < 10 && a >> s & 1) { return dp[n][s][a] = 1; } else { return dp[n][s][a] = 0; } } if (n <= 0) return dp[n][s][a] = 0; ll ret = 0; rep(i, 10) { // cout<<(a>>i)<<endl; if (a >> i & 1) { ret += foo(n - 1, s - n * i, a - (1 << i)); } } return dp[n][s][a] = ret; } int main() { int n, s; while (cin >> n) { cin >> s; ll ans = foo(n, s, (1 << 10) - 1); cout << ans << endl; } }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #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)); } // v.erase(unique(v.begin(),v.end()),v.end()); vint v(10, 0); ll dp[10 + 5][331 + 10][(1 << 10) + 10] = {0}; ll foo(int n, int s, int a) { // cout<<n<<" "<<s<<" "<< static_cast<std::bitset<10> >(a)<<endl; if (s > 330) return 0; if (s < 0) return 0; if (dp[n][s][a]) return dp[n][s][a]; if (n == 1) { if (s < 10 && a >> s & 1) { return dp[n][s][a] = 1; } else { return dp[n][s][a] = 0; } } if (n <= 0) return dp[n][s][a] = 0; ll ret = 0; rep(i, 10) { // cout<<(a>>i)<<endl; if (a >> i & 1) { ret += foo(n - 1, s - n * i, a - (1 << i)); } } return dp[n][s][a] = ret; } int main() { int n, s; while (cin >> n) { cin >> s; ll ans = foo(n, s, (1 << 10) - 1); cout << ans << endl; } }
insert
45
45
45
47
0
p00070
C++
Runtime Error
#include <bits/stdc++.h> #define SIZE 300005 #define MOD 1000000007LL #define INF 1 << 30 #define LLINF 1LL << 60 #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i <= b; i++) #define DOWN(i, b, a) for (int i = b; i >= a; i--) #define SET(a, c) memset(a, c, sizeof a) #define FORALL(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define FOREACH(i, c) for (auto(i) : (c)) #define BIT(i, j) ((i) >> (j)) & 1 #define ALL(o) (o).begin(), (o).end() #define ERASE(o) (o).erase(unique((o).begin(), (o).end()), (o).end()) #define SQ(x) ((x) * (x)) using namespace std; typedef long long ll; typedef valarray<int> Array; typedef pair<ll, ll> Pll; typedef pair<int, int> Pii; typedef pair<double, double> Pdd; template <typename T> inline void priv(vector<T> a) { REP(i, a.size()) { cout << a[i] << ((i == a.size() - 1) ? "\n" : " "); } } ll gcd(ll a, ll b) { int c = max(a, b); int d = min(a, b); return c == 0 || d == 0 ? c : gcd(c % d, d); } ll lcm(ll a, ll b) { return a == 0 || b == 0 ? 0 : a * b / gcd(a, b); } int a[10]; int T[11][335]; void memo(int m, int s) { if (m > 11) return; FOR(i, 0, 9) { if (a[i]) { a[i] = 0; T[m][s + m * i]++; memo(m + 1, s + m * i); a[i] = 1; } } } void init() { fill_n(a, 10, 1); REP(i, 11) fill_n(T[i], 335, 0); memo(1, 0); } int main() { init(); int n, s; while (cin >> n >> s) cout << T[n][s] << endl; return 0; }
#include <bits/stdc++.h> #define SIZE 300005 #define MOD 1000000007LL #define INF 1 << 30 #define LLINF 1LL << 60 #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i <= b; i++) #define DOWN(i, b, a) for (int i = b; i >= a; i--) #define SET(a, c) memset(a, c, sizeof a) #define FORALL(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define FOREACH(i, c) for (auto(i) : (c)) #define BIT(i, j) ((i) >> (j)) & 1 #define ALL(o) (o).begin(), (o).end() #define ERASE(o) (o).erase(unique((o).begin(), (o).end()), (o).end()) #define SQ(x) ((x) * (x)) using namespace std; typedef long long ll; typedef valarray<int> Array; typedef pair<ll, ll> Pll; typedef pair<int, int> Pii; typedef pair<double, double> Pdd; template <typename T> inline void priv(vector<T> a) { REP(i, a.size()) { cout << a[i] << ((i == a.size() - 1) ? "\n" : " "); } } ll gcd(ll a, ll b) { int c = max(a, b); int d = min(a, b); return c == 0 || d == 0 ? c : gcd(c % d, d); } ll lcm(ll a, ll b) { return a == 0 || b == 0 ? 0 : a * b / gcd(a, b); } int a[10]; int T[11][335]; void memo(int m, int s) { if (m > 11) return; FOR(i, 0, 9) { if (a[i]) { a[i] = 0; T[m][s + m * i]++; memo(m + 1, s + m * i); a[i] = 1; } } } void init() { fill_n(a, 10, 1); REP(i, 11) fill_n(T[i], 335, 0); memo(1, 0); } int main() { init(); int n, s; while (cin >> n >> s) cout << (s > 330 ? 0 : T[n][s]) << endl; return 0; }
replace
58
59
58
59
0
p00070
C++
Time Limit Exceeded
#include <iostream> void solve(const int &sum, const int &s, int limit, long long int &cnt, const int &used) { int tmp; int est_sum; for (int i = 0; i < 10; ++i) { if ((used & (1 << i)) == 0) { tmp = i * limit + sum; if (limit > 1) { est_sum = 9 * (limit - 1) * (limit - 1); if (est_sum + tmp >= s) { solve(tmp, s, limit - 1, cnt, used | (1 << i)); } } else { if (tmp == s) { ++cnt; return; } } } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int s, n; while (std::cin >> n >> s) { long long int cnt = 0; solve(0, s, n, cnt, 0); std::cout << cnt << std::endl; } return 0; }
#include <iostream> void solve(const int &sum, const int &s, int limit, long long int &cnt, const int &used) { int tmp; int est_sum; for (int i = 0; i < 10; ++i) { if ((used & (1 << i)) == 0) { tmp = i * limit + sum; if (limit > 1) { est_sum = 9 * (limit - 1) * (limit - 1); if (est_sum + tmp >= s) { solve(tmp, s, limit - 1, cnt, used | (1 << i)); } } else { if (tmp == s) { ++cnt; return; } else if (tmp > s) { return; } } } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int s, n; while (std::cin >> n >> s) { long long int cnt = 0; solve(0, s, n, cnt, 0); std::cout << cnt << std::endl; } return 0; }
insert
19
19
19
21
TLE
p00070
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int table[10][10001]; int perm[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int factorial(int n) { if (n == 1) return 1; return n * factorial(n - 1); } int main() { do { int sum = 0; for (int i = 1; i <= 10; i++) { sum += i * perm[i - 1]; table[i - 1][sum]++; } } while (next_permutation(perm, perm + 10)); int n, s; while (cin >> n >> s) { cout << table[n - 1][s] / factorial(10 - n) << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int table[10][10001]; int perm[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int factorial(int n) { int ret = 1; for (int i = 1; i <= n; i++) ret *= i; return ret; } int main() { do { int sum = 0; for (int i = 1; i <= 10; i++) { sum += i * perm[i - 1]; table[i - 1][sum]++; } } while (next_permutation(perm, perm + 10)); int n, s; while (cin >> n >> s) { cout << table[n - 1][s] / factorial(10 - n) << endl; } return 0; }
replace
8
11
8
12
TLE
p00070
C++
Runtime Error
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <vector> using namespace std; #define REP(i, j) for (int i = 0; i < j; i++) #define FOR(i, j, k) for (int i = j; i < k; i++) const int INF = INT_MAX / 2; const int NUM = 10; const int N = 11; const int S = 331; const int P = (1 << NUM); int n, s; int dp[N][S][P]; void make_dp() { REP(i, N) REP(j, S) REP(k, P) dp[i][j][k] = 0; int num = 0; for (int mask = 1; mask < (1 << NUM); mask = (mask << 1)) { dp[1][num][mask] = 1; ++num; } FOR(i, 2, N) { num = 0; for (int mask = 1; mask < (1 << NUM); mask = (mask << 1)) { FOR(j, (num * i), S) { for (int k = 1; k < (1 << NUM); ++k) { if ((k & mask) != 0) continue; int p = (k | mask); if (j - (num * i) >= 0) dp[i][j][p] += dp[i - 1][j - (num * i)][k]; } } ++num; } } } int main() { make_dp(); while (cin >> n >> s) { if (n > 10) { cout << 0 << endl; continue; } int ans = 0; REP(i, P) ans += dp[n][s][i]; cout << ans << endl; } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <vector> using namespace std; #define REP(i, j) for (int i = 0; i < j; i++) #define FOR(i, j, k) for (int i = j; i < k; i++) const int INF = INT_MAX / 2; const int NUM = 10; const int N = 11; const int S = 331; const int P = (1 << NUM); int n, s; int dp[N][S][P]; void make_dp() { REP(i, N) REP(j, S) REP(k, P) dp[i][j][k] = 0; int num = 0; for (int mask = 1; mask < (1 << NUM); mask = (mask << 1)) { dp[1][num][mask] = 1; ++num; } FOR(i, 2, N) { num = 0; for (int mask = 1; mask < (1 << NUM); mask = (mask << 1)) { FOR(j, (num * i), S) { for (int k = 1; k < (1 << NUM); ++k) { if ((k & mask) != 0) continue; int p = (k | mask); if (j - (num * i) >= 0) dp[i][j][p] += dp[i - 1][j - (num * i)][k]; } } ++num; } } } int main() { make_dp(); while (cin >> n >> s) { if (n >= N || s >= S) { cout << 0 << endl; continue; } int ans = 0; REP(i, P) ans += dp[n][s][i]; cout << ans << endl; } return 0; }
replace
50
51
50
51
0
p00070
C++
Runtime Error
#include <iostream> #include <string.h> using namespace std; int m[11][1024]; int n, s; void dfs(int b, int d, int s) { m[d][s]++; for (int i = 0; i < 10; i++) if ((b >> i) & 1) dfs(b - (1 << i), d + 1, s + (1 + d) * i); } int main() { memset(m, 0, sizeof(m)); dfs(1023, 0, 0); while (cin >> n >> s) cout << m[n][s] << endl; }
#include <iostream> #include <string.h> using namespace std; int m[21][11024]; int n, s; void dfs(int b, int d, int s) { m[d][s]++; for (int i = 0; i < 10; i++) if ((b >> i) & 1) dfs(b - (1 << i), d + 1, s + (1 + d) * i); } int main() { memset(m, 0, sizeof(m)); dfs(1023, 0, 0); while (cin >> n >> s) cout << m[n][s] << endl; }
replace
4
5
4
5
0
p00070
C++
Runtime Error
#include <iostream> #include <string.h> using namespace std; int memo[11][400]; void recursive(int depth, int sum, bool flag[10]) { ++memo[depth][sum]; for (int i = 0; i < 10; ++i) { if (flag[i]) { continue; } flag[i] = true; recursive(depth + 1, sum + (depth + 1) * i, flag); flag[i] = false; } } void solve() { bool flag[10]; memset(flag, 0, sizeof(flag)); recursive(0, 0, flag); int n, s; while (cin >> n >> s) { cout << memo[n][s] << endl; } } int main() { solve(); return (0); }
#include <iostream> #include <string.h> using namespace std; int memo[11][400]; void recursive(int depth, int sum, bool flag[10]) { ++memo[depth][sum]; for (int i = 0; i < 10; ++i) { if (flag[i]) { continue; } flag[i] = true; recursive(depth + 1, sum + (depth + 1) * i, flag); flag[i] = false; } } void solve() { bool flag[10]; memset(flag, 0, sizeof(flag)); recursive(0, 0, flag); int n, s; while (cin >> n >> s) { if (s >= 331) { cout << 0 << endl; } else { cout << memo[n][s] << endl; } } } int main() { solve(); return (0); }
replace
24
25
24
29
0
p00070
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { int a[10][331] = {0}; int p[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int q[10] = {362880, 40320, 5040, 720, 120, 24, 6, 2, 1}; int s, n; do { s = 0; for (int i = 0; i < 10; ++i) { s += (i + 1) * p[i]; a[i][s]++; } } while (next_permutation(p, p + 10)); while (cin >> n >> s) { if (s > 330) cout << 0; else cout << a[n - 1][s] / q[n - 1]; cout << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int a[10][331] = {0}; int p[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int q[10] = {362880, 40320, 5040, 720, 120, 24, 6, 2, 1, 1}; int s, n; do { s = 0; for (int i = 0; i < 10; ++i) { s += (i + 1) * p[i]; a[i][s]++; } } while (next_permutation(p, p + 10)); while (cin >> n >> s) { if (s > 330) cout << 0; else cout << a[n - 1][s] / q[n - 1]; cout << endl; } return 0; }
replace
7
8
7
8
0