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
p00070
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int dp[10 + 1][330 + 1]; for (int i = 0; i < 10 + 1; ++i) { for (int j = 0; j < 330 + 1; ++j) dp[i][j] = 0; } int fac[10 + 1]; fac[0] = fac[1] = 1; for (int i = 2; i < 10 + 1; ++i) fac[i] = i * fac[i - 1]; vector<int> num; for (int i = 0; i < 10; ++i) num.push_back(i); do { int sum = 0; for (int i = 0; i < 10; ++i) { sum += ((i + 1) * num[i]); ++dp[i + 1][sum]; } } while (next_permutation(num.begin(), num.end())); int n, s; while (cin >> n >> s) cout << dp[n][s] / fac[10 - n] << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int dp[10 + 1][330 + 1]; for (int i = 0; i < 10 + 1; ++i) { for (int j = 0; j < 330 + 1; ++j) dp[i][j] = 0; } int fac[10 + 1]; fac[0] = fac[1] = 1; for (int i = 2; i < 10 + 1; ++i) fac[i] = i * fac[i - 1]; vector<int> num; for (int i = 0; i < 10; ++i) num.push_back(i); do { int sum = 0; for (int i = 0; i < 10; ++i) { sum += ((i + 1) * num[i]); ++dp[i + 1][sum]; } } while (next_permutation(num.begin(), num.end())); int n, s; while (cin >> n >> s) if (n < 0 || 10 < n || s < 0 || 330 < s) cout << "0" << endl; else cout << dp[n][s] / fac[10 - n] << endl; return 0; }
replace
30
31
30
34
0
p00070
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; template <typename Iterator> inline bool next_combination(const Iterator first, Iterator k, const Iterator last) { if ((first == last) || (first == k) || (last == k)) return false; Iterator itr1 = first; Iterator itr2 = last; ++itr1; if (last == itr1) return false; itr1 = last; --itr1; itr1 = k; --itr2; while (first != itr1) { if (*--itr1 < *itr2) { Iterator j = k; while (!(*itr1 < *j)) ++j; std::iter_swap(itr1, j); ++itr1; ++j; itr2 = k; std::rotate(itr1, j, last); while (last != j) { ++j; ++itr2; } std::rotate(k, itr2, last); return true; } } std::rotate(first, k, last); return false; } int main() { vector<int> v; for (int i = 0; i < 10; i++) v.push_back(i); int n, s; while (cin >> n >> s) { int ret = 0; do { int sum = 0; for (int j = 0; j < n; j++) sum += v[j] * (j + 1); if (sum < s) continue; vector<int> vv; for (int i = 0; i < n; i++) vv.push_back(v[i]); do { int sum = 0; for (int j = 0; j < n; j++) sum += vv[j] * (j + 1); if (sum == s) ret++; } while (next_permutation(vv.begin(), vv.end())); } while (next_combination(v.begin(), v.begin() + n, v.end())); cout << ret << endl; } }
#include <bits/stdc++.h> using namespace std; template <typename Iterator> inline bool next_combination(const Iterator first, Iterator k, const Iterator last) { if ((first == last) || (first == k) || (last == k)) return false; Iterator itr1 = first; Iterator itr2 = last; ++itr1; if (last == itr1) return false; itr1 = last; --itr1; itr1 = k; --itr2; while (first != itr1) { if (*--itr1 < *itr2) { Iterator j = k; while (!(*itr1 < *j)) ++j; std::iter_swap(itr1, j); ++itr1; ++j; itr2 = k; std::rotate(itr1, j, last); while (last != j) { ++j; ++itr2; } std::rotate(k, itr2, last); return true; } } std::rotate(first, k, last); return false; } int main() { vector<int> v; for (int i = 0; i < 10; i++) v.push_back(i); int n, s; while (cin >> n >> s) { int ret = 0; do { int sum = 0; for (int j = 0; j < n; j++) sum += v[j] * (j + 1); if (sum < s) continue; else if (sum == s) { ret++; continue; } vector<int> vv; for (int i = 0; i < n; i++) vv.push_back(v[i]); do { int sum = 0; for (int j = 0; j < n; j++) sum += vv[j] * (j + 1); if (sum == s) ret++; } while (next_permutation(vv.begin(), vv.end())); } while (next_combination(v.begin(), v.begin() + n, v.end())); cout << ret << endl; } }
insert
54
54
54
58
TLE
p00070
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <time.h> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() #define it vector<int>::iterator const double PI = acos(-1); const double EPS = 1e-10; const int inf = 1e8; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; using namespace std; bool next_combination(it first1, it last1, it first2, it last2) { if ((first1 == last1) || (first2 == last2)) { return false; } it m1 = last1; it m2 = last2; --m2; while (--m1 != first1 && !(*m1 < *m2)) { } bool result = (m1 == first1) && !(*first1 < *m2); if (!result) { while (first2 != m2 && !(*m1 < *first2)) { ++first2; } first1 = m1; std ::iter_swap(first1, first2); ++first1; ++first2; } if ((first1 != last1) && (first2 != last2)) { m1 = last1; m2 = first2; while ((m1 != first1) && (m2 != last2)) { std ::iter_swap(--m1, m2); ++m2; } std ::reverse(first1, m1); std ::reverse(first1, last1); std ::reverse(m2, last2); std ::reverse(first2, last2); } return !result; } bool next_combination(it first, it middle, it last) { return next_combination(first, middle, middle, last); } int main() { int n, s; vvi in(20, vi(500, -1)); while (cin >> n >> s) { if (in[n][s] >= 0) { cout << in[n][s] << endl; continue; } vi d(10); int co = 0; rep(i, 10) d[i] = i; do { do { int sum = 0; rep(i, n) sum += (i + 1) * d[i]; if (sum == s) { co++; } } while (next_permutation(d.begin(), d.begin() + n)); } while (next_combination(d.begin(), d.begin() + n, d.end())); cout << co << endl; in[n][s] = co; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <set> #include <string> #include <time.h> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() #define it vector<int>::iterator const double PI = acos(-1); const double EPS = 1e-10; const int inf = 1e8; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; using namespace std; bool next_combination(it first1, it last1, it first2, it last2) { if ((first1 == last1) || (first2 == last2)) { return false; } it m1 = last1; it m2 = last2; --m2; while (--m1 != first1 && !(*m1 < *m2)) { } bool result = (m1 == first1) && !(*first1 < *m2); if (!result) { while (first2 != m2 && !(*m1 < *first2)) { ++first2; } first1 = m1; std ::iter_swap(first1, first2); ++first1; ++first2; } if ((first1 != last1) && (first2 != last2)) { m1 = last1; m2 = first2; while ((m1 != first1) && (m2 != last2)) { std ::iter_swap(--m1, m2); ++m2; } std ::reverse(first1, m1); std ::reverse(first1, last1); std ::reverse(m2, last2); std ::reverse(first2, last2); } return !result; } bool next_combination(it first, it middle, it last) { return next_combination(first, middle, middle, last); } int main() { int n, s; vvi in(20, vi(500, -1)); while (cin >> n >> s) { if (in[n][s] >= 0) { cout << in[n][s] << endl; continue; } int sum = 0; rep(i, n) sum += (i + 1) * (n - i - 1); if (sum > s) { cout << 0 << endl; in[n][s] = 0; continue; } vi d(10); int co = 0; rep(i, 10) d[i] = i; do { do { int sum = 0; rep(i, n) sum += (i + 1) * d[i]; if (sum == s) { co++; } } while (next_permutation(d.begin(), d.begin() + n)); } while (next_combination(d.begin(), d.begin() + n, d.end())); cout << co << endl; in[n][s] = co; } }
insert
70
70
70
77
TLE
p00070
C++
Runtime Error
#include <algorithm> #include <bitset> #include <iostream> using namespace std; int dp[11][1024][341]; int main() { dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j < 1024; j++) { for (int k = 0; k < 331; k++) { if (dp[i][j][k] == 0) continue; for (int l = 0; l < 10; l++) { if (!((j >> l) & 1)) { dp[i + 1][j | (1 << l)][(i + 1) * l + k] += dp[i][j][k]; } } } } } int n, s; while (cin >> n >> s) { int sum = 0; for (int i = 0; i < 1024; i++) { sum += dp[n][i][s]; } cout << sum << endl; } }
#include <algorithm> #include <bitset> #include <iostream> using namespace std; int dp[11][1024][341]; int main() { dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j < 1024; j++) { for (int k = 0; k < 331; k++) { if (dp[i][j][k] == 0) continue; for (int l = 0; l < 10; l++) { if (!((j >> l) & 1)) { dp[i + 1][j | (1 << l)][(i + 1) * l + k] += dp[i][j][k]; } } } } } int n, s; while (cin >> n >> s) { int sum = 0; if (n > 10 || s > 330) { cout << 0 << endl; continue; } for (int i = 0; i < 1024; i++) { sum += dp[n][i][s]; } cout << sum << endl; } }
insert
23
23
23
27
0
p00070
C++
Runtime Error
// AOJ 0070 Combination of Number Sequences #include <iostream> using namespace std; void set_count(int n, int sum, int used); const int MAX_N = 10; const int MAX_SUM = 330; int count_s[MAX_N + 1][MAX_SUM + 1]; int main() { int n, s; set_count(1, 0, 0); while (cin) { cin >> n >> s; if (cin.eof()) break; cout << count_s[n][s] << endl; } return 0; } void set_count(int depth, int sum, int used) { int new_sum; int i, used_i; for (i = 0; i < 10; i++) { used_i = 1 << i; if (used & used_i) continue; new_sum = sum + depth * i; count_s[depth][new_sum] += 1; if (depth < MAX_N) set_count(depth + 1, new_sum, used | used_i); } }
// AOJ 0070 Combination of Number Sequences #include <iostream> using namespace std; void set_count(int n, int sum, int used); const int MAX_N = 10; const int MAX_SUM = 330; int count_s[MAX_N + 1][MAX_SUM + 1]; int main() { int n, s; set_count(1, 0, 0); while (cin) { cin >> n >> s; if (cin.eof()) break; if (1 <= n && n <= 10 && 0 <= s && s <= 330) cout << count_s[n][s] << endl; else cout << 0 << endl; } return 0; } void set_count(int depth, int sum, int used) { int new_sum; int i, used_i; for (i = 0; i < 10; i++) { used_i = 1 << i; if (used & used_i) continue; new_sum = sum + depth * i; count_s[depth][new_sum] += 1; if (depth < MAX_N) set_count(depth + 1, new_sum, used | used_i); } }
replace
23
24
23
27
0
p00070
C++
Runtime Error
#include <stdio.h> #include <string.h> int a[10][331]; bool e[10]; void m(int d, int s) { for (int i = 0; i < 10; i++) { if (e[i]) continue; a[d][s + d * i]++; if (d < 10) { e[i] = true; m(d + 1, s + d * i); e[i] = false; } } } int main(void) { memset(a, 0, sizeof(a)); memset(e, 0, sizeof(e)); m(1, 0); int n, s; while (~scanf("%d%d", &n, &s)) { if (n < 0 || n > 10 || s < 0 || s > 330) puts("0"); else printf("%d\n", a[n][s]); } return 0; }
#include <stdio.h> #include <string.h> int a[11][331]; bool e[10]; void m(int d, int s) { for (int i = 0; i < 10; i++) { if (e[i]) continue; a[d][s + d * i]++; if (d < 10) { e[i] = true; m(d + 1, s + d * i); e[i] = false; } } } int main(void) { memset(a, 0, sizeof(a)); memset(e, 0, sizeof(e)); m(1, 0); int n, s; while (~scanf("%d%d", &n, &s)) { if (n < 0 || n > 10 || s < 0 || s > 330) puts("0"); else printf("%d\n", a[n][s]); } return 0; }
replace
2
3
2
3
0
p00070
C++
Runtime Error
#include <iostream> using namespace std; int dp[1024][500]; int main() { int n, s; dp[0][0] = 1; for (int i = 0; i < 350; i++) { for (int j = 0; j < 1024; j++) { int cnt = 1; for (int k = 0; k < 10; k++) if (j & (1 << k)) cnt++; for (int k = 0; k < 10; k++) { if (j & (1 << k)) continue; dp[j | (1 << k)][i + cnt * k] += dp[j][i]; } } } while (cin >> n >> s) { int res = 0; for (int i = 0; i < 1024; i++) { int c = 0; for (int j = 0; j < 10; j++) if (i & (1 << j)) c++; if (c == n) res += dp[i][s]; } cout << res << endl; } }
#include <iostream> using namespace std; int dp[1024][500]; int main() { int n, s; dp[0][0] = 1; for (int i = 0; i < 350; i++) { for (int j = 0; j < 1024; j++) { int cnt = 1; for (int k = 0; k < 10; k++) if (j & (1 << k)) cnt++; for (int k = 0; k < 10; k++) { if (j & (1 << k)) continue; dp[j | (1 << k)][i + cnt * k] += dp[j][i]; } } } while (cin >> n >> s) { int res = 0; for (int i = 0; i < 1024; i++) { if (s > 400) continue; int c = 0; for (int j = 0; j < 10; j++) if (i & (1 << j)) c++; if (c == n) res += dp[i][s]; } cout << res << endl; } }
insert
25
25
25
27
0
p00070
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define loop for (;;) #define trace(var) cerr << ">>> " << #var << " = " << var << endl; #define all(v) begin(v), end(v) #define pb push_back #define inf (1e9) #define eps (1e-9) typedef long long Integer; typedef long double Real; const Real PI = acosl(-1); typedef pair<int, int> P; template <class S, class T> inline ostream &operator<<(ostream &os, pair<S, T> p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class S, class T, class U> inline ostream &operator<<(ostream &os, tuple<S, T, U> t) { return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')'; } template <class T> inline ostream &operator<<(ostream &os, set<T> v) { os << "(set"; for (T item : v) os << ' ' << item; os << ")"; return os; } template <class T> inline ostream &operator<<(ostream &os, vector<T> v) { if (v.size() == 0) { return os << "(empty)"; } os << v[0]; for (int i = 1, len = v.size(); i < len; ++i) os << ' ' << v[i]; return os; } template <class T> inline istream &operator>>(istream &is, vector<T> &v) { rep(i, v.size()) is >> v[i]; return is; } // ^ > v < int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<bool> vb; int table[11][331]; bool used[10]; void search(int len, int d, int sum) { if (len == d) table[len][sum]++; else { rep(i, 10) { if (used[i]) continue; used[i] = true; search(len, d + 1, sum + i * (d + 1)); used[i] = false; } } } void dp(int len) { rep(i, 10) used[i] = false; search(len, 0, 0); } int main() { cin.tie(0); ios::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(10); random_device dev; mt19937 rand(dev()); rep(i, 10) { trace(i + 1); dp(i + 1); } int n, s; while (cin >> n >> s) { if (s > 330) { cout << 0 << endl; } else { cout << table[n][s] << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define loop for (;;) #define trace(var) cerr << ">>> " << #var << " = " << var << endl; #define all(v) begin(v), end(v) #define pb push_back #define inf (1e9) #define eps (1e-9) typedef long long Integer; typedef long double Real; const Real PI = acosl(-1); typedef pair<int, int> P; template <class S, class T> inline ostream &operator<<(ostream &os, pair<S, T> p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class S, class T, class U> inline ostream &operator<<(ostream &os, tuple<S, T, U> t) { return os << '(' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << ')'; } template <class T> inline ostream &operator<<(ostream &os, set<T> v) { os << "(set"; for (T item : v) os << ' ' << item; os << ")"; return os; } template <class T> inline ostream &operator<<(ostream &os, vector<T> v) { if (v.size() == 0) { return os << "(empty)"; } os << v[0]; for (int i = 1, len = v.size(); i < len; ++i) os << ' ' << v[i]; return os; } template <class T> inline istream &operator>>(istream &is, vector<T> &v) { rep(i, v.size()) is >> v[i]; return is; } // ^ > v < int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<bool> vb; int table[11][331]; bool used[10]; void search(int len, int d, int sum) { if (len == d) table[len][sum]++; else { rep(i, 10) { if (used[i]) continue; used[i] = true; search(len, d + 1, sum + i * (d + 1)); used[i] = false; } } } void dp(int len) { rep(i, 10) used[i] = false; search(len, 0, 0); } int main() { cin.tie(0); ios::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(10); random_device dev; mt19937 rand(dev()); rep(i, 10) { dp(i + 1); } int n, s; while (cin >> n >> s) { if (s > 330) { cout << 0 << endl; } else { cout << table[n][s] << endl; } } return 0; }
replace
90
94
90
91
0
>>> i+1 = 1 >>> i+1 = 2 >>> i+1 = 3 >>> i+1 = 4 >>> i+1 = 5 >>> i+1 = 6 >>> i+1 = 7 >>> i+1 = 8 >>> i+1 = 9 >>> i+1 = 10
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int table[10 + 1][330 + 1]; 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; 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
5
6
5
6
0
p00070
C++
Runtime Error
#include <cstring> #include <iostream> using namespace std; int table[10 + 1][330 + 2]; 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
5
6
5
9
0
p00070
C++
Runtime Error
#include <algorithm> #include <stdio.h> int main() { int m[10][331] = {0}; int n, s, i, a[10], f[11] = {1}; for (i = 0; i < 10; ++i) a[i] = i; for (i = 1; i < 10; ++i) f[i] = f[i - 1] * i; do { for (s = i = 0; i < 10; ++i) { s += (i + 1) * a[i]; ++m[i][s]; } } while (std::next_permutation(a, a + 10)); while (scanf("%d%d", &n, &s) > 0) printf("%d\n", m[n - 1][s] / f[10 - n]); return 0; }
#include <algorithm> #include <stdio.h> int main() { int m[10][331] = {0}; int n, s, i, a[10], f[11] = {1}; for (i = 0; i < 10; ++i) a[i] = i; for (i = 1; i < 10; ++i) f[i] = f[i - 1] * i; do { for (s = i = 0; i < 10; ++i) { s += (i + 1) * a[i]; ++m[i][s]; } } while (std::next_permutation(a, a + 10)); while (scanf("%d%d", &n, &s) > 0) if (s > 330) puts("0"); else printf("%d\n", m[n - 1][s] / f[10 - n]); return 0; }
replace
16
17
16
20
0
p00070
C++
Runtime Error
#include <stdio.h> #include <string.h> #define SIZE (750) int dp[11][1 << 10][SIZE]; int main(void) { int n; char buf[256]; int s; memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j < (1 << 10); j++) { for (int k = 0; k < SIZE; k++) { for (int l = 0; l < 10; l++) { if (((j >> l) & 1) == 0) { dp[i + 1][j | (1 << l)][k + ((i + 1) * l)] += dp[i][j][k]; } } } } } while (fgets(buf, 255, stdin) != NULL) { sscanf(buf, "%d%d", &n, &s); int ans = 0; for (int i = 0; i < (1 << 10); i++) { ans += dp[n][i][s]; } printf("%d\n", ans); } return (0); }
#include <stdio.h> #include <string.h> #define SIZE (750) int dp[11][1 << 10][SIZE]; int main(void) { int n; char buf[256]; int s; memset(dp, 0, sizeof(dp)); dp[0][0][0] = 1; for (int i = 0; i < 10; i++) { for (int j = 0; j < (1 << 10); j++) { for (int k = 0; k < SIZE; k++) { for (int l = 0; l < 10; l++) { if (((j >> l) & 1) == 0) { dp[i + 1][j | (1 << l)][k + ((i + 1) * l)] += dp[i][j][k]; } } } } } while (fgets(buf, 255, stdin) != NULL) { sscanf(buf, "%d%d", &n, &s); int ans = 0; if (s < SIZE) { for (int i = 0; i < (1 << 10); i++) { ans += dp[n][i][s]; } } else { ans = 0; } printf("%d\n", ans); } return (0); }
replace
28
30
28
34
0
p00070
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #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() const int INF = 1 << 29; int main() { const int N = 10; int dp[1 << N][331] = {}; int res = 0; REP(i, N) { dp[1 << i][i] = 1; } REP(S, 1 << N) { vector<int> se; REP(j, N) if ((S >> j) & 1) { se.push_back(j); // cout << j << " "; } FOR(it, se) { REP(i, 331) { if (i + (*it) * se.size() >= 331) break; dp[S][i + (*it) * se.size()] += dp[S - (1 << *it)][i]; } } // REP(i,331) { // if (dp[S][i])cout << i << " "; // }cout << endl; } int table[11][331] = {}; for (int i = 1; i <= N; ++i) { int comb = (1 << i) - 1; while (comb < 1 << 10) { REP(j, 331) { table[i][j] += dp[comb][j]; } int x = comb & -comb, y = comb + x; comb = ((comb & ~y) / x >> 1) | y; } // if (i == 3) { // REP(j,331) { // cout << table[i][j] << endl; // } // } // cout << table[i][10] << endl; } int n, s; while (cin >> n >> s) { if (n < 0 || n > 10 || s < 0 || s >= 331) cout << 0 << endl; cout << table[n][s] << endl; } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #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() const int INF = 1 << 29; int main() { const int N = 10; int dp[1 << N][331] = {}; int res = 0; REP(i, N) { dp[1 << i][i] = 1; } REP(S, 1 << N) { vector<int> se; REP(j, N) if ((S >> j) & 1) { se.push_back(j); // cout << j << " "; } FOR(it, se) { REP(i, 331) { if (i + (*it) * se.size() >= 331) break; dp[S][i + (*it) * se.size()] += dp[S - (1 << *it)][i]; } } // REP(i,331) { // if (dp[S][i])cout << i << " "; // }cout << endl; } int table[11][331] = {}; for (int i = 1; i <= N; ++i) { int comb = (1 << i) - 1; while (comb < 1 << 10) { REP(j, 331) { table[i][j] += dp[comb][j]; } int x = comb & -comb, y = comb + x; comb = ((comb & ~y) / x >> 1) | y; } // if (i == 3) { // REP(j,331) { // cout << table[i][j] << endl; // } // } // cout << table[i][10] << endl; } int n, s; while (cin >> n >> s) { if (n < 0 || n > 10 || s < 0 || s >= 331) cout << 0 << endl; else cout << table[n][s] << endl; } }
replace
63
64
63
65
0
p00071
C++
Memory Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int main(int argc, char *argv[]) { int n; cin >> n; cin.ignore(); for (int k = 0; k < n; ++k) { int grid[8][8]; int x, y; for (int i = 0; i < 8; ++i) { string str; cin >> str; for (int j = 0; j < 8; ++j) { grid[i][j] = str[j] - '0'; } } cin >> x; cin >> y; cin.ignore(); int dx[12] = {1, 2, 3, 0, 0, 0, -1, -2, -3, 0, 0, 0}; int dy[12] = {0, 0, 0, 1, 2, 3, 0, 0, 0, -1, -2, -3}; vector<pair<int, int>> p; p.push_back(make_pair(x - 1, y - 1)); while (!p.empty()) { auto pos = p.back(); p.pop_back(); for (int i = 0; i < 12; ++i) { int nx = pos.first + dx[i]; int ny = pos.second + dy[i]; if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) { if (grid[ny][nx] == 1) p.push_back(make_pair(nx, ny)); } } } printf("Data %d:\n", k + 1); for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { cout << grid[i][j]; } cout << endl; } } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int main(int argc, char *argv[]) { int n; cin >> n; cin.ignore(); for (int k = 0; k < n; ++k) { int grid[8][8]; int x, y; for (int i = 0; i < 8; ++i) { string str; cin >> str; for (int j = 0; j < 8; ++j) { grid[i][j] = str[j] - '0'; } } cin >> x; cin >> y; cin.ignore(); int dx[12] = {1, 2, 3, 0, 0, 0, -1, -2, -3, 0, 0, 0}; int dy[12] = {0, 0, 0, 1, 2, 3, 0, 0, 0, -1, -2, -3}; vector<pair<int, int>> p; p.push_back(make_pair(x - 1, y - 1)); while (!p.empty()) { auto pos = p.back(); grid[pos.second][pos.first] = 0; p.pop_back(); for (int i = 0; i < 12; ++i) { int nx = pos.first + dx[i]; int ny = pos.second + dy[i]; if (0 <= nx && nx < 8 && 0 <= ny && ny < 8) { if (grid[ny][nx] == 1) p.push_back(make_pair(nx, ny)); } } } printf("Data %d:\n", k + 1); for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { cout << grid[i][j]; } cout << endl; } } return 0; }
insert
35
35
35
36
MLE
p00072
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; #define MAX_V 111 #define INF (1 << 21) int cost[MAX_V][MAX_V] = {{0}}; int mincost[MAX_V] = {}; bool used[MAX_V] = {}; int V; int prim(void); int min(int a, int b); int main() { int m; scanf("%d", &V); while (1) { if (V == 0) break; scanf("%d", &m); for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { cost[i][j] = INF; } } for (int i = 0; i < m; i++) { int a, b, c; scanf("%d,%d,%d", &a, &b, &c); cost[a][b] = c / 100 - 1; cost[b][a] = c / 100 - 1; } printf("%d\n", prim()); scanf("%d", &V); } return 0; } int min(int a, int b) { if (a > b) return b; return a; } int prim(void) { for (int i = 0; i < V; i++) { mincost[i] = INF; used[i] = false; } mincost[0] = 0; int res = 0; while (true) { int v = -1; for (int u = 0; u < V; u++) { if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u; } if (v == -1) break; used[v] = true; res += mincost[v]; for (int u = 0; u < V; u++) { // if(cost[v][u]==0); // else{ mincost[u] = min(mincost[u], cost[v][u]); // } } } return res; }
#include <cstdio> #include <iostream> using namespace std; #define MAX_V 111 #define INF (1 << 21) int cost[MAX_V][MAX_V] = {{0}}; int mincost[MAX_V] = {}; bool used[MAX_V] = {}; int V; int prim(void); int min(int a, int b); int main() { int m; scanf("%d", &V); while (1) { if (V == 0) break; scanf("%d", &m); for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { cost[i][j] = INF; } } for (int i = 0; i < m; i++) { int a, b, c; scanf("%d,%d,%d", &a, &b, &c); cost[a][b] = c / 100 - 1; cost[b][a] = c / 100 - 1; } printf("%d\n", prim()); scanf("%d", &V); } return 0; } int min(int a, int b) { if (a > b) return b; return a; } int prim(void) { for (int i = 0; i < V; i++) { mincost[i] = INF; used[i] = false; } mincost[0] = 0; int res = 0; while (true) { int v = -1; for (int u = 0; u < V; u++) { if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u; } if (v == -1) break; used[v] = true; res += mincost[v]; for (int u = 0; u < V; u++) { // if(cost[v][u]==0); // else{ mincost[u] = min(mincost[u], cost[v][u]); // } } } return res; }
replace
25
27
25
27
0
p00072
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int INF = 1000000000; const int MAX_V = 101; int cost[MAX_V][MAX_V]; int mincost[MAX_V]; bool used[MAX_V]; int V; int prim() { for (int i = 0; i < V; ++i) { mincost[i] = INF; used[i] = false; } mincost[0] = 0; int res = 0; while (true) { int v = -1; for (int u = 0; u < V; u++) { if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u; } if (v == -1) break; used[v] = true; res += mincost[v]; for (int u = 0; u < V; u++) { mincost[u] = min(mincost[u], cost[v][u]); } } return res; } int main() { int m; while (cin >> V >> m, V) { for (int i = 0; i < V; i++) { for (int j = 0; j < m; j++) { cost[i][j] = INF; } } for (int i = 0; i < m; i++) { char ch; int a, b, c; cin >> a >> ch >> b >> ch >> c; cost[a][b] = c; cost[b][a] = c; } int ans = prim(); cout << (ans / 100) - (V - 1) << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; const int INF = 1000000000; const int MAX_V = 10000; int cost[MAX_V][MAX_V]; int mincost[MAX_V]; bool used[MAX_V]; int V; int prim() { for (int i = 0; i < V; ++i) { mincost[i] = INF; used[i] = false; } mincost[0] = 0; int res = 0; while (true) { int v = -1; for (int u = 0; u < V; u++) { if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u; } if (v == -1) break; used[v] = true; res += mincost[v]; for (int u = 0; u < V; u++) { mincost[u] = min(mincost[u], cost[v][u]); } } return res; } int main() { int m; while (cin >> V >> m, V) { for (int i = 0; i < V; i++) { for (int j = 0; j < m; j++) { cost[i][j] = INF; } } for (int i = 0; i < m; i++) { char ch; int a, b, c; cin >> a >> ch >> b >> ch >> c; cost[a][b] = c; cost[b][a] = c; } int ans = prim(); cout << (ans / 100) - (V - 1) << endl; } return 0; }
replace
5
6
5
6
0
p00072
C++
Runtime Error
// kruskal tree #include <algorithm> #include <cstdio> using namespace std; #define M 999 int parent[M], a[M], b[M]; pair<int, int> node[M]; int root(int a) { return parent[a] == a ? a : parent[a] = root(parent[a]); } int unite(int a, int b) { int x = root(a), y = root(b); if (x == y) return 0; parent[x] = y; return 1; } int main() { int i, s, n, m; for (; scanf("%d%d", &n, &m) > 1; printf("%d\n", s / 100 - n + 1)) { for (i = 0; i < m; i++) scanf("%d,%d,%d", a + i, b + i, &node[i].first), node[i].second = i; sort(node, node + m); for (i = 0; i < n; i++) parent[i] = i; for (s = i = 0; i < m; i++) if (unite(a[node[i].second], b[node[i].second])) s += node[i].first; } }
// kruskal tree #include <algorithm> #include <cstdio> using namespace std; #define M 99999 int parent[M], a[M], b[M]; pair<int, int> node[M]; int root(int a) { return parent[a] == a ? a : parent[a] = root(parent[a]); } int unite(int a, int b) { int x = root(a), y = root(b); if (x == y) return 0; parent[x] = y; return 1; } int main() { int i, s, n, m; for (; scanf("%d%d", &n, &m) > 1; printf("%d\n", s / 100 - n + 1)) { for (i = 0; i < m; i++) scanf("%d,%d,%d", a + i, b + i, &node[i].first), node[i].second = i; sort(node, node + m); for (i = 0; i < n; i++) parent[i] = i; for (s = i = 0; i < m; i++) if (unite(a[node[i].second], b[node[i].second])) s += node[i].first; } }
replace
4
5
4
5
0
p00072
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <functional> #include <queue> #include <vector> using namespace std; typedef pair<int, int> Pair; struct Edge { int len; int to; }; int n; int m; bool used[10000]; vector<Edge> es[10000]; priority_queue<Pair, vector<Pair>, greater<Pair>> q; int CalcMSTCost() { int ret = 0; fill(used, used + n, false); q.push(Pair(0, 0)); while (!q.empty()) { Pair p = q.top(); q.pop(); int d = p.first; int v = p.second; if (used[v]) continue; used[v] = true; ret += d; for (int i = 0; i < es[v].size(); i++) { q.push(Pair(es[v][i].len, es[v][i].to)); } } return ret; } int main() { while (1) { scanf("%d", &n); if (n == 0) return 0; for (int i = 0; i < n; i++) { es[i].clear(); } scanf("%d", &m); for (int i = 0; i < m; i++) { int a, b; struct Edge e; scanf("%d,%d,%d", &a, &b, &e.len); --a; --b; e.len -= 100; e.to = b; es[a].push_back(e); e.to = a; es[b].push_back(e); } printf("%d\n", CalcMSTCost() / 100); } }
#include <algorithm> #include <cstdio> #include <functional> #include <queue> #include <vector> using namespace std; typedef pair<int, int> Pair; struct Edge { int len; int to; }; int n; int m; bool used[10000]; vector<Edge> es[10000]; priority_queue<Pair, vector<Pair>, greater<Pair>> q; int CalcMSTCost() { int ret = 0; fill(used, used + n, false); q.push(Pair(0, 0)); while (!q.empty()) { Pair p = q.top(); q.pop(); int d = p.first; int v = p.second; if (used[v]) continue; used[v] = true; ret += d; for (int i = 0; i < es[v].size(); i++) { q.push(Pair(es[v][i].len, es[v][i].to)); } } return ret; } int main() { while (1) { scanf("%d", &n); if (n == 0) return 0; for (int i = 0; i < n; i++) { es[i].clear(); } scanf("%d", &m); for (int i = 0; i < m; i++) { int a, b; struct Edge e; scanf("%d,%d,%d", &a, &b, &e.len); e.len -= 100; e.to = b; es[a].push_back(e); e.to = a; es[b].push_back(e); } printf("%d\n", CalcMSTCost() / 100); } }
delete
58
60
58
58
0
p00072
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; struct edge { int u, v, cost; }; bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; } const int MAX_N = 101; const int MAX_E = 150; int par[MAX_N]; int r[MAX_N]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; r[i] = 0; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) { par[x] = y; } else { par[y] = x; if (r[x] == r[y]) r[x]++; } } bool same(int x, int y) { return find(x) == find(y); } edge es[MAX_E]; int V, E; int kruskal() { sort(es, es + E, comp); init(V); int res = 0; for (int i = 0; i < E; i++) { edge e = es[i]; if (!same(e.u, e.v)) { unite(e.u, e.v); res += e.cost; } } return res; } int main() { while (cin >> V >> E, V) { for (int i = 0; i < E; i++) { char ch; cin >> es[i].u >> ch >> es[i].v >> ch >> es[i].cost; } int ans = kruskal(); cout << ((ans / 100) - (V - 1)) << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; struct edge { int u, v, cost; }; bool comp(const edge &e1, const edge &e2) { return e1.cost < e2.cost; } const int MAX_N = 101; const int MAX_E = 10000; int par[MAX_N]; int r[MAX_N]; void init(int n) { for (int i = 0; i < n; i++) { par[i] = i; r[i] = 0; } } int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (r[x] < r[y]) { par[x] = y; } else { par[y] = x; if (r[x] == r[y]) r[x]++; } } bool same(int x, int y) { return find(x) == find(y); } edge es[MAX_E]; int V, E; int kruskal() { sort(es, es + E, comp); init(V); int res = 0; for (int i = 0; i < E; i++) { edge e = es[i]; if (!same(e.u, e.v)) { unite(e.u, e.v); res += e.cost; } } return res; } int main() { while (cin >> V >> E, V) { for (int i = 0; i < E; i++) { char ch; cin >> es[i].u >> ch >> es[i].v >> ch >> es[i].cost; } int ans = kruskal(); cout << ((ans / 100) - (V - 1)) << endl; } return 0; }
replace
11
12
11
12
0
p00072
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> constexpr int MAX_N = 100; struct edge { int from_, to_, cost_; edge() = default; edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {} bool operator<(const edge &rhs) const { return (cost_ == rhs.cost_) ? to_ < rhs.to_ : cost_ < rhs.cost_; } }; int n, m; std::vector<edge> edges; class Union { int par[MAX_N], rank[MAX_N]; public: Union() { for (int i = 0; i < n; ++i) { par[i] = i; rank[i] = 0; } } int find(int x) { if (x == par[x]) return x; par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) std::swap(x, y); par[y] = x; rank[x] += rank[y]; } }; int main() { while (1) { std::cin >> n; if (!n) break; std::cin >> m; Union uni; edges.clear(); int a, b, d; char ch; for (int i = 0; i < m; ++i) { std::cin >> a >> ch >> b >> ch >> d; d /= 100; --d; edges.push_back(edge(a, b, d)); } std::sort(edges.begin(), edges.end()); long long int ans = 0; for (int i = 0; i < edges.size(); ++i) { if (!uni.same(edges[i].from_, edges[i].to_)) { uni.unite(edges[i].from_, edges[i].to_); ans += edges[i].cost_; } } std::cout << ans << std::endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> constexpr int MAX_N = 100; struct edge { int from_, to_, cost_; edge() = default; edge(int from, int to, int cost) : from_(from), to_(to), cost_(cost) {} bool operator<(const edge &rhs) const { return (cost_ == rhs.cost_) ? to_ < rhs.to_ : cost_ < rhs.cost_; } }; int n, m; std::vector<edge> edges; class Union { int par[MAX_N], rank[MAX_N]; public: Union() { for (int i = 0; i < n; ++i) { par[i] = i; rank[i] = 0; } } int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) std::swap(x, y); par[y] = x; rank[x] += rank[y]; } }; int main() { while (1) { std::cin >> n; if (!n) break; std::cin >> m; Union uni; edges.clear(); int a, b, d; char ch; for (int i = 0; i < m; ++i) { std::cin >> a >> ch >> b >> ch >> d; d /= 100; --d; edges.push_back(edge(a, b, d)); } std::sort(edges.begin(), edges.end()); long long int ans = 0; for (int i = 0; i < edges.size(); ++i) { if (!uni.same(edges[i].from_, edges[i].to_)) { uni.unite(edges[i].from_, edges[i].to_); ans += edges[i].cost_; } } std::cout << ans << std::endl; } return 0; }
replace
31
32
31
32
0
p00072
C++
Runtime Error
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define reep(i, f, n) for (int i = f; i < int(n); ++i) #define rep(i, n) reep(i, 0, n) typedef vector<int> vi; typedef pair<int, int> pii; struct Edge { int src, dst, cost; Edge(int s, int d, int c) : src(s), dst(d), cost(c) {} Edge() {} bool operator<(const Edge &e) const { return cost > e.cost; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; Edges prim(const Graph &g) { Edges T; vector<int> visited(g.size(), 0); visited[0] = 1; priority_queue<Edge> Q; rep(i, g[0].size()) Q.push(g[0][i]); while (!Q.empty()) { Edge e = Q.top(); Q.pop(); if (visited[e.dst]) continue; T.push_back(e); visited[e.dst] = 1; rep(i, g[e.dst].size()) { if (!visited[g[e.dst][i].dst]) Q.push(g[e.dst][i]); } } return T; } int main() { int n, m; while (scanf("%d", &n), n) { scanf("%d", &m); Graph g(n); rep(i, n) { int a, b, d; scanf("%d,%d,%d", &a, &b, &d); g[a].push_back(Edge(a, b, d)); g[b].push_back(Edge(b, a, d)); } Edges t = prim(g); int ans = 0; rep(i, t.size()) ans += t[i].cost / 100 - 1; printf("%d\n", ans); } return 0; }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; #define reep(i, f, n) for (int i = f; i < int(n); ++i) #define rep(i, n) reep(i, 0, n) typedef vector<int> vi; typedef pair<int, int> pii; struct Edge { int src, dst, cost; Edge(int s, int d, int c) : src(s), dst(d), cost(c) {} Edge() {} bool operator<(const Edge &e) const { return cost > e.cost; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; Edges prim(const Graph &g) { Edges T; vector<int> visited(g.size(), 0); visited[0] = 1; priority_queue<Edge> Q; rep(i, g[0].size()) Q.push(g[0][i]); while (!Q.empty()) { Edge e = Q.top(); Q.pop(); if (visited[e.dst]) continue; T.push_back(e); visited[e.dst] = 1; rep(i, g[e.dst].size()) { if (!visited[g[e.dst][i].dst]) Q.push(g[e.dst][i]); } } return T; } int main() { int n, m; while (scanf("%d", &n), n) { scanf("%d", &m); Graph g(n); rep(i, m) { int a, b, d; scanf("%d,%d,%d", &a, &b, &d); g[a].push_back(Edge(a, b, d)); g[b].push_back(Edge(b, a, d)); } Edges t = prim(g); int ans = 0; rep(i, t.size()) ans += t[i].cost / 100 - 1; printf("%d\n", ans); } return 0; }
replace
62
63
62
63
0
p00075
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; double kg, m; while (scanf("%d, %lf,%lf", &n, &kg, &m)) { if (kg / (m * m) >= 25) { cout << n << endl; } } }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; double kg, m; while (scanf("%d, %lf,%lf", &n, &kg, &m) != EOF) { if (kg / (m * m) >= 25) { cout << n << endl; } } }
replace
12
13
12
13
TLE
p00075
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define r(i, a, n) for (int i = a; i < n; i++) using namespace std; int main() { int a; double b, c; while (scanf("%d,%lf,%lf", &a, &b, &c)) { if (25 <= (b / (c * c))) cout << a << endl; } }
#include <bits/stdc++.h> #define r(i, a, n) for (int i = a; i < n; i++) using namespace std; int main() { int a; double b, c; while (scanf("%d,%lf,%lf", &a, &b, &c) != EOF) { if (25 <= (b / (c * c))) cout << a << endl; } }
replace
6
7
6
7
TLE
p00075
C++
Time Limit Exceeded
// #define _GRIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; // ?????¬???????????¬?????? #pragma region MACRO #define P(x) cout << (x) << endl #define p(x) cout << (x) #define PED cout << "\n" #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define REP(i, x, n) for (int i = x; i < (int)n; ++i) #define repi(i, n) for (int i = 0; i <= (int)n; ++i) #define REPI(i, x, n) for (int i = x; i <= (int)n; ++i) #define ILP while (true) #define FOR(i, c) \ for (__typeof((c).begin()) != (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define mp make_pair #pragma endregion // ??? #pragma region TYPE_DEF typedef long long ll; typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<string, int> psi; typedef pair<int, string> pis; typedef vector<int> vi; typedef vector<double> vd; typedef vector<long> vl; typedef vector<long long> vll; typedef vector<string> vs; #pragma endregion // Effective std #pragma region ESTD template <typename C, typename T> int count(C &c, T t) { return count(ALL(c), t); } template <typename C, typename F> int count_if(C &c, F f) { return count_if(ALL(c), f); } template <typename C, typename T> void erase(C &c, T t) { remove(ALL(c), t), c.end(); } template <typename C> void remove(vector<C> &c, unsigned int index) { c.erase(c.begin() + index); } template <typename C, typename T, typename U> void replace(C &c, T t, U u) { replace(ALL(c), t, u); } template <typename C, typename F, typename U> void replace_if(C &c, F f, U u) { (ALL(c), f, u); } template <typename C> void reverse(C &c) { reverse(ALL(c)); } template <typename C> void sort(C &c) { sort(ALL(c)); } template <typename C, typename Pred> void sort(C &c, Pred p) { sort(ALL(c), p); } #pragma endregion // ?????° #pragma region CONST_VAL #define PI (2 * acos(0.0)) #define EPS (1e-9) #define MOD (int)(1e9 + 7) #define INF numeric_limits<int>::infinity() #pragma endregion int main() { vi v; int s; float w, h; while (scanf("%d,%f,%f", &s, &w, &h)) { if (w / (h * h) >= 25) v.push_back(s); } for (int el : v) P(el); return 0; }
// #define _GRIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; // ?????¬???????????¬?????? #pragma region MACRO #define P(x) cout << (x) << endl #define p(x) cout << (x) #define PED cout << "\n" #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define REP(i, x, n) for (int i = x; i < (int)n; ++i) #define repi(i, n) for (int i = 0; i <= (int)n; ++i) #define REPI(i, x, n) for (int i = x; i <= (int)n; ++i) #define ILP while (true) #define FOR(i, c) \ for (__typeof((c).begin()) != (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define mp make_pair #pragma endregion // ??? #pragma region TYPE_DEF typedef long long ll; typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<string, int> psi; typedef pair<int, string> pis; typedef vector<int> vi; typedef vector<double> vd; typedef vector<long> vl; typedef vector<long long> vll; typedef vector<string> vs; #pragma endregion // Effective std #pragma region ESTD template <typename C, typename T> int count(C &c, T t) { return count(ALL(c), t); } template <typename C, typename F> int count_if(C &c, F f) { return count_if(ALL(c), f); } template <typename C, typename T> void erase(C &c, T t) { remove(ALL(c), t), c.end(); } template <typename C> void remove(vector<C> &c, unsigned int index) { c.erase(c.begin() + index); } template <typename C, typename T, typename U> void replace(C &c, T t, U u) { replace(ALL(c), t, u); } template <typename C, typename F, typename U> void replace_if(C &c, F f, U u) { (ALL(c), f, u); } template <typename C> void reverse(C &c) { reverse(ALL(c)); } template <typename C> void sort(C &c) { sort(ALL(c)); } template <typename C, typename Pred> void sort(C &c, Pred p) { sort(ALL(c), p); } #pragma endregion // ?????° #pragma region CONST_VAL #define PI (2 * acos(0.0)) #define EPS (1e-9) #define MOD (int)(1e9 + 7) #define INF numeric_limits<int>::infinity() #pragma endregion int main() { vi v; int s; float w, h; while (scanf("%d,%f,%f", &s, &w, &h) != EOF) { if (w / (h * h) >= 25) v.push_back(s); } for (int el : v) P(el); return 0; }
replace
73
74
73
74
TLE
p00075
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int main(void) { int a; double b, c; while (scanf("%d,%lf,%lf", &a, &b, &c)) { int d = 0; d = b / (c * c); if (d >= 25.00) { cout << a << endl; } } return (0); }
#include <cstdio> #include <iostream> using namespace std; int main(void) { int a; double b, c; while (scanf("%d,%lf,%lf", &a, &b, &c) != EOF) { int d = 0; d = b / (c * c); if (d >= 25.00) { cout << a << endl; } } return (0); }
replace
9
10
9
10
TLE
p00075
C++
Time Limit Exceeded
#include <stdio.h> int main(void) { int ban; double tai, sin, BMI; while (scanf("%d %lf %lf", &ban, &tai, &sin) != EOF) { BMI = tai / (sin * sin); if (BMI >= 25.0) { printf("%d\n", ban); } } return 0; }
#include <stdio.h> int main(void) { int ban; double tai, sin, BMI; while (scanf("%d,%lf,%lf", &ban, &tai, &sin) != EOF) { BMI = tai / (sin * sin); if (BMI >= 25.0) { printf("%d\n", ban); } } return 0; }
replace
4
5
4
5
TLE
p00075
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int main() { int a = 0; double b, c; while (scanf("%d,%lf,%lf", &a, &b, &c)) { if (b / (c * c) >= 25) cout << a << endl; } }
#include <cstdio> #include <iostream> using namespace std; int main() { int a = 0; double b, c; while (~scanf("%d,%lf,%lf", &a, &b, &c)) { if (b / (c * c) >= 25) cout << a << endl; } }
replace
6
7
6
7
TLE
p00075
C++
Time Limit Exceeded
#include <iostream> #include <stdio.h> using namespace std; double BMI(double Kg, double m) { double bmi; bmi = Kg / (m * m); return bmi; } int main() { double Kg, m; int student; while (scanf("%d,%lf,%lf", &student, &Kg, &m)) { if (BMI(Kg, m) >= 25) { cout << student << endl; } } }
#include <iostream> #include <stdio.h> using namespace std; double BMI(double Kg, double m) { double bmi; bmi = Kg / (m * m); return bmi; } int main() { double Kg, m; int student; while (scanf("%d,%lf,%lf", &student, &Kg, &m) != EOF) { if (BMI(Kg, m) >= 25) { cout << student << endl; } } }
replace
12
13
12
13
TLE
p00075
C++
Time Limit Exceeded
#include <stdio.h> int main() { int l, i = 0; double m, n; while (scanf("%d,%lf,%lf", &l, &m, &n) != NULL) { if (25.0 <= m / (n * n)) { printf("%d\n", l); i++; } } if (i == 0) printf("????????????\n"); return 0; }
#include <stdio.h> int main() { int l, i = 0; double m, n; while (scanf("%d,%lf,%lf", &l, &m, &n) != EOF) { if (25.0 <= m / (n * n)) { printf("%d\n", l); i++; } } if (i == 0) printf("????????????\n"); return 0; }
replace
5
6
5
6
TLE
p00075
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iostream> #include <vector> using namespace std; struct data { int number; double weight; double tall; }; int main() { data dt; while (1) { scanf("%d,%lf,%lf", &dt.number, &dt.weight, &dt.tall); if (!dt.number) break; if (dt.weight / pow(dt.tall, 2) >= 25) cout << dt.number << endl; } return 0; }
#include <cmath> #include <cstdio> #include <iostream> #include <vector> using namespace std; struct data { int number; double weight; double tall; }; int main() { data dt; while (scanf("%d,%lf,%lf", &dt.number, &dt.weight, &dt.tall) != EOF) { if (dt.weight / pow(dt.tall, 2) >= 25) cout << dt.number << endl; } return 0; }
replace
14
18
14
15
TLE
p00075
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int main() { int id; double h, w; while (scanf("%d,%lf,%lf", &id, &w, &h)) { double b = (double)w / (h * h); if (b >= 25.0) cout << id << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int id; double h, w; while (scanf("%d,%lf,%lf", &id, &w, &h) != EOF) { double b = (double)w / (h * h); if (b >= 25.0) cout << id << endl; } return 0; }
replace
7
8
7
8
TLE
p00075
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int main() { int id; double w, h; while (scanf("%d,%lf,%lf", &id, &w, &h), id) { double bmi = w / (h * h); if (bmi >= 25.0) { cout << id << endl; } } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int id; double w, h; while (scanf("%d,%lf,%lf", &id, &w, &h) != EOF) { double bmi = w / (h * h); if (bmi >= 25.0) { cout << id << endl; } } return 0; }
replace
7
8
7
8
TLE
p00075
C++
Time Limit Exceeded
#include <iostream> #include <stdio.h> using namespace std; int main() { int num; double tai, sint; char d; while (scanf("%d,%lf,%lf", &num, &tai, &sint) != '\0') { // cout<<tai/sint*sint<<endl; if (tai / (sint * sint) >= 25) cout << num << endl; } }
#include <iostream> #include <stdio.h> using namespace std; int main() { int num; double tai, sint; char d; while (scanf("%d,%lf,%lf", &num, &tai, &sint) != EOF) { // cout<<tai/sint*sint<<endl; if (tai / (sint * sint) >= 25) cout << num << endl; } }
replace
7
8
7
8
TLE
p00076
C++
Time Limit Exceeded
#include <cmath> #include <iomanip> #include <iostream> int main() { int n; while (std::cin >> n) { double x = 1.0, y = 0.0; for (int i = 0; i != n - 1; ++i) { double t = sqrt(x * x + y * y); double vx = -y / t, vy = x / t; x += vx; y += vy; } std::cout << std::fixed << std::setprecision(2); std::cout << x << std::endl; std::cout << y << std::endl; } return 0; }
#include <cmath> #include <iomanip> #include <iostream> int main() { int n; while (std::cin >> n, n != -1) { double x = 1.0, y = 0.0; for (int i = 0; i != n - 1; ++i) { double t = sqrt(x * x + y * y); double vx = -y / t, vy = x / t; x += vx; y += vy; } std::cout << std::fixed << std::setprecision(2); std::cout << x << std::endl; std::cout << y << std::endl; } return 0; }
replace
6
7
6
7
TLE
p00076
C++
Time Limit Exceeded
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; /* ??????????????¬ */ #include <complex> typedef complex<ld> Point; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() const ld pi = acos(-1.0); const ld dtop = pi / 180.; const ld ptod = 1. / dtop; namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std // ????????\??? Point input_Point() { ld x, y; cin >> x >> y; return Point(x, y); } // ???????????????????????? bool eq(const ld a, const ld b) { return (abs(a - b) < eps); } // ?????? ld dot(const Point &a, const Point &b) { return real(conj(a) * b); } // ?????? ld cross(const Point &a, const Point &b) { return imag(conj(a) * b); } // ??´???????????? class Line { public: Point a, b; Line() : a(Point(0, 0)), b(Point(0, 0)) {} Line(Point a, Point b) : a(a), b(b) {} Point operator[](const int _num) const { if (_num == 0) return a; else if (_num == 1) return b; else { assert(false); return Point(); } } }; // ???????????? class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; // ccw // 1: a,b,c??????????¨???¨?????????????????¶ //-1: a,b,c???????¨???¨?????????????????¶ // 2: c,a,b???????????´???????????¶ //-2: a,b,c???????????´???????????¶ // 0: a,c,b???????????´???????????¶ int ccw(const Point &a, const Point &b, const Point &c) { const Point nb(b - a); const Point nc(c - a); if (cross(nb, nc) > eps) return 1; // a,b,c??????????¨???¨?????????????????¶ if (cross(nb, nc) < -eps) return -1; // a,b,c???????¨???¨?????????????????¶ if (dot(nb, nc) < 0) return 2; // c,a,b???????????´???????????¶ if (norm(nb) < norm(nc)) return -2; // a,b,c???????????´???????????¶ return 0; // a,c,b???????????´???????????¶ } /* ???????????? */ // ??´?????¨??´?????????????????? bool isis_ll(const Line &l, const Line &m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } // ??´?????¨????????????????????? bool isis_ls(const Line &l, const Line &s) { return isis_ll(l, s) && (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps); } // ????????¨????????????????????? bool isis_ss(const Line &s, const Line &t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } // ????????´???????????? bool isis_lp(const Line &l, const Point &p) { return (abs(cross(l.b - p, l.a - p)) < eps); } // ????????????????????? bool isis_sp(const Line &s, const Point &p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps); } // ??????????¶? Point proj(const Line &l, const Point &p) { ld t = dot(p - l.a, l.b - l.a) / norm(l.a - l.b); return l.a + t * (l.b - l.a); } //???????±?????????????????????? Point reflect(const Line &l, const Point &p) { Point pr = proj(l, p); return pr * 2.l - p; } // ??´?????¨??´???????????? Point is_ll(const Line &s, const Line &t) { Point sv = s.b - s.a, tv = t.b - t.a; assert(cross(sv, tv) != 0); return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv); } // ??´?????¨??´???????????? vector<Point> is_ll2(const Line &s, const Line &t) { Point sv = s.b - s.a, tv = t.b - t.a; if (cross(sv, tv) != 0) return vector<Point>(1, is_ll(s, t)); else { vector<Point> ans; for (int k = 0; k < 2; ++k) { if (isis_sp(s, t[k]) && find(ans.begin(), ans.end(), t[k]) == ans.end()) ans.push_back(t[k]); if (isis_sp(t, s[k]) && find(ans.begin(), ans.end(), s[k]) == ans.end()) ans.push_back(s[k]); } return ans; } } // ????????¨??????????????? //???????????£????????¨???????????¨assert(false) Point is_ss(const Line &s, const Line &t) { if (isis_ss(s, t)) { for (int k = 0; k < 2; ++k) { for (int l = 0; l < 2; ++l) { if (s[k] == t[l]) return s[k]; } } return is_ll(s, t); } else { //??????isis_ss????????? assert(false); return Point(0, 0); } } // ????????¨??????????????? vector<Point> is_ss2(const Line &s, const Line &t) { vector<Point> kouho(is_ll2(s, t)); vector<Point> ans; for (auto p : kouho) { if (isis_sp(s, p) && isis_sp(t, p)) ans.emplace_back(p); } return ans; } // ??´?????¨???????????¢ ld dist_lp(const Line &l, const Point &p) { return abs(p - proj(l, p)); } //??´?????¨??´???????????¢ ld dist_ll(const Line &l, const Line &m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } // ??´?????¨??????????????¢ ld dist_ls(const Line &l, const Line &s) { return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } // ????????¨???????????¢ ld dist_sp(const Line &s, const Point &p) { Point r = proj(s, p); return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } // ????????¨??????????????¢ ld dist_ss(const Line &s, const Line &t) { if (isis_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } //??´?????¨??´????????????????????????????????? Line bisection(const Line &s, const Line &t) { const Point laglanju(is_ll(s, t)); const Point avec = !(abs(laglanju - s[0]) < eps) ? s[0] - laglanju : s[1] - laglanju; const Point bvec = !(abs(laglanju - t[0]) < eps) ? t[0] - laglanju : t[1] - laglanju; return Line(laglanju, laglanju + (abs(bvec) * avec + abs(avec) * bvec) / (abs(avec) + abs(bvec))); } //???????????´????????????????????? //???????????´??????????????§???????????¨????¢?????????¨????????? Point inner_center(const vector<Line> &ls) { vector<Point> vertics; for (int i = 0; i < static_cast<int>(ls.size()); ++i) { vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3])); } if (vertics[0] == vertics[1] || vertics[1] == vertics[2] || vertics[2] == vertics[0]) return vertics[0]; Line bi1( bisection(Line(vertics[0], vertics[1]), Line(vertics[0], vertics[2]))); Line bi2( bisection(Line(vertics[1], vertics[2]), Line(vertics[1], vertics[0]))); if (bi1[0] == bi2[0]) return bi1[0]; else { return is_ll(bi1, bi2); } } //???????????´????????????????????? //???????????´??????????????§???????????¨????¢?????????¨????????? vector<Point> ex_center(const vector<Line> &ls) { vector<Point> vertics; for (int i = 0; i < static_cast<int>(ls.size()); ++i) { vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3])); } if (abs(vertics[0] - vertics[1]) < eps || abs(vertics[1] - vertics[2]) < eps || (abs(vertics[2] - vertics[0]) < eps)) return vector<Point>(); vector<Point> ecs; for (int i = 0; i < 3; ++i) { Line bi1( bisection(Line(vertics[i], vertics[i] * 2.0l - vertics[(i + 2) % 3]), Line(vertics[i], vertics[(i + 1) % 3]))); Line bi2(bisection(Line(vertics[(i + 1) % 3], vertics[(i + 1) % 3] * 2.0l - vertics[(i + 2) % 3]), Line(vertics[(i + 1) % 3], vertics[i]))); ecs.push_back(is_ll(bi1, bi2)); } return ecs; } // a,b:?????? // c:????????§?????? //???????????´?????????????????¢?????????????±?????????? vector<Point> same_dis(const vector<Line> &ls) { vector<Point> vertics; vertics.push_back(is_ll(ls[0], ls[2])); vertics.push_back(is_ll(ls[1], ls[2])); if (abs(vertics[0] - vertics[1]) < eps) return vector<Point>{vertics[0]}; Line bis(bisection(ls[0], ls[1])); vector<Point> ecs; Line abi(bisection(Line(vertics[0], vertics[1]), ls[0])); ecs.push_back(is_ll(bis, abi)); Line bbi(bisection(Line(vertics[0], 2.l * vertics[0] - vertics[1]), ls[0])); ecs.push_back(is_ll(bis, bbi)); return ecs; } /* ??? */ // ?????¨???????????? vector<Point> is_cc(const Circle &c1, const Circle &c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } //??????????????????????????? /* 0 => out 1 => on 2 => in*/ int is_in_Circle(const Circle &cir, const Point &p) { ld dis = abs(cir.p - p); if (dis > cir.r + eps) return 0; else if (dis < cir.r - eps) return 2; else return 1; } //???lc??????rc?????????????????? /*0 => out 1 => on 2 => in*/ int Circle_in_Circle(const Circle &lc, const Circle &rc) { ld dis = abs(lc.p - rc.p); if (dis < rc.r - lc.r - eps) return 2; else if (dis > rc.r - lc.r + eps) return 0; else return 1; } // ?????¨??´???????????? vector<Point> is_lc(const Circle &c, const Line &l) { vector<Point> res; ld d = dist_lp(l, c.p); if (d < c.r + eps) { ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety; Point nor = (l.a - l.b) / abs(l.a - l.b); res.push_back(proj(l, c.p) + len * nor); res.push_back(proj(l, c.p) - len * nor); } return res; } // ?????¨??????????????¢ vector<Point> is_sc(const Circle &c, const Line &l) { vector<Point> v = is_lc(c, l), res; for (Point p : v) if (isis_sp(l, p)) res.push_back(p); return res; } // ?????¨????????\??? vector<Line> tangent_cp(const Circle &c, const Point &p) { vector<Line> ret; Point v = c.p - p; ld d = abs(v); ld l = sqrt(norm(v) - c.r * c.r); if (isnan(l)) { return ret; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); ret.push_back(Line(p, p + v1)); if (l < eps) return ret; ret.push_back(Line(p, p + v2)); return ret; } // ?????¨????????\??? vector<Line> tangent_cc(const Circle &c1, const Circle &c2) { vector<Line> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > eps) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nret = tangent_cp(c1, out); ret.insert(ret.end(), all(nret)); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; ret.push_back(Line(q1, q1 + v)); ret.push_back(Line(q2, q2 + v)); } return ret; } //??????????????????????????¢??? ld two_Circle_area(const Circle &l, const Circle &r) { ld dis = abs(l.p - r.p); if (dis > l.r + r.r) return 0; else if (dis + r.r < l.r) { return r.r * r.r * pi; } else if (dis + l.r < r.r) { return l.r * l.r * pi; } else { ld ans = (l.r) * (l.r) * acos((dis * dis + l.r * l.r - r.r * r.r) / (2 * dis * l.r)) + (r.r) * (r.r) * acos((dis * dis + r.r * r.r - l.r * l.r) / (2 * dis * r.r)) - sqrt(4 * dis * dis * l.r * l.r - (dis * dis + l.r * l.r - r.r * r.r) * (dis * dis + l.r * l.r - r.r * r.r)) / 2; return ans; } } /* ????§???¢ */ typedef vector<Point> Polygon; // ??¢??? ld area(const Polygon &p) { ld res = 0; int n = p.size(); rep(j, n) res += cross(p[j], p[(j + 1) % n]); return res / 2; } //????§???¢????????¢?????? bool is_counter_clockwise(const Polygon &poly) { ld angle = 0; int n = poly.size(); rep(i, n) { Point a = poly[i], b = poly[(i + 1) % n], c = poly[(i + 2) % n]; angle += arg((c - b) / (b - a)); } return angle > eps; } // ?????????????????? /*0 => out 1 => on 2 => in*/ int is_in_Polygon(const Polygon &poly, const Point &p) { ld angle = 0; int n = poly.size(); rep(i, n) { Point a = poly[i], b = poly[(i + 1) % n]; if (isis_sp(Line(a, b), p)) return 1; angle += arg((b - p) / (a - p)); } return eq(angle, 0) ? 0 : 2; } //??????????????????2????????? enum { out, on, in }; int convex_contains(const Polygon &P, const Point &p) { const int n = P.size(); Point g = (P[0] + P[n / 3] + P[2 * n / 3]) / 3.0l; // inner-point int a = 0, b = n; while (a + 1 < b) { // invariant: c is in fan g-P[a]-P[b] int c = (a + b) / 2; if (cross(P[a] - g, P[c] - g) > 0) { // angle < 180 deg if (cross(P[a] - g, p - g) > 0 && cross(P[c] - g, p - g) < 0) b = c; else a = c; } else { if (cross(P[a] - g, p - g) < 0 && cross(P[c] - g, p - g) > 0) a = c; else b = c; } } b %= n; if (cross(P[a] - p, P[b] - p) < 0) return 0; if (cross(P[a] - p, P[b] - p) > 0) return 2; return 1; } // ?????? //???????????????????????¨????????????????????§??¨??? Polygon convex_hull(vector<Point> ps) { int n = ps.size(); int k = 0; sort(ps.begin(), ps.end()); Polygon ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) 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--]) while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; } //???????????? vector<Polygon> convex_cut(const Polygon &ps, const Line &l) { int n = ps.size(); Polygon q; Polygon r; rep(i, n) { Point a = ps[i], b = ps[(i + 1) % n]; Line m = Line(a, b); if (ccw(l.a, l.b, a) != -1) q.push_back(a); if (ccw(l.a, l.b, a) != 1) r.push_back(a); if (ccw(l.a, l.b, a) * ccw(l.a, l.b, b) < 0 && isis_ll(l, m)) { q.push_back(is_ll(l, m)); r.push_back(is_ll(l, m)); } } const vector<Polygon> polys{q, r}; return polys; } /* ??¢??¬??????????????? */ void add_Point(vector<Point> &ps, const Point p) { for (Point q : ps) if (abs(q - p) < eps) return; ps.push_back(p); } typedef int Weight; struct edge { int src, dst; Weight weight; edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {} }; typedef vector<edge> edges; typedef vector<edges> graph; void add_edge(graph &g, const int from, const int to, const Weight &weight) { g[from].push_back(edge{from, to, weight}); } graph segment_arrangement(const vector<Line> &s, const vector<Point> &p) { int n = p.size(), m = s.size(); graph g(n); rep(i, m) { vector<pair<ld, int>> vec; rep(j, n) if (isis_sp(s[i], p[j])) vec.emplace_back(abs(s[i].a - p[j]), j); sort(all(vec)); rep(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; add_edge(g, from, to, static_cast<Weight>(abs(p[from] - p[to]))); } } return g; } graph sennbunn_arrangement(const vector<Line> &s) { vector<Point> crss; for (int i = 0; i < static_cast<int>(s.size()); ++i) { for (int j = i + 1; j < static_cast<int>(s.size()); ++j) { if (isis_ss(s[i], s[j])) { crss.push_back(is_ll2(s[i], s[j])[0]); } } } for (int i = 0; i < static_cast<int>(s.size()); ++i) { crss.push_back(s[i][0]); crss.push_back(s[i][1]); } return segment_arrangement(s, crss); } graph Circle_arrangement(const vector<Circle> &c, const vector<Point> &p) { int n = p.size(), m = c.size(); graph g(n); rep(i, m) { vector<pair<ld, int>> vec; rep(j, n) if (abs(abs(c[i].p - p[j]) - c[i].r) < eps) vec.emplace_back(arg(c[i].p - p[j]), j); sort(all(vec)); rep(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; ld angle = vec[j + 1].first - vec[j].first; add_edge(g, from, to, static_cast<Weight>(angle * c[i].r)); } if (vec.size() >= 2) { int from = vec.back().second, to = vec.front().first; ld angle = vec.front().first - vec.back().first; add_edge(g, from, to, static_cast<Weight>(angle * c[i].r)); } } return g; } int main() { while (1) { int N; cin >> N; N--; Point p(1, 0); while (N--) { Point way = p * Point(0, 1); p += way / abs(way); } cout << p.real() << endl << p.imag() << endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; /* ??????????????¬ */ #include <complex> typedef complex<ld> Point; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() const ld pi = acos(-1.0); const ld dtop = pi / 180.; const ld ptod = 1. / dtop; namespace std { bool operator<(const Point &lhs, const Point &rhs) { if (lhs.real() < rhs.real() - eps) return true; if (lhs.real() > rhs.real() + eps) return false; return lhs.imag() < rhs.imag(); } } // namespace std // ????????\??? Point input_Point() { ld x, y; cin >> x >> y; return Point(x, y); } // ???????????????????????? bool eq(const ld a, const ld b) { return (abs(a - b) < eps); } // ?????? ld dot(const Point &a, const Point &b) { return real(conj(a) * b); } // ?????? ld cross(const Point &a, const Point &b) { return imag(conj(a) * b); } // ??´???????????? class Line { public: Point a, b; Line() : a(Point(0, 0)), b(Point(0, 0)) {} Line(Point a, Point b) : a(a), b(b) {} Point operator[](const int _num) const { if (_num == 0) return a; else if (_num == 1) return b; else { assert(false); return Point(); } } }; // ???????????? class Circle { public: Point p; ld r; Circle() : p(Point(0, 0)), r(0) {} Circle(Point p, ld r) : p(p), r(r) {} }; // ccw // 1: a,b,c??????????¨???¨?????????????????¶ //-1: a,b,c???????¨???¨?????????????????¶ // 2: c,a,b???????????´???????????¶ //-2: a,b,c???????????´???????????¶ // 0: a,c,b???????????´???????????¶ int ccw(const Point &a, const Point &b, const Point &c) { const Point nb(b - a); const Point nc(c - a); if (cross(nb, nc) > eps) return 1; // a,b,c??????????¨???¨?????????????????¶ if (cross(nb, nc) < -eps) return -1; // a,b,c???????¨???¨?????????????????¶ if (dot(nb, nc) < 0) return 2; // c,a,b???????????´???????????¶ if (norm(nb) < norm(nc)) return -2; // a,b,c???????????´???????????¶ return 0; // a,c,b???????????´???????????¶ } /* ???????????? */ // ??´?????¨??´?????????????????? bool isis_ll(const Line &l, const Line &m) { return !eq(cross(l.b - l.a, m.b - m.a), 0); } // ??´?????¨????????????????????? bool isis_ls(const Line &l, const Line &s) { return isis_ll(l, s) && (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps); } // ????????¨????????????????????? bool isis_ss(const Line &s, const Line &t) { return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0; } // ????????´???????????? bool isis_lp(const Line &l, const Point &p) { return (abs(cross(l.b - p, l.a - p)) < eps); } // ????????????????????? bool isis_sp(const Line &s, const Point &p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps); } // ??????????¶? Point proj(const Line &l, const Point &p) { ld t = dot(p - l.a, l.b - l.a) / norm(l.a - l.b); return l.a + t * (l.b - l.a); } //???????±?????????????????????? Point reflect(const Line &l, const Point &p) { Point pr = proj(l, p); return pr * 2.l - p; } // ??´?????¨??´???????????? Point is_ll(const Line &s, const Line &t) { Point sv = s.b - s.a, tv = t.b - t.a; assert(cross(sv, tv) != 0); return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv); } // ??´?????¨??´???????????? vector<Point> is_ll2(const Line &s, const Line &t) { Point sv = s.b - s.a, tv = t.b - t.a; if (cross(sv, tv) != 0) return vector<Point>(1, is_ll(s, t)); else { vector<Point> ans; for (int k = 0; k < 2; ++k) { if (isis_sp(s, t[k]) && find(ans.begin(), ans.end(), t[k]) == ans.end()) ans.push_back(t[k]); if (isis_sp(t, s[k]) && find(ans.begin(), ans.end(), s[k]) == ans.end()) ans.push_back(s[k]); } return ans; } } // ????????¨??????????????? //???????????£????????¨???????????¨assert(false) Point is_ss(const Line &s, const Line &t) { if (isis_ss(s, t)) { for (int k = 0; k < 2; ++k) { for (int l = 0; l < 2; ++l) { if (s[k] == t[l]) return s[k]; } } return is_ll(s, t); } else { //??????isis_ss????????? assert(false); return Point(0, 0); } } // ????????¨??????????????? vector<Point> is_ss2(const Line &s, const Line &t) { vector<Point> kouho(is_ll2(s, t)); vector<Point> ans; for (auto p : kouho) { if (isis_sp(s, p) && isis_sp(t, p)) ans.emplace_back(p); } return ans; } // ??´?????¨???????????¢ ld dist_lp(const Line &l, const Point &p) { return abs(p - proj(l, p)); } //??´?????¨??´???????????¢ ld dist_ll(const Line &l, const Line &m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } // ??´?????¨??????????????¢ ld dist_ls(const Line &l, const Line &s) { return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b)); } // ????????¨???????????¢ ld dist_sp(const Line &s, const Point &p) { Point r = proj(s, p); return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p)); } // ????????¨??????????????¢ ld dist_ss(const Line &s, const Line &t) { if (isis_ss(s, t)) return 0; return min( {dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)}); } //??´?????¨??´????????????????????????????????? Line bisection(const Line &s, const Line &t) { const Point laglanju(is_ll(s, t)); const Point avec = !(abs(laglanju - s[0]) < eps) ? s[0] - laglanju : s[1] - laglanju; const Point bvec = !(abs(laglanju - t[0]) < eps) ? t[0] - laglanju : t[1] - laglanju; return Line(laglanju, laglanju + (abs(bvec) * avec + abs(avec) * bvec) / (abs(avec) + abs(bvec))); } //???????????´????????????????????? //???????????´??????????????§???????????¨????¢?????????¨????????? Point inner_center(const vector<Line> &ls) { vector<Point> vertics; for (int i = 0; i < static_cast<int>(ls.size()); ++i) { vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3])); } if (vertics[0] == vertics[1] || vertics[1] == vertics[2] || vertics[2] == vertics[0]) return vertics[0]; Line bi1( bisection(Line(vertics[0], vertics[1]), Line(vertics[0], vertics[2]))); Line bi2( bisection(Line(vertics[1], vertics[2]), Line(vertics[1], vertics[0]))); if (bi1[0] == bi2[0]) return bi1[0]; else { return is_ll(bi1, bi2); } } //???????????´????????????????????? //???????????´??????????????§???????????¨????¢?????????¨????????? vector<Point> ex_center(const vector<Line> &ls) { vector<Point> vertics; for (int i = 0; i < static_cast<int>(ls.size()); ++i) { vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3])); } if (abs(vertics[0] - vertics[1]) < eps || abs(vertics[1] - vertics[2]) < eps || (abs(vertics[2] - vertics[0]) < eps)) return vector<Point>(); vector<Point> ecs; for (int i = 0; i < 3; ++i) { Line bi1( bisection(Line(vertics[i], vertics[i] * 2.0l - vertics[(i + 2) % 3]), Line(vertics[i], vertics[(i + 1) % 3]))); Line bi2(bisection(Line(vertics[(i + 1) % 3], vertics[(i + 1) % 3] * 2.0l - vertics[(i + 2) % 3]), Line(vertics[(i + 1) % 3], vertics[i]))); ecs.push_back(is_ll(bi1, bi2)); } return ecs; } // a,b:?????? // c:????????§?????? //???????????´?????????????????¢?????????????±?????????? vector<Point> same_dis(const vector<Line> &ls) { vector<Point> vertics; vertics.push_back(is_ll(ls[0], ls[2])); vertics.push_back(is_ll(ls[1], ls[2])); if (abs(vertics[0] - vertics[1]) < eps) return vector<Point>{vertics[0]}; Line bis(bisection(ls[0], ls[1])); vector<Point> ecs; Line abi(bisection(Line(vertics[0], vertics[1]), ls[0])); ecs.push_back(is_ll(bis, abi)); Line bbi(bisection(Line(vertics[0], 2.l * vertics[0] - vertics[1]), ls[0])); ecs.push_back(is_ll(bis, bbi)); return ecs; } /* ??? */ // ?????¨???????????? vector<Point> is_cc(const Circle &c1, const Circle &c2) { vector<Point> res; ld d = abs(c1.p - c2.p); ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d); ld dfr = c1.r * c1.r - rc * rc; if (abs(dfr) < eps) dfr = 0.0; else if (dfr < 0.0) return res; // no intersection ld rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } //??????????????????????????? /* 0 => out 1 => on 2 => in*/ int is_in_Circle(const Circle &cir, const Point &p) { ld dis = abs(cir.p - p); if (dis > cir.r + eps) return 0; else if (dis < cir.r - eps) return 2; else return 1; } //???lc??????rc?????????????????? /*0 => out 1 => on 2 => in*/ int Circle_in_Circle(const Circle &lc, const Circle &rc) { ld dis = abs(lc.p - rc.p); if (dis < rc.r - lc.r - eps) return 2; else if (dis > rc.r - lc.r + eps) return 0; else return 1; } // ?????¨??´???????????? vector<Point> is_lc(const Circle &c, const Line &l) { vector<Point> res; ld d = dist_lp(l, c.p); if (d < c.r + eps) { ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety; Point nor = (l.a - l.b) / abs(l.a - l.b); res.push_back(proj(l, c.p) + len * nor); res.push_back(proj(l, c.p) - len * nor); } return res; } // ?????¨??????????????¢ vector<Point> is_sc(const Circle &c, const Line &l) { vector<Point> v = is_lc(c, l), res; for (Point p : v) if (isis_sp(l, p)) res.push_back(p); return res; } // ?????¨????????\??? vector<Line> tangent_cp(const Circle &c, const Point &p) { vector<Line> ret; Point v = c.p - p; ld d = abs(v); ld l = sqrt(norm(v) - c.r * c.r); if (isnan(l)) { return ret; } Point v1 = v * Point(l / d, c.r / d); Point v2 = v * Point(l / d, -c.r / d); ret.push_back(Line(p, p + v1)); if (l < eps) return ret; ret.push_back(Line(p, p + v2)); return ret; } // ?????¨????????\??? vector<Line> tangent_cc(const Circle &c1, const Circle &c2) { vector<Line> ret; if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) { Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r); ret = tangent_cp(c1, center); } if (abs(c1.r - c2.r) > eps) { Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r); vector<Line> nret = tangent_cp(c1, out); ret.insert(ret.end(), all(nret)); } else { Point v = c2.p - c1.p; v /= abs(v); Point q1 = c1.p + v * Point(0, 1) * c1.r; Point q2 = c1.p + v * Point(0, -1) * c1.r; ret.push_back(Line(q1, q1 + v)); ret.push_back(Line(q2, q2 + v)); } return ret; } //??????????????????????????¢??? ld two_Circle_area(const Circle &l, const Circle &r) { ld dis = abs(l.p - r.p); if (dis > l.r + r.r) return 0; else if (dis + r.r < l.r) { return r.r * r.r * pi; } else if (dis + l.r < r.r) { return l.r * l.r * pi; } else { ld ans = (l.r) * (l.r) * acos((dis * dis + l.r * l.r - r.r * r.r) / (2 * dis * l.r)) + (r.r) * (r.r) * acos((dis * dis + r.r * r.r - l.r * l.r) / (2 * dis * r.r)) - sqrt(4 * dis * dis * l.r * l.r - (dis * dis + l.r * l.r - r.r * r.r) * (dis * dis + l.r * l.r - r.r * r.r)) / 2; return ans; } } /* ????§???¢ */ typedef vector<Point> Polygon; // ??¢??? ld area(const Polygon &p) { ld res = 0; int n = p.size(); rep(j, n) res += cross(p[j], p[(j + 1) % n]); return res / 2; } //????§???¢????????¢?????? bool is_counter_clockwise(const Polygon &poly) { ld angle = 0; int n = poly.size(); rep(i, n) { Point a = poly[i], b = poly[(i + 1) % n], c = poly[(i + 2) % n]; angle += arg((c - b) / (b - a)); } return angle > eps; } // ?????????????????? /*0 => out 1 => on 2 => in*/ int is_in_Polygon(const Polygon &poly, const Point &p) { ld angle = 0; int n = poly.size(); rep(i, n) { Point a = poly[i], b = poly[(i + 1) % n]; if (isis_sp(Line(a, b), p)) return 1; angle += arg((b - p) / (a - p)); } return eq(angle, 0) ? 0 : 2; } //??????????????????2????????? enum { out, on, in }; int convex_contains(const Polygon &P, const Point &p) { const int n = P.size(); Point g = (P[0] + P[n / 3] + P[2 * n / 3]) / 3.0l; // inner-point int a = 0, b = n; while (a + 1 < b) { // invariant: c is in fan g-P[a]-P[b] int c = (a + b) / 2; if (cross(P[a] - g, P[c] - g) > 0) { // angle < 180 deg if (cross(P[a] - g, p - g) > 0 && cross(P[c] - g, p - g) < 0) b = c; else a = c; } else { if (cross(P[a] - g, p - g) < 0 && cross(P[c] - g, p - g) > 0) a = c; else b = c; } } b %= n; if (cross(P[a] - p, P[b] - p) < 0) return 0; if (cross(P[a] - p, P[b] - p) > 0) return 2; return 1; } // ?????? //???????????????????????¨????????????????????§??¨??? Polygon convex_hull(vector<Point> ps) { int n = ps.size(); int k = 0; sort(ps.begin(), ps.end()); Polygon ch(2 * n); for (int i = 0; i < n; ch[k++] = ps[i++]) 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--]) while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k; ch.resize(k - 1); return ch; } //???????????? vector<Polygon> convex_cut(const Polygon &ps, const Line &l) { int n = ps.size(); Polygon q; Polygon r; rep(i, n) { Point a = ps[i], b = ps[(i + 1) % n]; Line m = Line(a, b); if (ccw(l.a, l.b, a) != -1) q.push_back(a); if (ccw(l.a, l.b, a) != 1) r.push_back(a); if (ccw(l.a, l.b, a) * ccw(l.a, l.b, b) < 0 && isis_ll(l, m)) { q.push_back(is_ll(l, m)); r.push_back(is_ll(l, m)); } } const vector<Polygon> polys{q, r}; return polys; } /* ??¢??¬??????????????? */ void add_Point(vector<Point> &ps, const Point p) { for (Point q : ps) if (abs(q - p) < eps) return; ps.push_back(p); } typedef int Weight; struct edge { int src, dst; Weight weight; edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {} }; typedef vector<edge> edges; typedef vector<edges> graph; void add_edge(graph &g, const int from, const int to, const Weight &weight) { g[from].push_back(edge{from, to, weight}); } graph segment_arrangement(const vector<Line> &s, const vector<Point> &p) { int n = p.size(), m = s.size(); graph g(n); rep(i, m) { vector<pair<ld, int>> vec; rep(j, n) if (isis_sp(s[i], p[j])) vec.emplace_back(abs(s[i].a - p[j]), j); sort(all(vec)); rep(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; add_edge(g, from, to, static_cast<Weight>(abs(p[from] - p[to]))); } } return g; } graph sennbunn_arrangement(const vector<Line> &s) { vector<Point> crss; for (int i = 0; i < static_cast<int>(s.size()); ++i) { for (int j = i + 1; j < static_cast<int>(s.size()); ++j) { if (isis_ss(s[i], s[j])) { crss.push_back(is_ll2(s[i], s[j])[0]); } } } for (int i = 0; i < static_cast<int>(s.size()); ++i) { crss.push_back(s[i][0]); crss.push_back(s[i][1]); } return segment_arrangement(s, crss); } graph Circle_arrangement(const vector<Circle> &c, const vector<Point> &p) { int n = p.size(), m = c.size(); graph g(n); rep(i, m) { vector<pair<ld, int>> vec; rep(j, n) if (abs(abs(c[i].p - p[j]) - c[i].r) < eps) vec.emplace_back(arg(c[i].p - p[j]), j); sort(all(vec)); rep(j, vec.size() - 1) { int from = vec[j].second, to = vec[j + 1].second; ld angle = vec[j + 1].first - vec[j].first; add_edge(g, from, to, static_cast<Weight>(angle * c[i].r)); } if (vec.size() >= 2) { int from = vec.back().second, to = vec.front().first; ld angle = vec.front().first - vec.back().first; add_edge(g, from, to, static_cast<Weight>(angle * c[i].r)); } } return g; } int main() { while (1) { int N; cin >> N; if (N == -1) break; N--; Point p(1, 0); while (N--) { Point way = p * Point(0, 1); p += way / abs(way); } cout << p.real() << endl << p.imag() << endl; } return 0; }
insert
601
601
601
603
TLE
p00077
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> using namespace std; int main() { char a; while (scanf("%c", &a)) { if (a == '@') { int s; cin >> a; s = a - '0'; cin >> a; for (int i = 0; i < s; i++) { cout << a; } } else if (a == '\n') cout << endl; else cout << a; } }
#include <cstdio> #include <iostream> using namespace std; int main() { char a; while (scanf("%c", &a) != EOF) { if (a == '@') { int s; cin >> a; s = a - '0'; cin >> a; for (int i = 0; i < s; i++) { cout << a; } } else if (a == '\n') cout << endl; else cout << a; } }
replace
6
7
6
7
TLE
p00077
C++
Time Limit Exceeded
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { std::ios_base::sync_with_stdio(false); string inp, mozi; int kai; while (1) { cin >> inp; for (int i = 0; i < inp.length(); i++) { if (inp[i] == '@') { kai = inp[i + 1] - '0'; mozi = inp[i + 2]; for (int j = 0; j < kai; j++) { cout << mozi; } i += 2; } else cout << inp[i]; } cout << endl; } return 0; }
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { std::ios_base::sync_with_stdio(false); string inp, mozi; int kai; while (cin >> inp) { for (int i = 0; i < inp.length(); i++) { if (inp[i] == '@') { kai = inp[i + 1] - '0'; mozi = inp[i + 2]; for (int j = 0; j < kai; j++) { cout << mozi; } i += 2; } else cout << inp[i]; } cout << endl; } return 0; }
replace
12
14
12
13
TLE
p00077
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 int main() { string s; while (1) { cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '@') { for (int j = 0; j < (s[i + 1] - '0'); j++) { cout << s[i + 2]; } i += 2; } else { cout << s[i]; } } cout << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 int main() { string s; while (cin >> s) { for (int i = 0; i < s.size(); i++) { if (s[i] == '@') { for (int j = 0; j < (s[i + 1] - '0'); j++) { cout << s[i + 2]; } i += 2; } else { cout << s[i]; } } cout << endl; } return 0; }
replace
22
24
22
23
TLE
p00077
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string s; while (cin >> s) { while (s.find("@") != 0) { int x = s.find("@"); string buf; for (int i = 0; i < s[x + 1] - '0'; i++) buf += s[x + 2]; s.replace(x, 3, buf); } cout << s << endl; } }
#include <iostream> #include <string> using namespace std; int main() { string s; while (cin >> s) { while (s.find("@") != -1) { int x = s.find("@"); string buf; for (int i = 0; i < s[x + 1] - '0'; i++) buf += s[x + 2]; s.replace(x, 3, buf); } cout << s << endl; } }
replace
6
7
6
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 18)
p00079
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iomanip> #include <iostream> using namespace std; #pragma warning(disable : 4996) struct Point { long double px, py; }; struct Segment { Point p1, p2; }; Point X[200000]; Point Minus(Point a, Point b) { Point G; G.px = a.px - b.px; G.py = a.py - b.py; return G; } long double Abs(Point a) { return sqrt(a.px * a.px + a.py * a.py); } long double dot(const Point &a, const Point &b) { return a.px * b.px + a.py * b.py; } long double crs(const Point &a, const Point &b) { return a.px * b.py - a.py * b.px; } long double dst(const Segment &a, const Point &b) { return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1))); } int main() { int N = 0; while (scanf("%Lf,%Lf", &X[N].px, &X[N].py)) { N++; } long double SUM = 0.0l; for (int i = 1; i < N - 1; i++) { Segment A; A.p1 = X[i]; A.p2 = X[i + 1]; long double DST = dst(A, X[0]); Point H; H.px = X[i].px - X[i + 1].px; H.py = X[i].py - X[i + 1].py; long double LEN = Abs(H); SUM += DST * LEN / 2; } cout << fixed << setprecision(1919) << SUM << endl; return 0; }
#include <cmath> #include <cstdio> #include <iomanip> #include <iostream> using namespace std; #pragma warning(disable : 4996) struct Point { long double px, py; }; struct Segment { Point p1, p2; }; Point X[200000]; Point Minus(Point a, Point b) { Point G; G.px = a.px - b.px; G.py = a.py - b.py; return G; } long double Abs(Point a) { return sqrt(a.px * a.px + a.py * a.py); } long double dot(const Point &a, const Point &b) { return a.px * b.px + a.py * b.py; } long double crs(const Point &a, const Point &b) { return a.px * b.py - a.py * b.px; } long double dst(const Segment &a, const Point &b) { return abs(crs(Minus(a.p2, a.p1), Minus(b, a.p1)) / Abs(Minus(a.p2, a.p1))); } int main() { int N = 0; while (scanf("%Lf,%Lf", &X[N].px, &X[N].py) != EOF) { N++; } long double SUM = 0.0l; for (int i = 1; i < N - 1; i++) { Segment A; A.p1 = X[i]; A.p2 = X[i + 1]; long double DST = dst(A, X[0]); Point H; H.px = X[i].px - X[i + 1].px; H.py = X[i].py - X[i + 1].py; long double LEN = Abs(H); SUM += DST * LEN / 2; } cout << fixed << setprecision(1919) << SUM << endl; return 0; }
replace
31
32
31
32
TLE
p00079
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 int main() { double num[21][2]; int r = 1; while (scanf("%lf %lf", &num[r][0], &num[r][1]) != EOF) { r++; } double ans = 0.0; for (int i = 2; i < r - 1; i++) { double a, b, c; a = sqrt((num[i][0] - num[1][0]) * (num[i][0] - num[1][0]) + (num[i][1] - num[1][1]) * (num[i][1] - num[1][1])); b = sqrt((num[i + 1][0] - num[1][0]) * (num[i + 1][0] - num[1][0]) + (num[i + 1][1] - num[1][1]) * (num[i + 1][1] - num[1][1])); c = sqrt((num[i][0] - num[i + 1][0]) * (num[i][0] - num[i + 1][0]) + (num[i][1] - num[i + 1][1]) * (num[i][1] - num[i + 1][1])); double y = (a + b + c) / 2.0; ans += sqrt(y * (y - a) * (y - b) * (y - c)); } printf("%f\n", ans); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 int main() { double num[21][2]; int r = 1; while (scanf("%lf,%lf", &num[r][0], &num[r][1]) != EOF) { r++; } double ans = 0.0; for (int i = 2; i < r - 1; i++) { double a, b, c; a = sqrt((num[i][0] - num[1][0]) * (num[i][0] - num[1][0]) + (num[i][1] - num[1][1]) * (num[i][1] - num[1][1])); b = sqrt((num[i + 1][0] - num[1][0]) * (num[i + 1][0] - num[1][0]) + (num[i + 1][1] - num[1][1]) * (num[i + 1][1] - num[1][1])); c = sqrt((num[i][0] - num[i + 1][0]) * (num[i][0] - num[i + 1][0]) + (num[i][1] - num[i + 1][1]) * (num[i][1] - num[i + 1][1])); double y = (a + b + c) / 2.0; ans += sqrt(y * (y - a) * (y - b) * (y - c)); } printf("%f\n", ans); }
replace
25
26
25
26
TLE
p00079
C++
Runtime Error
#include <cmath> #include <complex> #include <cstdio> #include <iostream> using namespace std; typedef complex<double> xy_t; int main() { xy_t P[110]; int N = 0; double x, y; while (scanf("%lf,%lf", &x, &y)) { P[N++] = xy_t(x, y); } double sum = 0.0; for (int i = 0; i + 2 < N; ++i) { xy_t a = P[0], b = P[i + 1], c = P[i + 2]; sum += (conj(b - a) * (c - a)).imag(); } sum /= 2; printf("%.6f\n", abs(sum)); return 0; }
#include <cmath> #include <complex> #include <cstdio> #include <iostream> using namespace std; typedef complex<double> xy_t; int main() { xy_t P[110]; int N = 0; double x, y; while (~scanf("%lf,%lf", &x, &y)) { P[N++] = xy_t(x, y); } double sum = 0.0; for (int i = 0; i + 2 < N; ++i) { xy_t a = P[0], b = P[i + 1], c = P[i + 2]; sum += (conj(b - a) * (c - a)).imag(); } sum /= 2; printf("%.6f\n", abs(sum)); return 0; }
replace
10
11
10
11
-11
p00079
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) #define X real() #define Y imag() typedef complex<double> P; double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; } int main() { double a, b; vector<P> p; while (scanf("%lf,%lf", &a, &b)) { p.push_back(P(a, b)); } double sum = 0; reps(i, 1, p.size() - 1) { sum += cross(p[i] - p[0], p[i + 1] - p[0]) / 2; } printf("%.9lf\n", fabs(sum)); }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) #define X real() #define Y imag() typedef complex<double> P; double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; } int main() { double a, b; vector<P> p; while (scanf("%lf,%lf", &a, &b) != EOF) { p.push_back(P(a, b)); } double sum = 0; reps(i, 1, p.size() - 1) { sum += cross(p[i] - p[0], p[i + 1] - p[0]) / 2; } printf("%.9lf\n", fabs(sum)); }
replace
26
27
26
27
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p00079
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <stdio.h> #include <vector> using namespace std; //------------------------------------------------------------------------- // geometric library namespace geometry { #define EPS 1E-10 ///< 0とみなすサイズ。適当 struct point { double x; double y; point &operator+=(const point &rhs) { x += rhs.x; y += rhs.y; return *this; } point &operator-=(const point &rhs) { x -= rhs.x; y -= rhs.y; return *this; } point &operator/=(double factor) { x /= factor; y /= factor; return *this; } point &operator*=(double factor) { x *= factor; y *= factor; return *this; } bool operator==(const point &rhs) const { return (std::abs(x - rhs.x) < EPS) && (std::abs(y - rhs.y) < EPS); } bool operator!=(const point &rhs) const { return !(*this == rhs); } bool operator<=(const point &rhs) const { return x < rhs.x || (x == rhs.x && y <= rhs.y); } bool operator>=(const point &rhs) const { return x > rhs.x || (x == rhs.x && y >= rhs.y); } bool operator<(const point &rhs) const { return !(*this >= rhs); } bool operator>(const point &rhs) const { return !(*this <= rhs); } }; enum rotate_dir { rotate_None = 0, rotate_CW = 1, rotate_CCW = -1 }; point operator+(const point &p1, const point &p2) { point p(p1); p += p2; return p; } point operator/(const point &p1, double factor) { point p(p1); p /= factor; return p; } point operator-(const point &p1, const point &p2) { point p(p1); p -= p2; return p; } ///! 2点の距離 double get_distance(const point &p1, const point &p2) { return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2)); } } // namespace geometry //------------------------------------------------------------------------- // solution using namespace geometry; double get_area_of_triangle(const point &p1, const point &p2, const point &p3) { double a = get_distance(p1, p2); double b = get_distance(p2, p3); double c = get_distance(p3, p1); double z = (a + b + c) / 2; assert(z > a && z > b && z > c); // 3角形であるための条件 return sqrt(z * (z - a) * (z - b) * (z - c)); } double get_area_of_convex(const vector<point> &points) { double S = 0.0; for (int i = 2; i < points.size(); i++) { S += get_area_of_triangle(points[0], points[i - 1], points[i]); } return S; } int main(void) { vector<point> points; point p; char sep; while (cin >> p.x >> sep >> p.y) { points.push_back(p); } cout << get_area_of_convex(points); return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <iostream> #include <stdio.h> #include <vector> using namespace std; //------------------------------------------------------------------------- // geometric library namespace geometry { #define EPS 1E-10 ///< 0とみなすサイズ。適当 struct point { double x; double y; point &operator+=(const point &rhs) { x += rhs.x; y += rhs.y; return *this; } point &operator-=(const point &rhs) { x -= rhs.x; y -= rhs.y; return *this; } point &operator/=(double factor) { x /= factor; y /= factor; return *this; } point &operator*=(double factor) { x *= factor; y *= factor; return *this; } bool operator==(const point &rhs) const { return (std::abs(x - rhs.x) < EPS) && (std::abs(y - rhs.y) < EPS); } bool operator!=(const point &rhs) const { return !(*this == rhs); } bool operator<=(const point &rhs) const { return x < rhs.x || (x == rhs.x && y <= rhs.y); } bool operator>=(const point &rhs) const { return x > rhs.x || (x == rhs.x && y >= rhs.y); } bool operator<(const point &rhs) const { return !(*this >= rhs); } bool operator>(const point &rhs) const { return !(*this <= rhs); } }; enum rotate_dir { rotate_None = 0, rotate_CW = 1, rotate_CCW = -1 }; point operator+(const point &p1, const point &p2) { point p(p1); p += p2; return p; } point operator/(const point &p1, double factor) { point p(p1); p /= factor; return p; } point operator-(const point &p1, const point &p2) { point p(p1); p -= p2; return p; } ///! 2点の距離 double get_distance(const point &p1, const point &p2) { return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2)); } } // namespace geometry //------------------------------------------------------------------------- // solution using namespace geometry; double get_area_of_triangle(const point &p1, const point &p2, const point &p3) { double a = get_distance(p1, p2); double b = get_distance(p2, p3); double c = get_distance(p3, p1); double z = (a + b + c) / 2; return sqrt(z * (z - a) * (z - b) * (z - c)); } double get_area_of_convex(const vector<point> &points) { double S = 0.0; for (int i = 2; i < points.size(); i++) { S += get_area_of_triangle(points[0], points[i - 1], points[i]); } return S; } int main(void) { vector<point> points; point p; char sep; while (cin >> p.x >> sep >> p.y) { points.push_back(p); } cout << get_area_of_convex(points); return 0; }
delete
92
94
92
92
0
p00080
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iostream> using namespace std; #define EPS 1e-5 int main() { double q; while (cin >> q, q >= 0) { double x = q / 2; while (fabs(x * x * x) > EPS * q) { x = x - (x * x * x - q) / (3 * x * x); } printf("%f\n", x); } return 0; }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; #define EPS 1e-5 int main() { double q; while (cin >> q, q >= 0) { double x = q / 2; while (fabs(x * x * x - q) >= EPS * q) { x = x - (x * x * x - q) / (3 * x * x); } printf("%f\n", x); } return 0; }
replace
12
13
12
13
TLE
p00080
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { int in; double q, x; while (cin >> in && in) { q = in; x = q / 2; while (fabs(x * x * x - q) >= q * 1e-5) { x = x - (x * x * x - q) / (3 * x * x); } printf("%.5f\n", x); } return 0; }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { int in; double q, x; while (cin >> in && in != -1) { q = in; x = q / 2; while (fabs(x * x * x - q) >= q * 1e-5) { x = x - (x * x * x - q) / (3 * x * x); } printf("%.5f\n", x); } return 0; }
replace
8
9
8
9
TLE
p00080
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; #define REP(i, n) for (ll i = 0; i < n; ++i) #define REPR(i, n) for (ll i = 1; i < n; ++i) #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define MOD (ll)(1e9 + 7) #define ADD(a, b) a = ((a) + (b)) % MOD #define FIX(a) ((a) % MOD + MOD) % MOD #define INF 1000000000 typedef double Real; #define EPS 1e-11 #define EQ(x) (-EPS < x && x < EPS) typedef complex<Real> P; Real dot(P a, P b) { return real(conj(a) * b); } Real cross(P a, P b) { return imag(conj(a) * b); } int main() { cout.precision(12); while (true) { Real x; cin >> x; if (x == -1) break; Real a = x / 2; while (abs(a * a * a - x) > 1e-7) { a = a - (a * a * a - x) / (3 * a * a); } cout << fixed << a << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; #define REP(i, n) for (ll i = 0; i < n; ++i) #define REPR(i, n) for (ll i = 1; i < n; ++i) #define FOR(i, a, b) for (ll i = a; i < b; ++i) #define DEBUG(x) cout << #x << ": " << x << endl #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << " " << v[i]; \ cout << endl #define ALL(a) (a).begin(), (a).end() #define MOD (ll)(1e9 + 7) #define ADD(a, b) a = ((a) + (b)) % MOD #define FIX(a) ((a) % MOD + MOD) % MOD #define INF 1000000000 typedef double Real; #define EPS 1e-11 #define EQ(x) (-EPS < x && x < EPS) typedef complex<Real> P; Real dot(P a, P b) { return real(conj(a) * b); } Real cross(P a, P b) { return imag(conj(a) * b); } int main() { cout.precision(12); while (true) { Real x; cin >> x; if (x == -1) break; Real a = x / 2.0; while (abs(a * a * a - x) >= 0.00001 * x) { a = a - (a * a * a - x) / (3.0 * a * a); } cout << fixed << a << endl; } return 0; }
replace
39
42
39
42
TLE
p00080
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main(void) { int q; while (cin >> q) { if (q == -1) break; double x = q / 2; while (1) { if (abs(x * x * x - q) < 0.00001 * q) break; x = x - (x * x * x - q) / (3 * x * x); } printf("%.6f", x); cout << endl; } return 0; }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int main(void) { int q; while (cin >> q) { if (q == -1) break; if (q == 1) { printf("1.000000"); cout << endl; continue; } double x = q / 2; while (1) { if (abs(x * x * x - q) < 0.00001 * q) break; x = x - (x * x * x - q) / (3 * x * x); } printf("%.6f", x); cout << endl; } return 0; }
replace
12
13
12
17
TLE
p00080
C++
Time Limit Exceeded
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { double q; while (cin >> q && q != -1) { double x = q / 2; while (true) { if (fabs(x * x * x * q) < 0.00001 * q) break; x -= (x * x * x - q) / (x * x * 3); } cout << fixed << setprecision(7) << x << endl; } }
#include <cmath> #include <iomanip> #include <iostream> using namespace std; int main() { double q; while (cin >> q && q != -1) { double x = q / 2; while (true) { if (fabs(x * x * x - q) < 0.00001 * q) break; x -= (x * x * x - q) / (x * x * 3); } cout << fixed << setprecision(7) << x << endl; } }
replace
9
10
9
10
TLE
p00080
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> int main() { int q; float x; for (; scanf("%d", &q), ~q; printf("%f\n", x)) for (x = q / 2.; fabs(x * x * x - q) > 1e-5 * q; x -= x / 3 - q / 3 / x / x) ; }
#include <cmath> #include <cstdio> int main() { int q; float x; for (; scanf("%d", &q), ~q; printf("%f\n", x)) for (x = q / 2.; fabs(x * x * x - q) > 1e-5 * q; x -= (x * x * x - q) / (3 * x * x)) ; }
replace
6
7
6
8
TLE
p00080
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <list> #include <queue> #include <stack> #include <vector> using namespace std; int main() { double tmp[20][2]; int cnt = 0; int n; for (;;) { scanf("%d", &n); if (n == -1) break; double ans = 1.0 * n / 2.0; while (abs(ans * ans * ans - n) >= 1e-10) ans -= (ans * ans * ans - n) / (3 * ans * ans); printf("%.8lf\n", ans); } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <list> #include <queue> #include <stack> #include <vector> using namespace std; int main() { double tmp[20][2]; int cnt = 0; int n; for (;;) { scanf("%d", &n); if (n == -1) break; double ans = 1.0 * n / 2.0; while (abs(ans * ans * ans - n) >= 0.00001 * n) ans -= (ans * ans * ans - n) / (3 * ans * ans); printf("%.8lf\n", ans); } return 0; }
replace
17
18
17
18
TLE
p00081
C++
Runtime Error
#include <cmath> #include <cstdio> #include <iomanip> #include <iostream> using namespace std; #define EPS 1e-10 #define equals(a, b) (fabs((a) - (b)) < EPS) class Point { public: long double x, y; Point(long double x = 0, long 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(x * a, y * a); } Point operator/(double a) { return Point(x / a, y / a); } long double abs() { return sqrt(norm()); } long double norm() { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } 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; } }; struct Segment { Point p1, p2; }; long double norm(Point p) { return p.x * p.x + p.y * p.y; } long double abs(Point p) { return sqrt(norm(p)); } double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } Point projection(Segment a, Point b) { Point sa = a.p2 - a.p1; double hyp = dot(b - a.p1, sa); double r = hyp / norm(sa); return a.p1 + sa * r; } Point reflection(Segment a, Point b) { return b + ((projection(a, b) - b) * 2.0); } int main() { Point P1, P2, P3; Segment G; int q; while (scanf("%Lf,%Lf,%Lf,%Lf,%Lf,%Lf", &P2.x, P2.y, P3.x, P3.y, P1.x, P1.y) != EOF) { G.p1 = P2; G.p2 = P3; P2 = reflection(G, P1); cout << fixed << setprecision(15) << P2.x << ' ' << fixed << setprecision(15) << P2.y << endl; } return 0; }
#include <cmath> #include <cstdio> #include <iomanip> #include <iostream> using namespace std; #define EPS 1e-10 #define equals(a, b) (fabs((a) - (b)) < EPS) class Point { public: long double x, y; Point(long double x = 0, long 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(x * a, y * a); } Point operator/(double a) { return Point(x / a, y / a); } long double abs() { return sqrt(norm()); } long double norm() { return x * x + y * y; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } 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; } }; struct Segment { Point p1, p2; }; long double norm(Point p) { return p.x * p.x + p.y * p.y; } long double abs(Point p) { return sqrt(norm(p)); } double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } Point projection(Segment a, Point b) { Point sa = a.p2 - a.p1; double hyp = dot(b - a.p1, sa); double r = hyp / norm(sa); return a.p1 + sa * r; } Point reflection(Segment a, Point b) { return b + ((projection(a, b) - b) * 2.0); } int main() { Point P1, P2, P3; Segment G; int q; while (scanf("%Lf,%Lf,%Lf,%Lf,%Lf,%Lf", &P2.x, &P2.y, &P3.x, &P3.y, &P1.x, &P1.y) != EOF) { G.p1 = P2; G.p2 = P3; P2 = reflection(G, P1); cout << fixed << setprecision(15) << P2.x << ' ' << fixed << setprecision(15) << P2.y << endl; } return 0; }
replace
42
44
42
44
-11
p00081
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 long double D; typedef complex<D> P; typedef struct { P s, t; } L; const D eps = 1.0e-10; const D pi = acos(-1.0); template <class T> bool operator==(T a, T b) { return abs(a - b) < eps; } template <class T> bool operator<(T a, T b) { return a < b - eps; } template <class T> bool operator<=(T a, T b) { return a < b + eps; } template <class T> int sig(T r) { return (r == 0 || r == -0) ? 0 : r > 0 ? 1 : -1; } template <class T> int sig(T a, T b = 0) { return a < b ? -1 : b > a ? 1 : 0; } #define X real() #define Y imag() D ip(P a, P b) { return a.X * b.X + a.Y * b.Y; } D ep(P a, P b) { return a.X * b.Y - a.Y * b.X; } D sq(D a) { return sqrt(max(a, (D)0)); } P vec(L l) { return l.t - l.s; } inline P input() { D x, y; cin >> x >> y; return P(x, y); } //??\??? ???????????¬????????¨??? // ?°???± verify AOJ CGL_1_A P proj(P b, P p) { return b * ip(b, p) / norm(b); } P proj(L l, P p) { return l.s + proj(vec(l), p - l.s); } // ????°? verify AOJ CGL_1_B P refl(L l, P p) { return proj(l, p) * D(2.0) - p; } int main(void) { while (1) { char tmp; double x, y; cin >> x >> tmp >> y; P a, b; a = {x, y}; cin >> tmp >> x >> tmp >> y; b = {x, y}; L base = {a, b}; P point; cin >> tmp >> x >> tmp >> y; point = {x, y}; P ans = refl(base, point); cout.precision(10); cout << fixed << ans.X << " " << ans.Y << 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; typedef long double D; typedef complex<D> P; typedef struct { P s, t; } L; const D eps = 1.0e-10; const D pi = acos(-1.0); template <class T> bool operator==(T a, T b) { return abs(a - b) < eps; } template <class T> bool operator<(T a, T b) { return a < b - eps; } template <class T> bool operator<=(T a, T b) { return a < b + eps; } template <class T> int sig(T r) { return (r == 0 || r == -0) ? 0 : r > 0 ? 1 : -1; } template <class T> int sig(T a, T b = 0) { return a < b ? -1 : b > a ? 1 : 0; } #define X real() #define Y imag() D ip(P a, P b) { return a.X * b.X + a.Y * b.Y; } D ep(P a, P b) { return a.X * b.Y - a.Y * b.X; } D sq(D a) { return sqrt(max(a, (D)0)); } P vec(L l) { return l.t - l.s; } inline P input() { D x, y; cin >> x >> y; return P(x, y); } //??\??? ???????????¬????????¨??? // ?°???± verify AOJ CGL_1_A P proj(P b, P p) { return b * ip(b, p) / norm(b); } P proj(L l, P p) { return l.s + proj(vec(l), p - l.s); } // ????°? verify AOJ CGL_1_B P refl(L l, P p) { return proj(l, p) * D(2.0) - p; } int main(void) { while (1) { char tmp; double x, y; cin >> x >> tmp >> y; if (cin.eof()) break; P a, b; a = {x, y}; cin >> tmp >> x >> tmp >> y; b = {x, y}; L base = {a, b}; P point; cin >> tmp >> x >> tmp >> y; point = {x, y}; P ans = refl(base, point); cout.precision(10); cout << fixed << ans.X << " " << ans.Y << endl; } return 0; }
insert
45
45
45
47
TLE
p00081
C++
Time Limit Exceeded
#include <cmath> #include <cstdio> using namespace std; #define rep(i, j) for (int i = 0; i < j; i++) // note: theta[rad] void rotate(double &x, double &y, const double &theta) { double nx, ny; nx = x * cos(theta) - y * sin(theta); ny = x * sin(theta) + y * cos(theta); x = nx; y = ny; } int main() { double p[2][2], q[2]; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &p[0][0], &p[0][1], &p[1][0], &p[1][1], &q[0], &q[1])) { double bias[2] = {p[0][0], p[0][1]}; p[0][0] -= bias[0]; p[0][1] -= bias[1]; p[1][0] -= bias[0]; p[1][1] -= bias[1]; q[0] -= bias[0]; q[1] -= bias[1]; double theta = atan2(p[1][1] - p[0][1], p[1][0] - p[0][0]); rotate(q[0], q[1], -theta); double r[2] = {q[0], -q[1]}; rotate(r[0], r[1], theta); r[0] += bias[0]; r[1] += bias[1]; printf("%lf %lf\n", r[0], r[1]); } return 0; }
#include <cmath> #include <cstdio> using namespace std; #define rep(i, j) for (int i = 0; i < j; i++) // note: theta[rad] void rotate(double &x, double &y, const double &theta) { double nx, ny; nx = x * cos(theta) - y * sin(theta); ny = x * sin(theta) + y * cos(theta); x = nx; y = ny; } int main() { double p[2][2], q[2]; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &p[0][0], &p[0][1], &p[1][0], &p[1][1], &q[0], &q[1]) == 6) { double bias[2] = {p[0][0], p[0][1]}; p[0][0] -= bias[0]; p[0][1] -= bias[1]; p[1][0] -= bias[0]; p[1][1] -= bias[1]; q[0] -= bias[0]; q[1] -= bias[1]; double theta = atan2(p[1][1] - p[0][1], p[1][0] - p[0][0]); rotate(q[0], q[1], -theta); double r[2] = {q[0], -q[1]}; rotate(r[0], r[1], theta); r[0] += bias[0]; r[1] += bias[1]; printf("%lf %lf\n", r[0], r[1]); } return 0; }
replace
18
19
18
19
TLE
p00081
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long double ld; const ld EPS = 1e-9; const ld INF = 1e10; const ld PI = M_PI; struct Point { ld x, y; Point(ld x, ld y) : x(x), y(y) {} Point() {} }; Point operator+(const Point &a, const Point &b) { return Point(a.x + b.x, a.y + b.y); } Point operator-(const Point &a, const Point &b) { return Point(a.x - b.x, a.y - b.y); } Point operator*(const Point &a, const ld b) { return Point(a.x * b, a.y * b); } Point operator*(const Point &a, const Point &b) { return Point(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); } Point operator/(const Point &a, const ld b) { return Point(a.x / b, a.y / b); } ld dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } ld norm(const Point &a) { return dot(a, a); } struct Line : vector<Point> { Line(Point a = Point(0, 0), Point b = Point(0, 0)) { this->push_back(a); this->push_back(b); } }; // 写像 Point projection(const Line &l, const Point &p) { ld t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]); return l[0] + (l[1] - l[0]) * t; } // 反射 Point reflection(const Line &l, const Point &p) { return p + (projection(l, p) - p) * 2; } int main() { double x1, y1, x2, y2, xq, yq; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq)) { Line l = Line(Point(x1, y1), Point(x2, y2)); Point p = Point(xq, yq); Point ans = reflection(l, p); printf("%.6Lf %.6Lf\n", ans.x, ans.y); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long double ld; const ld EPS = 1e-9; const ld INF = 1e10; const ld PI = M_PI; struct Point { ld x, y; Point(ld x, ld y) : x(x), y(y) {} Point() {} }; Point operator+(const Point &a, const Point &b) { return Point(a.x + b.x, a.y + b.y); } Point operator-(const Point &a, const Point &b) { return Point(a.x - b.x, a.y - b.y); } Point operator*(const Point &a, const ld b) { return Point(a.x * b, a.y * b); } Point operator*(const Point &a, const Point &b) { return Point(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x); } Point operator/(const Point &a, const ld b) { return Point(a.x / b, a.y / b); } ld dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } ld norm(const Point &a) { return dot(a, a); } struct Line : vector<Point> { Line(Point a = Point(0, 0), Point b = Point(0, 0)) { this->push_back(a); this->push_back(b); } }; // 写像 Point projection(const Line &l, const Point &p) { ld t = dot(p - l[0], l[1] - l[0]) / norm(l[0] - l[1]); return l[0] + (l[1] - l[0]) * t; } // 反射 Point reflection(const Line &l, const Point &p) { return p + (projection(l, p) - p) * 2; } int main() { double x1, y1, x2, y2, xq, yq; while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) != EOF) { Line l = Line(Point(x1, y1), Point(x2, y2)); Point p = Point(xq, yq); Point ans = reflection(l, p); printf("%.6Lf %.6Lf\n", ans.x, ans.y); } return 0; }
replace
50
51
50
52
TLE
p00082
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() #define INF 1 << 29 using namespace std; typedef long long ll; typedef pair<int, int> P; const int usage[] = {4, 1, 4, 1, 2, 1, 2, 1}; int main() { // cut here before submit // freopen ("testcase.flying_jenny", "r", stdin ); vector<vector<int>> c(8, vector<int>(8, 0)); rep(i, 8) c[0][i] = usage[i]; for (int i = 1; i < 8; i++) { rep(j, 8) { c[i][j] = c[i - 1][(i + j) % 8]; } // end rep } // end for sort(ALL(c)); rep(i, 8) { rep(j, 8) { cerr << setw(2) << c[i][j]; } // end rep cerr << endl; } // end rep string str = ""; while (getline(cin, str)) { stringstream ss(str); vector<int> p(8, 0); rep(i, 8) { ss >> p[i]; } // end rep int res = INF; int ans = -1; rep(i, 8) { int curr = 0; rep(j, 8) { curr += max(p[j] - c[i][j], 0); } // end rep if (res > curr) { res = curr; ans = i; } // end if } // end rep rep(i, 8) { cout << c[ans][i] << (i != 7 ? ' ' : '\n'); } // end rep } // 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() #define INF 1 << 29 using namespace std; typedef long long ll; typedef pair<int, int> P; const int usage[] = {4, 1, 4, 1, 2, 1, 2, 1}; int main() { // cut here before submit // freopen ("testcase.flying_jenny", "r", stdin ); vector<vector<int>> c(8, vector<int>(8, 0)); rep(i, 8) c[0][i] = usage[i]; for (int i = 1; i < 8; i++) { rep(j, 8) { c[i][j] = c[i - 1][(i + j) % 8]; } // end rep } // end for sort(ALL(c)); /* rep (i, 8 ){ rep (j, 8 ){ cerr << setw(2) << c[i][j]; } // end rep cerr << endl; } // end rep */ string str = ""; while (getline(cin, str)) { stringstream ss(str); vector<int> p(8, 0); rep(i, 8) { ss >> p[i]; } // end rep int res = INF; int ans = -1; rep(i, 8) { int curr = 0; rep(j, 8) { curr += max(p[j] - c[i][j], 0); } // end rep if (res > curr) { res = curr; ans = i; } // end if } // end rep rep(i, 8) { cout << c[ans][i] << (i != 7 ? ' ' : '\n'); } // end rep } // end loop return 0; }
replace
44
50
44
52
0
1 2 1 2 1 4 1 4 1 2 1 4 1 4 1 2 1 4 1 2 1 2 1 4 1 4 1 4 1 2 1 2 2 1 2 1 4 1 4 1 2 1 4 1 4 1 2 1 4 1 2 1 2 1 4 1 4 1 4 1 2 1 2 1
p00082
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, b, n) for (int i = b; i < n; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; const int jenny[8] = {4, 1, 2, 1, 2, 1, 4, 1}; int main() { int p[7]; int sum; int pi; while (scanf("%d %d %d %d %d %d %d %d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &p[7])) { if (cin.eof()) break; int ans = INF; for (int i = 0; i <= 7; i++) { // どれだけずらすか sum = 0; for (int j = 0; j <= 7; j++) { int d = jenny[(i + j) % 8] - p[j]; if (d < 0) { sum += abs(d); } } if (ans == sum) { int d1 = 0; int d2 = 0; for (int j = 0; j <= 7; j++) { d1 += jenny[(j + pi) % 8] * pow(10.0, 7 - j); } for (int j = 0; j <= 7; j++) { d2 += jenny[(j + i) % 8] * pow(10.0, 7 - j); } if (d1 > d2) { pi = i; continue; } continue; } if (ans > sum) { ans = sum; pi = i; } } for (int i = 0; i <= 7; i++) { cout << jenny[(i + pi) % 8]; if (i != 7) cout << " "; if (i == 7) cout << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, b, n) for (int i = b; i < n; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; const int jenny[8] = {4, 1, 2, 1, 2, 1, 4, 1}; int main() { int p[7]; int sum; int pi; while (scanf("%d %d %d %d %d %d %d %d", &p[0], &p[1], &p[2], &p[3], &p[4], &p[5], &p[6], &p[7]) != EOF) { if (cin.eof()) break; int ans = INF; for (int i = 0; i <= 7; i++) { // どれだけずらすか sum = 0; for (int j = 0; j <= 7; j++) { int d = jenny[(i + j) % 8] - p[j]; if (d < 0) { sum += abs(d); } } if (ans == sum) { int d1 = 0; int d2 = 0; for (int j = 0; j <= 7; j++) { d1 += jenny[(j + pi) % 8] * pow(10.0, 7 - j); } for (int j = 0; j <= 7; j++) { d2 += jenny[(j + i) % 8] * pow(10.0, 7 - j); } if (d1 > d2) { pi = i; continue; } continue; } if (ans > sum) { ans = sum; pi = i; } } for (int i = 0; i <= 7; i++) { cout << jenny[(i + pi) % 8]; if (i != 7) cout << " "; if (i == 7) cout << endl; } } return 0; }
replace
44
45
44
45
TLE
p00083
C++
Time Limit Exceeded
#include <stdbool.h> #include <stdio.h> int main(void) { int x, y, z, sum; while (true) { scanf("%d%d%d", &x, &y, &z); sum = 10000 * x + 100 * y + z; if (sum < 18680908) { printf("pre-meiji\n"); } else if (sum < 19120730) { printf("meiji %d %d %d\n", x - 1867, y, z); } else if (sum < 19261225) { printf("taisho %d %d %d\n", x - 1911, y, z); } else if (sum < 19890108) { printf("showa %d %d %d\n", x - 1925, y, z); } else { printf("heisei %d %d %d\n", x - 1988, y, z); } } return 0; }
#include <stdbool.h> #include <stdio.h> int main(void) { int x, y, z, sum; while (scanf("%d%d%d", &x, &y, &z) != EOF) { sum = 10000 * x + 100 * y + z; if (sum < 18680908) { printf("pre-meiji\n"); } else if (sum < 19120730) { printf("meiji %d %d %d\n", x - 1867, y, z); } else if (sum < 19261225) { printf("taisho %d %d %d\n", x - 1911, y, z); } else if (sum < 19890108) { printf("showa %d %d %d\n", x - 1925, y, z); } else { printf("heisei %d %d %d\n", x - 1988, y, z); } } return 0; }
replace
5
7
5
6
TLE
p00083
C++
Time Limit Exceeded
#include <stdbool.h> #include <stdio.h> bool Fmeiji, Ftaisho, Fshowa, Fheisei = false; void meiji(int year, int month, int day); void taisho(int year, int month, int day); void showa(int year, int month, int day); void heisei(int year, int month, int day); int year, month, day; int main(void) { int wagou; while (1) { scanf("%d %d %d", &year, &month, &day); heisei(year, month, day); if (Fheisei == true) { wagou = year - 1988; printf("heisei %d %d %d\n", wagou, month, day); } else { showa(year, month, day); if (Fshowa == true) { wagou = year - 1925; printf("showa %d %d %d\n", wagou, month, day); } else { taisho(year, month, day); if (Ftaisho == true) { wagou = year - 1911; printf("taisho %d %d %d\n", wagou, month, day); } else { meiji(year, month, day); if (Fmeiji == true) { wagou = year - 1867; printf("meiji %d %d %d\n", wagou, month, day); } else { printf("pre-meiji\n"); } } } } } return 0; } void meiji(int year, int month, int day) { if (year > 1868) { Fmeiji = true; } else if (year == 1868 && month > 9) { Fmeiji = true; } else if (year == 1868 && month == 9 && day >= 8) { Fmeiji = true; } else { Fmeiji = false; } } void taisho(int year, int month, int day) { if (year > 1912) { Ftaisho = true; } else if (year == 1912 && month > 7) { Ftaisho = true; } else if (year == 1912 && month == 7 && day >= 30) { Ftaisho = true; } else { Ftaisho = false; } } void showa(int year, int month, int day) { if (year > 1926) { Fshowa = true; } else if (year == 1926 && month > 12) { Fshowa = true; } else if (year == 1926 && month == 12 && day >= 25) { Fshowa = true; } else { Fshowa = false; } } void heisei(int year, int month, int day) { if (year > 1989) { Fheisei = true; } else if (year == 1989 && month > 1) { Fheisei = true; } else if (year == 1989 && month == 1 && day >= 8) { Fheisei = true; } else { Fheisei = false; } }
#include <stdbool.h> #include <stdio.h> bool Fmeiji, Ftaisho, Fshowa, Fheisei = false; void meiji(int year, int month, int day); void taisho(int year, int month, int day); void showa(int year, int month, int day); void heisei(int year, int month, int day); int year, month, day; int main(void) { int wagou; while ((scanf("%d %d %d", &year, &month, &day)) != EOF) { heisei(year, month, day); if (Fheisei == true) { wagou = year - 1988; printf("heisei %d %d %d\n", wagou, month, day); } else { showa(year, month, day); if (Fshowa == true) { wagou = year - 1925; printf("showa %d %d %d\n", wagou, month, day); } else { taisho(year, month, day); if (Ftaisho == true) { wagou = year - 1911; printf("taisho %d %d %d\n", wagou, month, day); } else { meiji(year, month, day); if (Fmeiji == true) { wagou = year - 1867; printf("meiji %d %d %d\n", wagou, month, day); } else { printf("pre-meiji\n"); } } } } } return 0; } void meiji(int year, int month, int day) { if (year > 1868) { Fmeiji = true; } else if (year == 1868 && month > 9) { Fmeiji = true; } else if (year == 1868 && month == 9 && day >= 8) { Fmeiji = true; } else { Fmeiji = false; } } void taisho(int year, int month, int day) { if (year > 1912) { Ftaisho = true; } else if (year == 1912 && month > 7) { Ftaisho = true; } else if (year == 1912 && month == 7 && day >= 30) { Ftaisho = true; } else { Ftaisho = false; } } void showa(int year, int month, int day) { if (year > 1926) { Fshowa = true; } else if (year == 1926 && month > 12) { Fshowa = true; } else if (year == 1926 && month == 12 && day >= 25) { Fshowa = true; } else { Fshowa = false; } } void heisei(int year, int month, int day) { if (year > 1989) { Fheisei = true; } else if (year == 1989 && month > 1) { Fheisei = true; } else if (year == 1989 && month == 1 && day >= 8) { Fheisei = true; } else { Fheisei = false; } }
replace
10
12
10
11
TLE
p00085
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main() { int total, step; vector<int> person; vector<int>::iterator it; int i, m; while (1) { // get input cin >> total >> step; // finish condition if (total == 0 && step == 0) break; // init for (i = 1; i <= total; i++) { person.push_back(i); } it = person.begin(); while (1) { // answer if (person.size() == 1) { cout << person[0] << endl; person.clear(); break; } // step forward for (m = 0; m < (step - 1); m++) { it++; if (it == person.end()) { it = person.begin(); } } // delete person.erase(it); if (it == person.end()) { it = person.begin(); } for (int k = 0; k < person.size(); k++) { cout << *it << "is erased " << person[k] << endl; } } } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int total, step; vector<int> person; vector<int>::iterator it; int i, m; while (1) { // get input cin >> total >> step; // finish condition if (total == 0 && step == 0) break; // init for (i = 1; i <= total; i++) { person.push_back(i); } it = person.begin(); while (1) { // answer if (person.size() == 1) { cout << person[0] << endl; person.clear(); break; } // step forward for (m = 0; m < (step - 1); m++) { it++; if (it == person.end()) { it = person.begin(); } } // delete person.erase(it); if (it == person.end()) { it = person.begin(); } // for(int k = 0; k < person.size(); k++){ // cout << *it <<"is erased " << person[k] << endl; // } } } return 0; }
replace
46
49
46
49
TLE
p00085
C++
Runtime Error
#include <iostream> #include <queue> using namespace std; int main() { int n, m; queue<int> qu; while (1) { cin >> n >> m; if (!n && !m) break; for (int i = 1; i <= n; i++) qu.push(i); int cnt = 0; while (qu.front() != qu.back()) { int buf = qu.front(); qu.pop(); qu.push(buf); cnt++; if (cnt % (m - 1) == 0) { qu.pop(); } } cout << qu.back() << endl; qu.pop(); } return 0; }
#include <iostream> #include <queue> using namespace std; int main() { int n, m; queue<int> qu; while (1) { cin >> n >> m; if (!n && !m) break; for (int i = 1; i <= n; i++) qu.push(i); int cnt = 0; while (qu.front() != qu.back()) { int buf = qu.front(); qu.pop(); if (++cnt % m != 0) qu.push(buf); } cout << qu.back() << endl; qu.pop(); } return 0; }
replace
17
22
17
19
0
p00085
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n, m, pc, count; while (cin >> n >> m) { if (n == 0 && m == 0) break; int p[n + 1]; p[0] = 0; pc = n; count = 0; for (int i = 1; i <= n; i++) p[i] = 1; while (pc != 1) { for (int i = 1; i <= n; i++) { if (p[i] == 1) count++; if (count == m) { p[i] = 0; pc--; if (pc == -1) break; count = 0; } } } for (int i = 1; i <= n; i++) { if (p[i] == 1) cout << i << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int n, m, pc, count; while (cin >> n >> m) { if (n == 0 && m == 0) break; int p[n + 1]; p[0] = 0; pc = n; count = 0; for (int i = 1; i <= n; i++) p[i] = 1; while (pc != 1) { for (int i = 1; i <= n; i++) { if (p[i] == 1) count++; if (count == m) { p[i] = 0; pc--; if (pc == 1) break; count = 0; } } } for (int i = 1; i <= n; i++) { if (p[i] == 1) cout << i << endl; } } return 0; }
replace
20
21
20
21
TLE
p00085
C++
Time Limit Exceeded
#include <iostream> #include <stdio.h> using namespace std; int main() { int hito[1000]; int m, n; int a; int counter = 0; int counter2 = 0; int k = 0; while (1) { cin >> n >> m; if (n == 0 && m == 0) { break; } for (int i = 0; i < n; i++) { hito[i] = 1; } while (1) { if (hito[k] == 1) { counter++; } if (counter == m) { hito[k] = 0; counter = 0; counter2++; } if (counter2 == n) { cout << k << endl; } k++; if (k >= n) { k = 0; } } } return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main() { int hito[1000]; int m, n; int a; int counter = 0; int counter2 = 0; int k = 0; while (1) { cin >> n >> m; if (n == 0 && m == 0) { break; } for (int i = 0; i < n; i++) { hito[i] = 1; } while (1) { if (hito[k] == 1) { counter++; } if (counter == m) { hito[k] = 0; counter = 0; counter2++; } if (counter2 == n) { cout << k + 1 << endl; counter = 0; counter2 = 0; k = 0; break; } k++; if (k >= n) { k = 0; } } } return 0; }
replace
37
38
37
42
TLE
p00086
C++
Time Limit Exceeded
#include <cstdio> #include <cstring> using namespace std; int list[100]; int main(void) { int a, b; bool flag = false; while (scanf("%d %d", &a, &b)) { memset(list, 0, 100); list[a - 1]++; list[b - 1]++; while (true) { scanf("%d %d", &a, &b); if (!a && !b) break; list[a - 1]++; list[b - 1]++; } flag = false; if (!(list[0] & 1) || !(list[1] & 1)) flag = true; for (int i = 2; i < 100; i++) { if (list[i] & 1) flag = true; } if (!flag) printf("OK\n"); else printf("NG\n"); } return 0; }
#include <cstdio> #include <cstring> using namespace std; int list[100]; int main(void) { int a, b; bool flag = false; while (scanf("%d %d", &a, &b) != EOF) { memset(list, 0, 100); list[a - 1]++; list[b - 1]++; while (true) { scanf("%d %d", &a, &b); if (!a && !b) break; list[a - 1]++; list[b - 1]++; } flag = false; if (!(list[0] & 1) || !(list[1] & 1)) flag = true; for (int i = 2; i < 100; i++) { if (list[i] & 1) flag = true; } if (!flag) printf("OK\n"); else printf("NG\n"); } return 0; }
replace
9
10
9
10
TLE
p00086
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main(int argc, const char *argv[]) { while (1) { vector<int> G[100]; int a, b; while (1) { if (!cin >> a >> b) { return 0; } if (a == 0 && b == 0) { break; } a--; b--; G[a].push_back(b); G[b].push_back(a); } if (G[0].size() % 2 == 1 && G[1].size() % 2 == 1) { int c = 0; for (int i = 0; i < 100; i++) { if (G[i].size() % 2 == 1) { c++; } } if (c == 2) { cout << "OK" << endl; } else { cout << "NG" << endl; } } else { cout << "NG" << endl; } } return 0; }
#include <iostream> #include <vector> using namespace std; int main(int argc, const char *argv[]) { while (1) { vector<int> G[100]; int a, b; while (1) { if (!(cin >> a >> b)) { return 0; } if (a == 0 && b == 0) { break; } a--; b--; G[a].push_back(b); G[b].push_back(a); } if (G[0].size() % 2 == 1 && G[1].size() % 2 == 1) { int c = 0; for (int i = 0; i < 100; i++) { if (G[i].size() % 2 == 1) { c++; } } if (c == 2) { cout << "OK" << endl; } else { cout << "NG" << endl; } } else { cout << "NG" << endl; } } return 0; }
replace
8
9
8
9
-11
p00086
C++
Runtime Error
// coding on smartphone #include <iostream> using namespace std; int main() { int a, b; while (cin >> a >> b) { int deg[51] = {}; deg[a]++, deg[b]++; while (cin >> a >> b, a + b) deg[a]++, deg[b]++; bool judge = deg[1] % 2 == 1 && deg[2] % 2 == 1; for (int i = 3; i < 51; i++) if (deg[i] % 2) judge = false; if (judge) cout << "OK" << endl; else cout << "NG" << endl; } return 0; }
// coding on smartphone #include <iostream> using namespace std; int main() { int a, b; while (cin >> a >> b) { int deg[101] = {}; deg[a]++, deg[b]++; while (cin >> a >> b, a + b) deg[a]++, deg[b]++; bool judge = deg[1] % 2 == 1 && deg[2] % 2 == 1; for (int i = 3; i < 51; i++) if (deg[i] % 2) judge = false; if (judge) cout << "OK" << endl; else cout << "NG" << endl; } return 0; }
replace
7
8
7
8
0
p00086
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORR(i, a, b) for (int i = (a); i > (b); i--) #define REP(i, n) FOR(i, 0, n) // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // debug //------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; vector<int> intersection[103]; int search() { int odd = 0; if (intersection[1].size() % 2 != 1 || intersection[2].size() % 2 != 1) { return 0; } FOR(i, 3, 103) { if (intersection[i].size() % 2 == 1) { debug(i); debug(intersection[i].size()); return 0; } } return 1; } void init() { REP(i, 103) { intersection[i].clear(); intersection[i].shrink_to_fit(); } } int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int s, d; cin >> s >> d; if (cin.eof()) break; intersection[s].push_back(d); intersection[d].push_back(s); if (!s && !d) { if (search()) { cout << "OK" << endl; } else { cout << "NG" << endl; } init(); } } return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORR(i, a, b) for (int i = (a); i > (b); i--) #define REP(i, n) FOR(i, 0, n) // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // debug //------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; vector<int> intersection[103]; int search() { int odd = 0; if (intersection[1].size() % 2 != 1 || intersection[2].size() % 2 != 1) { return 0; } FOR(i, 3, 103) { if (intersection[i].size() % 2 == 1) { return 0; } } return 1; } void init() { REP(i, 103) { intersection[i].clear(); intersection[i].shrink_to_fit(); } } int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int s, d; cin >> s >> d; if (cin.eof()) break; intersection[s].push_back(d); intersection[d].push_back(s); if (!s && !d) { if (search()) { cout << "OK" << endl; } else { cout << "NG" << endl; } init(); } } return 0; }
delete
61
63
61
61
0
i = 3 (L51) /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00086/C++/s032715447.cpp intersection[i].size() = 3 (L52) /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p00086/C++/s032715447.cpp
p00087
C++
Runtime Error
#include <cstdlib> #include <iomanip> #include <iostream> #include <sstream> #include <stack> #include <string> double calc(char op, double a, double b) { switch (op) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': return a / b; } } int main() { std::string str; while (std::getline(std::cin, str)) { std::stack<double> s; std::istringstream iss(str); std::string item; while (iss >> item) { if (item[0] == '+' || item[0] == '-' || item[0] == '*' || item[0] == '/') { double b = s.top(); s.pop(); double a = s.top(); s.pop(); s.push(calc(item[0], a, b)); } else s.push(atof(item.c_str())); } std::cout << std::fixed << std::setprecision(6) << s.top() << std::endl; } return 0; }
#include <cstdlib> #include <iomanip> #include <iostream> #include <sstream> #include <stack> #include <string> double calc(char op, double a, double b) { switch (op) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': return a / b; } } int main() { std::string str; while (std::getline(std::cin, str)) { std::stack<double> s; std::istringstream iss(str); std::string item; while (iss >> item) { if (item == "+" || item == "-" || item == "*" || item == "/") { double b = s.top(); s.pop(); double a = s.top(); s.pop(); s.push(calc(item[0], a, b)); } else s.push(atof(item.c_str())); } std::cout << std::fixed << std::setprecision(6) << s.top() << std::endl; } return 0; }
replace
28
30
28
29
-11
p00087
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; /* int stringToint(const string S) { int result=0; if(S[0]=='-') { for(int i=1;i<S.length();i++) { result=10*result+(S[i]-'0'); } result=-result; } else { for(int i=0;i<S.length();i++) { result=10*result+(S[i]-'0'); } } return result; } */ int main() { string s; string word; stack<double> mm; while (cin >> word) { if (word == "+" || word == "-" || word == "*" || word == "/") { double a = mm.top(); mm.pop(); double b = mm.top(); mm.pop(); double result; if (word == "+") result = b + a; else if (word == "-") result = b - a; else if (word == "*") result = b * a; else result = b / a; mm.push(result); } else if (word.length() == 2 && word[0] == '-' || (isdigit(word[0]))) { // double kk=1.0*(stringToint(word)); mm.push(atoi(word.c_str())); // mm.push(kk); } if (getchar() == '\n') { double final_result = mm.top(); printf("%.10lf\n", final_result); mm.pop(); } } // while(1); return 0; }
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; /* int stringToint(const string S) { int result=0; if(S[0]=='-') { for(int i=1;i<S.length();i++) { result=10*result+(S[i]-'0'); } result=-result; } else { for(int i=0;i<S.length();i++) { result=10*result+(S[i]-'0'); } } return result; } */ int main() { string s; string word; stack<double> mm; while (cin >> word) { if (word == "+" || word == "-" || word == "*" || word == "/") { double a = mm.top(); mm.pop(); double b = mm.top(); mm.pop(); double result; if (word == "+") result = b + a; else if (word == "-") result = b - a; else if (word == "*") result = b * a; else result = b / a; mm.push(result); } else if (word.length() >= 2 && word[0] == '-' || (isdigit(word[0]))) { // double kk=1.0*(stringToint(word)); mm.push(atoi(word.c_str())); // mm.push(kk); } if (getchar() == '\n') { double final_result = mm.top(); printf("%.10lf\n", final_result); mm.pop(); } } // while(1); return 0; }
replace
66
67
66
67
0
p00087
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second static const double PI = 6 * asin(0.5); typedef pair<double, double> P; typedef complex<double> CP; typedef long long ll; string s; int main() { while (getline(cin, s)) { stack<double> st; rep(i, s.size()) { // cout<<"size "<<s.size()<<endl; if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') { double a1, a2; a2 = st.top(); st.pop(); a1 = st.top(); st.pop(); if (s[i] == '+') { a1 += a2; } else if (s[i] == '-') { a1 -= a2; } else if (s[i] == '*') { a1 *= a2; } else if (s[i] == '/') { a1 /= a2; } st.push(a1); } else if (s[i] <= '9' && s[i] >= '0') { double sum = 0.0; for (int j = i; j < s.size(); j++) { if (s[j] <= '9' && s[j] >= '0') { sum *= 10.0; sum += s[j] - '0'; } else break; i = j; } st.push(sum); } // cout<<"st.top = "<<st.top()<<endl; } printf("%.6f\n", st.top()); st.pop(); } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second static const double PI = 6 * asin(0.5); typedef pair<double, double> P; typedef complex<double> CP; typedef long long ll; string s; int main() { while (getline(cin, s)) { stack<double> st; rep(i, s.size()) { // cout<<"size "<<s.size()<<endl; if (s[i] == '-' && s[i + 1] <= '9' && s[i + 1] >= '0') { double sum = 0.0; for (int j = i + 1; j < s.size(); j++) { if (s[j] <= '9' && s[j] >= '0') { sum *= 10.0; sum += s[j] - '0'; } else break; i = j; } sum = -sum; st.push(sum); } else if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') { double a1, a2; a2 = st.top(); st.pop(); a1 = st.top(); st.pop(); if (s[i] == '+') { a1 += a2; } else if (s[i] == '-') { a1 -= a2; } else if (s[i] == '*') { a1 *= a2; } else if (s[i] == '/') { a1 /= a2; } st.push(a1); } else if (s[i] <= '9' && s[i] >= '0') { double sum = 0.0; for (int j = i; j < s.size(); j++) { if (s[j] <= '9' && s[j] >= '0') { sum *= 10.0; sum += s[j] - '0'; } else break; i = j; } st.push(sum); } // cout<<"st.top = "<<st.top()<<endl; } printf("%.6f\n", st.top()); st.pop(); } return 0; }
replace
32
33
32
48
-11
p00087
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; #define dump(n) cout << "# " << #n << "=" << (n) << endl #define debug(n) \ cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, n) repi(i, 0, n) #define iter(c) __typeof((c).begin()) #define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define allof(c) (c).begin(), (c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; double solve(vs &ss) { stack<double> st; rep(i, ss.size()) { if (isdigit(ss[i][0])) st.push(atof(ss[i].c_str())); else { double a, b; b = st.top(); st.pop(); a = st.top(); st.pop(); switch (ss[i][0]) { case '+': st.push(a + b); break; case '-': st.push(a - b); break; case '*': st.push(a * b); break; case '/': st.push(a / b); break; } } } return st.top(); } int main() { for (string s; getline(cin, s);) { istringstream iss(s); vs ss; for (string s; iss >> s; ss.push_back(s)) ; printf("%f\n", solve(ss)); } 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; #define dump(n) cout << "# " << #n << "=" << (n) << endl #define debug(n) \ cout << __FILE__ << "," << __LINE__ << ": #" << #n << "=" << (n) << endl #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define rep(i, n) repi(i, 0, n) #define iter(c) __typeof((c).begin()) #define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++) #define allof(c) (c).begin(), (c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; double solve(vs &ss) { stack<double> st; rep(i, ss.size()) { if (isdigit(ss[i][ss[i].size() - 1])) st.push(atof(ss[i].c_str())); else { double a, b; b = st.top(); st.pop(); a = st.top(); st.pop(); switch (ss[i][0]) { case '+': st.push(a + b); break; case '-': st.push(a - b); break; case '*': st.push(a * b); break; case '/': st.push(a / b); break; } } } return st.top(); } int main() { for (string s; getline(cin, s);) { istringstream iss(s); vs ss; for (string s; iss >> s; ss.push_back(s)) ; printf("%f\n", solve(ss)); } return 0; }
replace
49
50
49
50
-11
p00087
C++
Runtime Error
#include <iomanip> #include <iostream> #include <stack> #include <string> using namespace std; string S, U[1000]; stack<double> T; int cnt; double a, b; int main() { while (getline(cin, S)) { cnt = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == ' ') { cnt++; } else { U[cnt] += S[i]; } } cnt++; for (int i = 0; i < cnt; i++) { if (U[i] == "+") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(a + b); } else if (U[i] == "-") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(b - a); } else if (U[i] == "*") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(a * b); } else if (U[i] == "/") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(b / a); } else { T.push(stoi(U[i])); } } cout << fixed << setprecision(20) << T.top() << endl; T.pop(); } }
#include <iomanip> #include <iostream> #include <stack> #include <string> using namespace std; string S, U[1000]; stack<double> T; int cnt; double a, b; int main() { while (getline(cin, S)) { for (int i = 0; i < 1000; i++) { U[i] = ""; } cnt = 0; for (int i = 0; i < S.size(); i++) { if (S[i] == ' ') { cnt++; } else { U[cnt] += S[i]; } } cnt++; for (int i = 0; i < cnt; i++) { if (U[i] == "+") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(a + b); } else if (U[i] == "-") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(b - a); } else if (U[i] == "*") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(a * b); } else if (U[i] == "/") { a = T.top(); T.pop(); b = T.top(); T.pop(); T.push(b / a); } else { T.push(stoi(U[i])); } } cout << fixed << setprecision(20) << T.top() << endl; T.pop(); } }
insert
11
11
11
14
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoi
p00087
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string s; while (getline(cin, s)) { stringstream ss(s); stack<double> stk; while (ss >> s) { if (isdigit(s[0])) { stk.push(atof(s.c_str())); } else { double b = stk.top(); stk.pop(); double a = stk.top(); stk.pop(); double res = 0; switch (s[0]) { case '+': res = a + b; break; case '-': res = a - b; break; case '*': res = a * b; break; case '/': res = a / b; break; } stk.push(res); } } printf("%.10f\n", stk.top()); } return 0; }
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string s; while (getline(cin, s)) { stringstream ss(s); stack<double> stk; while (ss >> s) { if (isdigit(*s.rbegin())) { stk.push(atof(s.c_str())); } else { double b = stk.top(); stk.pop(); double a = stk.top(); stk.pop(); double res = 0; switch (s[0]) { case '+': res = a + b; break; case '-': res = a - b; break; case '*': res = a * b; break; case '/': res = a / b; break; } stk.push(res); } } printf("%.10f\n", stk.top()); } return 0; }
replace
16
17
16
17
-11
p00087
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define DUMP(x) cerr << #x << "=" << x << endl #define DUMP2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl #define BINARY(x) static_cast<bitset<16>>(x) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, m, n) for (int i = m; i < (int)(n); i++) #define in_range(x, y, w, h) \ (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h)) #define ALL(a) (a).begin(), (a).end() typedef long long ll; const int INF = 1e9; typedef pair<int, int> PII; int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1}; int main() { string line; while (true) { getline(cin, line); if (cin.eof()) break; stack<double> st; stringstream ss(line); while (!ss.eof()) { string S; ss >> S; if (isdigit(S[0])) { int num = stoi(S); st.push(num); } else { double b = st.top(); st.pop(); double a = st.top(); st.pop(); if (S == "-") st.push(a - b); if (S == "+") st.push(a + b); if (S == "*") st.push(a * b); if (S == "/") st.push(a / b); } } cout << fixed << setprecision(10) << st.top() << endl; } }
#include <bits/stdc++.h> using namespace std; #define DUMP(x) cerr << #x << "=" << x << endl #define DUMP2(x, y) \ cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl #define BINARY(x) static_cast<bitset<16>>(x) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, m, n) for (int i = m; i < (int)(n); i++) #define in_range(x, y, w, h) \ (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h)) #define ALL(a) (a).begin(), (a).end() typedef long long ll; const int INF = 1e9; typedef pair<int, int> PII; int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1}; int main() { string line; while (true) { getline(cin, line); if (cin.eof()) break; stack<double> st; stringstream ss(line); while (!ss.eof()) { string S; ss >> S; if (isdigit(S[0]) || S.size() > 1) { int num = stoi(S); st.push(num); } else { double b = st.top(); st.pop(); double a = st.top(); st.pop(); if (S == "-") st.push(a - b); if (S == "+") st.push(a + b); if (S == "*") st.push(a * b); if (S == "/") st.push(a / b); } } cout << fixed << setprecision(10) << st.top() << endl; } }
replace
33
34
33
34
-11
p00087
C++
Runtime Error
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int main() { while (true) { stack<double> s; char In[81]; double num = 0; bool is_pos = true; int r; for (int i = 0; r = scanf("%c", &In[i]); i++) { if (In[i] == '\n') break; if (r == EOF) return 0; } for (int i = 0; In[i] != '\n'; i++) { if (In[i] == ' ') continue; if ('0' <= In[i] && In[i] <= '9') { num = num * 10 + (In[i] - '0'); if (In[i + 1] == ' ') { if (is_pos == false) num *= -1; s.push(num); num = 0; is_pos = true; } } else { if (In[i] == '-' && '0' <= In[i + 1] && In[i + 1] <= '9') { is_pos = false; } else { double a, b; b = s.top(); s.pop(); a = s.top(); s.pop(); if (In[i] == '+') s.push(a + b); else if (In[i] == '-') s.push(a - b); else if (In[i] == '*') s.push(a * b); else s.push(a / b); } } } printf("%lf\n", s.top()); } return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; int main() { while (true) { stack<double> s; char In[81]; double num = 0; bool is_pos = true; int r; for (int i = 0; r = scanf("%c", &In[i]); i++) { if (In[i] == '\n') break; if (r == EOF) return 0; } for (int i = 0; In[i] != '\n'; i++) { if (In[i] == ' ') continue; if ('0' <= In[i] && In[i] <= '9') { num = num * 10 + (In[i] - '0'); if (In[i + 1] < '0' || '9' < In[i + 1]) { if (is_pos == false) num *= -1; s.push(num); num = 0; is_pos = true; } } else { if (In[i] == '-' && '0' <= In[i + 1] && In[i + 1] <= '9') { is_pos = false; } else { double a, b; b = s.top(); s.pop(); a = s.top(); s.pop(); if (In[i] == '+') s.push(a + b); else if (In[i] == '-') s.push(a - b); else if (In[i] == '*') s.push(a * b); else s.push(a / b); } } } printf("%lf\n", s.top()); } return 0; }
replace
34
35
34
35
0
p00087
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iostream> #include <stack> #include <string> using namespace std; int main() { double x, y; string s; while (getline(cin, s)) { stack<double> box; s = s + '\0'; for (int i = 0; i < (int)s.size() - 1; i++) { if (s[i] == '-') { if (!isdigit(s[i + 1])) { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y - x); } else { box.push(-atof(&s[i + 1])); for (i += 1; s[i] != ' '; i++) ; } } else if (s[i] == '+') { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y + x); } else if (s[i] == '*') { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y * x); } else if (s[i] == '/') { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y / x); } else if (isdigit(s[i])) { box.push(atof(&s[i])); for (; s[i] != ' '; i++) ; } } if (!box.empty()) { printf("%.6lf\n", box.top()); } } return 0; }
#include <cstdio> #include <cstdlib> #include <iostream> #include <stack> #include <string> using namespace std; int main() { double x, y; string s; while (getline(cin, s)) { stack<double> box; s = s + ' '; for (int i = 0; i < (int)s.size() - 1; i++) { if (s[i] == '-') { if (!isdigit(s[i + 1])) { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y - x); } else { box.push(-atof(&s[i + 1])); for (i += 1; s[i] != ' '; i++) ; } } else if (s[i] == '+') { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y + x); } else if (s[i] == '*') { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y * x); } else if (s[i] == '/') { x = box.top(); box.pop(); y = box.top(); box.pop(); box.push(y / x); } else if (isdigit(s[i])) { box.push(atof(&s[i])); for (; s[i] != ' '; i++) ; } } if (!box.empty()) { printf("%.6lf\n", box.top()); } } return 0; }
replace
11
12
11
12
0
p00087
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> st; stringstream ss; ss << str; string item; while (ss >> item) { char c = item.at(0); if (c == '+' || c == '-' || c == '*' || c == '/') { double a, b; b = st.top(); st.pop(); a = st.top(); st.pop(); if (c == '+') st.push(a + b); else if (c == '-') st.push(a - b); else if (c == '*') st.push(a * b); else st.push(a / b); } else { st.push(atof(item.c_str())); } } printf("%f\n", st.top()); } return 0; }
#include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> st; stringstream ss; ss << str; string item; while (ss >> item) { char c = item.at(0); if (c == '+' || (c == '-' && item.length() == 1) || c == '*' || c == '/') { double a, b; b = st.top(); st.pop(); a = st.top(); st.pop(); if (c == '+') st.push(a + b); else if (c == '-') st.push(a - b); else if (c == '*') st.push(a * b); else st.push(a / b); } else { st.push(atof(item.c_str())); } } printf("%f\n", st.top()); } return 0; }
replace
20
21
20
22
-11
p00087
C++
Runtime Error
#include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> S; stringstream sin(str); string temp; while (sin >> temp) { switch (temp[0]) { double a, b; case '+': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b + a); break; case '-': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b - a); break; case '*': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b * a); break; case '/': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b / a); break; default: stringstream s1(temp); double d; s1 >> d; S.push(d); } } printf("%.6f\n", S.top()); } return 0; }
#include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> S; stringstream sin(str); string temp; while (sin >> temp) { bool flag = false; if (temp.length() == 1) { flag = true; switch (temp[0]) { double a, b; case '+': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b + a); break; case '-': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b - a); break; case '*': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b * a); break; case '/': a = S.top(); S.pop(); b = S.top(); S.pop(); S.push(b / a); break; default: flag = false; } } if (!flag) { stringstream s1(temp); double d; s1 >> d; S.push(d); } } printf("%.6f\n", S.top()); } return 0; }
replace
14
45
14
52
-11
p00087
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) int main() { while (1) { string str; getline(cin, str); if (cin.eof()) break; vector<bool> isnum; rep(i, str.size()) { if (i == 0 || str[i - 1] == ' ') { char c = str[i]; if (c >= '0' && c <= '9') isnum.push_back(true); else isnum.push_back(false); } } stringstream sst; sst << str; stack<double> t; rep(i, isnum.size()) { if (isnum[i]) { int a; sst >> a; t.push((double)a); } else { char c; sst >> c; double b = t.top(); t.pop(); double a = t.top(); t.pop(); if (c == '*') { t.push(a * b); } if (c == '+') { t.push(a + b); } if (c == '-') { t.push(a - b); } if (c == '/') { t.push(a / b); } } } printf("%.8lf\n", t.top()); } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) int main() { while (1) { string str; getline(cin, str); if (cin.eof()) break; vector<bool> isnum; rep(i, str.size()) { if (i == str.size() - 1 || str[i + 1] == ' ') { char c = str[i]; if (c >= '0' && c <= '9') isnum.push_back(true); else isnum.push_back(false); } } stringstream sst; sst << str; stack<double> t; rep(i, isnum.size()) { if (isnum[i]) { int a; sst >> a; t.push((double)a); } else { char c; sst >> c; double b = t.top(); t.pop(); double a = t.top(); t.pop(); if (c == '*') { t.push(a * b); } if (c == '+') { t.push(a + b); } if (c == '-') { t.push(a - b); } if (c == '/') { t.push(a / b); } } } printf("%.8lf\n", t.top()); } }
replace
27
28
27
28
-11
p00087
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; #define TT template <typename T> #define ET(T) typename T::value_type TT inline T sq(T x) { return x * x; } TT inline T In() { T x; cin >> x; return x; } TT inline int ubnd(T &v, ET(T) x) { return upper_bound(begin(v), end(v), x) - begin(v); } TT inline int lbnd(T &v, ET(T) x) { return lower_bound(begin(v), end(v), x) - begin(v); } TT inline void sort(T &v) { sort(begin(v), end(v)); } TT inline void revs(T &v) { reverse(begin(v), end(v)); } TT inline void uniq(T &v) { sort(v); v.erase(unique(begin(v), end(v)), end(v)); } TT inline void inpt(T &v, int n, function<ET(T)()> f = In<ET(T)>) { for (v.reserve(n); n--; v.emplace_back(f())) ; } TT inline void show(T &v, string d = " ", string e = "\n") { int i = 0; for (auto &x : v) i++ && (cout << d), cout << x; cout << e; } #undef TT #undef ET inline void fast_io() { ios::sync_with_stdio(0); cin.tie(0); } inline int in() { int x; scanf("%d", &x); return x; } inline string instr() { string x; cin >> x; return x; } inline ll pow_mod(ll a, ll k, ll m) { ll r = 1; for (; k > 0; a = a * a % m, k >>= 1) if (k & 1) r = r * a % m; return r; } inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); } const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const int Mod = 1000000000; bool is_digit(const string &s) { if (s.size() == 1) return isdigit(s[0]); return (s[0] == '+' || s[0] == '-') && isdigit(s[1]); } int main() { string line; while (getline(cin, line)) { stringstream ss(line); string e; stack<ld> st; while (ss >> e) { if (is_digit(e)) st.push(stof(e)); else { ld a, b; a = st.top(); st.pop(); b = st.top(); st.pop(); if (e == "+") st.push(b + a); if (e == "-") st.push(b - a); if (e == "*") st.push(b * a); if (e == "/") st.push(b / a); } } printf("%Lf\n", st.top()); } return (0); } // priority_queue queue deque front top push pop map set stringstream // max_element min_element insert count find get tie make_tuple
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; #define TT template <typename T> #define ET(T) typename T::value_type TT inline T sq(T x) { return x * x; } TT inline T In() { T x; cin >> x; return x; } TT inline int ubnd(T &v, ET(T) x) { return upper_bound(begin(v), end(v), x) - begin(v); } TT inline int lbnd(T &v, ET(T) x) { return lower_bound(begin(v), end(v), x) - begin(v); } TT inline void sort(T &v) { sort(begin(v), end(v)); } TT inline void revs(T &v) { reverse(begin(v), end(v)); } TT inline void uniq(T &v) { sort(v); v.erase(unique(begin(v), end(v)), end(v)); } TT inline void inpt(T &v, int n, function<ET(T)()> f = In<ET(T)>) { for (v.reserve(n); n--; v.emplace_back(f())) ; } TT inline void show(T &v, string d = " ", string e = "\n") { int i = 0; for (auto &x : v) i++ && (cout << d), cout << x; cout << e; } #undef TT #undef ET inline void fast_io() { ios::sync_with_stdio(0); cin.tie(0); } inline int in() { int x; scanf("%d", &x); return x; } inline string instr() { string x; cin >> x; return x; } inline ll pow_mod(ll a, ll k, ll m) { ll r = 1; for (; k > 0; a = a * a % m, k >>= 1) if (k & 1) r = r * a % m; return r; } inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); } const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; const int Mod = 1000000000; bool is_digit(const string &s) { if (isdigit(s[0])) return true; return (s[0] == '+' || s[0] == '-') && isdigit(s[1]); } int main() { string line; while (getline(cin, line)) { stringstream ss(line); string e; stack<ld> st; while (ss >> e) { if (is_digit(e)) st.push(stof(e)); else { ld a, b; a = st.top(); st.pop(); b = st.top(); st.pop(); if (e == "+") st.push(b + a); if (e == "-") st.push(b - a); if (e == "*") st.push(b * a); if (e == "/") st.push(b / a); } } printf("%Lf\n", st.top()); } return (0); } // priority_queue queue deque front top push pop map set stringstream // max_element min_element insert count find get tie make_tuple
replace
68
70
68
70
-11
p00087
C++
Runtime Error
// Name: Strange Mathematical Expression // Level: 1 // Category: 逆ポーランド記法,やるだけ // Note: #include <cctype> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); string line; while (getline(cin, line) && !cin.eof()) { istringstream is(line); stack<double> stk; string token; while (is >> token) { if (isdigit(token[0])) { stk.push(atof(token.c_str())); } else { double b = stk.top(); stk.pop(); double a = stk.top(); stk.pop(); switch (token[0]) { case '+': stk.push(a + b); break; case '-': stk.push(a - b); break; case '*': stk.push(a * b); break; case '/': stk.push(a / b); break; } } } printf("%.10f\n", stk.top()); } return 0; }
// Name: Strange Mathematical Expression // Level: 1 // Category: 逆ポーランド記法,やるだけ // Note: #include <cctype> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(0); string line; while (getline(cin, line) && !cin.eof()) { istringstream is(line); stack<double> stk; string token; while (is >> token) { if (isdigit(token[0]) || token.size() >= 2) { stk.push(atof(token.c_str())); } else { double b = stk.top(); stk.pop(); double a = stk.top(); stk.pop(); switch (token[0]) { case '+': stk.push(a + b); break; case '-': stk.push(a - b); break; case '*': stk.push(a * b); break; case '/': stk.push(a / b); break; } } } printf("%.10f\n", stk.top()); } return 0; }
replace
25
26
25
26
-11
p00087
C++
Runtime Error
#include <algorithm> #include <math.h> #include <stack> #include <stdio.h> using namespace std; int main() { char buf[200]; stack<double> S; double tmp, op1, op2; bool numFLG, negFLG; while (fgets(buf, 200, stdin) != 0) { numFLG = false; negFLG = false; tmp = 0; for (int i = 0; buf[i] != '\n' && buf[i] != '\0'; i++) { if (buf[i] >= '0' && buf[i] <= '9') { numFLG = true; tmp = 10 * tmp + (buf[i] - '0'); if (buf[i + 1] == '\n' || buf[i + 1] == '\0') { if (negFLG) { tmp = -1 * tmp; negFLG = false; } S.push(tmp); } } else { if (numFLG) { numFLG = false; if (negFLG) { tmp = -1 * tmp; negFLG = false; } S.push(tmp); tmp = 0; } if (buf[i] == ' ') { // Do nothing } else if (buf[i] == '+') { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 + op2); } else if (buf[i] == '-') { if (i == 0 || (i >= 2 && (buf[i - 2] == '+' || buf[i - 2] == '-' || buf[i - 2] == '*' || buf[i - 2] == '/'))) { negFLG = true; } else { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 - op2); } } else if (buf[i] == '*') { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 * op2); } else if (buf[i] == '/') { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 / op2); } } } printf("%.6lf\n", S.top()); S.pop(); } return 0; }
#include <algorithm> #include <math.h> #include <stack> #include <stdio.h> using namespace std; int main() { char buf[200]; stack<double> S; double tmp, op1, op2; bool numFLG, negFLG; while (fgets(buf, 200, stdin) != 0) { numFLG = false; negFLG = false; tmp = 0; for (int i = 0; buf[i] != '\n' && buf[i] != '\0'; i++) { if (buf[i] >= '0' && buf[i] <= '9') { numFLG = true; tmp = 10 * tmp + (buf[i] - '0'); if (buf[i + 1] == '\n' || buf[i + 1] == '\0') { if (negFLG) { tmp = -1 * tmp; negFLG = false; } S.push(tmp); } } else { if (numFLG) { numFLG = false; if (negFLG) { tmp = -1 * tmp; negFLG = false; } S.push(tmp); tmp = 0; } if (buf[i] == ' ') { // Do nothing } else if (buf[i] == '+') { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 + op2); } else if (buf[i] == '-') { if (buf[i + 1] != '\n' && buf[i + 1] >= '0' && buf[i + 1] <= '9') { negFLG = true; } else { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 - op2); } } else if (buf[i] == '*') { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 * op2); } else if (buf[i] == '/') { op2 = S.top(); S.pop(); op1 = S.top(); S.pop(); S.push(op1 / op2); } } } printf("%.6lf\n", S.top()); S.pop(); } return 0; }
replace
50
52
50
51
-11
p00087
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { string str; while (getline(cin, str)) { stack<double> s; stringstream ss; ss << str; while (ss >> str) { if (str[0] >= '0' && str[0] <= '9' || s.size() > 1) { s.push(atoi(str.c_str())); } else { double a = s.top(); s.pop(); double b = s.top(); s.pop(); double c; if (str[0] == '+') c = a + b; else if (str[0] == '-') c = b - a; else if (str[0] == '*') c = a * b; else c = b / a; s.push(c); } } printf("%.6lf\n", s.top()); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { string str; while (getline(cin, str)) { stack<double> s; stringstream ss; ss << str; while (ss >> str) { if (str[0] >= '0' && str[0] <= '9' || str.length() > 1) { s.push(atoi(str.c_str())); } else { double a = s.top(); s.pop(); double b = s.top(); s.pop(); double c; if (str[0] == '+') c = a + b; else if (str[0] == '-') c = b - a; else if (str[0] == '*') c = a * b; else c = b / a; s.push(c); } } printf("%.6lf\n", s.top()); } return 0; }
replace
17
18
17
18
-11
p00087
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { string str; while (getline(cin, str)) { stack<double> s; stringstream ss; ss << str; while (ss >> str) { if (isdigit(str[0])) { s.push(atoi(str.c_str())); } else { double a = s.top(); s.pop(); double b = s.top(); s.pop(); double c; if (str[0] == '+') c = a + b; else if (str[0] == '-') c = b - a; else if (str[0] == '*') c = a * b; else c = b / a; s.push(c); } } printf("%.6lf\n", s.top()); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; #define rep2(x, from, to) for (int x = (from); x < (to); ++(x)) #define rep(x, to) rep2(x, 0, to) int main() { string str; while (getline(cin, str)) { stack<double> s; stringstream ss; ss << str; while (ss >> str) { if (isdigit(str[0]) || str.length() > 1) { s.push(atoi(str.c_str())); } else { double a = s.top(); s.pop(); double b = s.top(); s.pop(); double c; if (str[0] == '+') c = a + b; else if (str[0] == '-') c = b - a; else if (str[0] == '*') c = a * b; else c = b / a; s.push(c); } } printf("%.6lf\n", s.top()); } return 0; }
replace
18
19
18
19
-11
p00087
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <memory> #include <string> #include <algorithm> #include <bitset> #include <complex> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype #define strtok_r strtok_s #endif #define ITER(c) __typeof__((c).begin()) #define FOREACH(it, c) for (ITER(c) it = (c).begin(); it != (c).end(); ++it) #define RITER(c) __typeof__((c).rbegin()) #define RFOREACH(it, c) for (RITER(c) it = (c).rbegin(); it != (c).rend(); ++it) #define REP(i, n) REPEAT(i, 0, n) #define RREP(i, n) RREPEAT(i, 0, n); #define REPEAT(i, k, n) for (int i = (k); i < (k + n); ++i) #define RREPEAT(i, k, n) for (int i = (k) + (n)-1; i >= (k); ++i) #define ALL(c) (c).begin(), (c).end() #define LLPOW(p1, p2) ((ll)pow((double)(p1), (int)p2)) #define ESIZEOF(A) (sizeof(A) / sizeof((A)[0])) #define MIN(p1, p2) (((p1) < (p2)) ? (p1) : (p2)) #define MAX(p1, p2) (((p1) > (p2)) ? (p1) : (p2)) #define CIN_NO_SYNC \ do { \ cin.tie(0); \ ios_base::sync_with_stdio(false); \ } while (0) #define GETSTR(p) fgets((p), sizeof(p), stdin) #define CHOMP(p) \ do { \ char *_q = (p) + strlen(p) - 1; \ if (*_q == '\n' || *_q == '\r') \ *_q = 0; \ } while (0) #define mp make_pair #define pb push_back typedef long long ll; typedef unsigned long long ull; #define X real() #define Y imag() typedef double D; typedef complex<D> P; #define EPS (1e-9) #ifdef _DEBUG #define pf printf #define pr(n) \ do { \ cout << #n " = " << (n) << endl; \ } while (0) #else #define pf(...) /* */ #define pr(...) /* */ #endif void solve(string &s) { stack<double> st; char buf[120], *p, *ctx; strcpy(buf, s.c_str()); p = strtok_r(buf, " ", &ctx); while (p) { if (isdigit((unsigned char)p[0])) { st.push(atof(p)); } else { double p2 = st.top(); st.pop(); double p1 = st.top(); st.pop(); switch (p[0]) { case '+': st.push(p1 + p2); break; case '-': st.push(p1 - p2); break; case '*': st.push(p1 * p2); break; case '/': st.push(p1 / p2); break; } } p = strtok_r(NULL, " ", &ctx); } if (st.size() != 1) return; double ans = st.top(); printf("%.9f\n", ans); } int main() { string s; while (getline(cin, s)) { solve(s); } return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <memory> #include <string> #include <algorithm> #include <bitset> #include <complex> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype #define strtok_r strtok_s #endif #define ITER(c) __typeof__((c).begin()) #define FOREACH(it, c) for (ITER(c) it = (c).begin(); it != (c).end(); ++it) #define RITER(c) __typeof__((c).rbegin()) #define RFOREACH(it, c) for (RITER(c) it = (c).rbegin(); it != (c).rend(); ++it) #define REP(i, n) REPEAT(i, 0, n) #define RREP(i, n) RREPEAT(i, 0, n); #define REPEAT(i, k, n) for (int i = (k); i < (k + n); ++i) #define RREPEAT(i, k, n) for (int i = (k) + (n)-1; i >= (k); ++i) #define ALL(c) (c).begin(), (c).end() #define LLPOW(p1, p2) ((ll)pow((double)(p1), (int)p2)) #define ESIZEOF(A) (sizeof(A) / sizeof((A)[0])) #define MIN(p1, p2) (((p1) < (p2)) ? (p1) : (p2)) #define MAX(p1, p2) (((p1) > (p2)) ? (p1) : (p2)) #define CIN_NO_SYNC \ do { \ cin.tie(0); \ ios_base::sync_with_stdio(false); \ } while (0) #define GETSTR(p) fgets((p), sizeof(p), stdin) #define CHOMP(p) \ do { \ char *_q = (p) + strlen(p) - 1; \ if (*_q == '\n' || *_q == '\r') \ *_q = 0; \ } while (0) #define mp make_pair #define pb push_back typedef long long ll; typedef unsigned long long ull; #define X real() #define Y imag() typedef double D; typedef complex<D> P; #define EPS (1e-9) #ifdef _DEBUG #define pf printf #define pr(n) \ do { \ cout << #n " = " << (n) << endl; \ } while (0) #else #define pf(...) /* */ #define pr(...) /* */ #endif void solve(string &s) { stack<double> st; char buf[120], *p, *ctx; strcpy(buf, s.c_str()); p = strtok_r(buf, " ", &ctx); while (p) { if (isdigit((unsigned char)p[strlen(p) - 1])) { st.push(atof(p)); } else { double p2 = st.top(); st.pop(); double p1 = st.top(); st.pop(); switch (p[0]) { case '+': st.push(p1 + p2); break; case '-': st.push(p1 - p2); break; case '*': st.push(p1 * p2); break; case '/': st.push(p1 / p2); break; } } p = strtok_r(NULL, " ", &ctx); } if (st.size() != 1) return; double ans = st.top(); printf("%.9f\n", ans); } int main() { string s; while (getline(cin, s)) { solve(s); } return 0; }
replace
87
88
87
88
-11
p00087
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { for (;;) { string s; getline(cin, s); if (s.size() == 0) return 0; istringstream iss(s); stack<double> stk; for (;;) { string s1; if (iss >> s1) { if ('0' <= s1[0] && s1[0] <= '9') stk.push(atof(s1.c_str())); else { double x = stk.top(); stk.pop(); double y = stk.top(); stk.pop(); if (s1 == "+") stk.push(y + x); else if (s1 == "-") stk.push(y - x); else if (s1 == "*") stk.push(y * x); else stk.push(y / x); } } else break; } printf("%.10f\n", stk.top()); } }
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { for (;;) { string s; getline(cin, s); if (s.size() == 0) return 0; istringstream iss(s); stack<double> stk; for (;;) { string s1; if (iss >> s1) { if (s1.size() > 1 || ('0' <= s1[0] && s1[0] <= '9')) stk.push(atof(s1.c_str())); else { double x = stk.top(); stk.pop(); double y = stk.top(); stk.pop(); if (s1 == "+") stk.push(y + x); else if (s1 == "-") stk.push(y - x); else if (s1 == "*") stk.push(y * x); else stk.push(y / x); } } else break; } printf("%.10f\n", stk.top()); } }
replace
30
31
30
31
-11
p00087
C++
Runtime Error
#include <cctype> #include <cfloat> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; double a, b; while (getline(cin, str)) { stack<double> st; stringstream ss(str); string s; a = atof(s.c_str()); st.push(a); while (ss >> s) { if (isdigit(s[0])) { a = atof(s.c_str()); st.push(a); } else if (s == "+") { a = st.top(); st.pop(); b = st.top(); st.pop(); st.push(b + a); } else if (s == "-") { a = st.top(); st.pop(); b = st.top(); st.pop(); st.push(b - a); } else if (s == "*") { a = st.top(); st.pop(); b = st.top(); st.pop(); st.push(b * a); } else if (s == "/") { a = st.top(); st.pop(); b = st.top(); st.pop(); if (a == 0) exit(EXIT_FAILURE); st.push(b / a); } } printf("%.6lf\n", st.top()); } return 0; }
#include <cctype> #include <cfloat> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; double a, b; while (getline(cin, str)) { stack<double> st; stringstream ss(str); string s; a = atof(s.c_str()); st.push(a); while (ss >> s) { if (s.size() > 1 || isdigit(s[0])) { a = atof(s.c_str()); st.push(a); } else if (s == "+") { a = st.top(); st.pop(); b = st.top(); st.pop(); st.push(b + a); } else if (s == "-") { a = st.top(); st.pop(); b = st.top(); st.pop(); st.push(b - a); } else if (s == "*") { a = st.top(); st.pop(); b = st.top(); st.pop(); st.push(b * a); } else if (s == "/") { a = st.top(); st.pop(); b = st.top(); st.pop(); if (a == 0) exit(EXIT_FAILURE); st.push(b / a); } } printf("%.6lf\n", st.top()); } return 0; }
replace
23
24
23
24
-11
p00087
C++
Runtime Error
#include <cstdio> #include <stack> using namespace std; bool isope(char c) { return c == '+' || c == '-' || c == '*' || c == '/'; } double calc(double a, char c, double b) { switch (c) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': return a / b; } } int main() { while (1) { stack<double> st; while (1) { char s[16]; int f = scanf("%s", s); if (!~f) return 0; if (isope(s[0])) { double b = st.top(); st.pop(); double a = st.top(); st.pop(); st.push(calc(a, s[0], b)); } else { double a; sscanf(s, "%lf", &a); st.push(a); } if (getchar() == '\n') break; } printf("%f\n", st.top()); } }
#include <cstdio> #include <stack> using namespace std; bool isope(char c) { return c == '+' || c == '-' || c == '*' || c == '/'; } double calc(double a, char c, double b) { switch (c) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': return a / b; } } int main() { while (1) { stack<double> st; while (1) { char s[16]; int f = scanf("%s", s); if (!~f) return 0; if (s[1] == '\0' && isope(s[0])) { double b = st.top(); st.pop(); double a = st.top(); st.pop(); st.push(calc(a, s[0], b)); } else { double a; sscanf(s, "%lf", &a); st.push(a); } if (getchar() == '\n') break; } printf("%f\n", st.top()); } }
replace
30
31
30
31
-11
p00087
C++
Runtime Error
#include <cctype> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> S; stringstream ss; ss << str; while (ss >> str) { if (isdigit(str[0])) { double d = (double)atoi(str.c_str()); S.push(d); } else { char ope = str[0]; double d1 = S.top(); S.pop(); double d2 = S.top(); S.pop(); if (ope == '+') S.push(d1 + d2); else if (ope == '-') S.push(d2 - d1); else if (ope == '*') S.push(d1 * d2); else S.push(d2 / d1); } } cout << fixed << S.top() << endl; } }
#include <cctype> #include <cstdlib> #include <iostream> #include <sstream> #include <stack> #include <string> using namespace std; int main() { string str; while (getline(cin, str)) { stack<double> S; stringstream ss; ss << str; while (ss >> str) { if (str[0] >= '0' && str[0] <= '9' || str.size() > 1) { S.push(atoi(str.c_str())); } else { char ope = str[0]; double d1 = S.top(); S.pop(); double d2 = S.top(); S.pop(); if (ope == '+') S.push(d1 + d2); else if (ope == '-') S.push(d2 - d1); else if (ope == '*') S.push(d1 * d2); else S.push(d2 / d1); } } cout << fixed << S.top() << endl; } }
replace
14
17
14
16
-11
p00087
C++
Runtime Error
#include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <string> using namespace std; int main() { char str[128]; while (fgets(str, sizeof(str), stdin) != NULL) { stack<double> s; for (int i = 0; str[i] && str[i] != '\n';) { if (str[i] == ' ') i++; else if ('0' <= str[i] && str[i] <= '9') { int p = 0; for (; str[i] && str[i] != ' ' && str[i] != '\n'; i++) { p *= 10; p += str[i] - '0'; } s.push((double)p); } else { double r, l; double p; r = s.top(); s.pop(); l = s.top(); s.pop(); switch (str[i]) { case '+': p = l + r; break; case '-': p = l - r; break; case '*': p = l * r; break; case '/': p = l / r; break; } s.push(p); i++; } } printf("%f\n", s.top()); } }
#include <cstdio> #include <cstring> #include <iostream> #include <stack> #include <string> using namespace std; int main() { char str[128]; while (fgets(str, sizeof(str), stdin) != NULL) { stack<double> s; for (int i = 0; str[i] && str[i] != '\n';) { if (str[i] == ' ') i++; else if ('0' <= str[i] && str[i] <= '9') { int p = 0; for (; str[i] && str[i] != ' ' && str[i] != '\n'; i++) { p *= 10; p += str[i] - '0'; } s.push((double)p); } else if (str[i] == '-' && str[i + 1] != ' ' && str[i + 1] != '\n') { int p = 0; i++; for (; str[i] && str[i] != ' ' && str[i] != '\n'; i++) { p *= 10; p += str[i] - '0'; } s.push((double)p * (-1)); } else { double r, l; double p; r = s.top(); s.pop(); l = s.top(); s.pop(); switch (str[i]) { case '+': p = l + r; break; case '-': p = l - r; break; case '*': p = l * r; break; case '/': p = l / r; break; } s.push(p); i++; } } printf("%f\n", s.top()); } }
insert
23
23
23
33
-11
p00087
C++
Runtime Error
#include <algorithm> #include <cctype> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; #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() int main() { string line; while (getline(cin, line)) { char str[81]; strcpy(str, line.c_str()); char *p; p = strtok(str, " "); stack<double> sk; while (p) { if (!isdigit(*p)) { double tmp2 = sk.top(); sk.pop(); double tmp1 = sk.top(); sk.pop(); if (*p == '+') sk.push(tmp1 + tmp2); else if (*p == '-') sk.push(tmp1 - tmp2); else if (*p == '*') sk.push(tmp1 * tmp2); else if (*p == '/') sk.push(tmp1 / tmp2); } else sk.push(atof(p)); p = strtok(NULL, " "); } printf("%.6lf\n", sk.top()); } }
#include <algorithm> #include <cctype> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; #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() int main() { string line; while (getline(cin, line)) { char str[81]; strcpy(str, line.c_str()); char *p; p = strtok(str, " "); stack<double> sk; while (p) { if (strlen(p) == 1 && !isdigit(*p)) { double tmp2 = sk.top(); sk.pop(); double tmp1 = sk.top(); sk.pop(); if (*p == '+') sk.push(tmp1 + tmp2); else if (*p == '-') sk.push(tmp1 - tmp2); else if (*p == '*') sk.push(tmp1 * tmp2); else if (*p == '/') sk.push(tmp1 / tmp2); } else sk.push(atof(p)); p = strtok(NULL, " "); } printf("%.6lf\n", sk.top()); } }
replace
26
27
26
27
-11
p00088
C++
Memory Limit Exceeded
#include <cstdio> #include <iostream> #include <string> using namespace std; int main(void) { char tmp; int sum; string inp; string before(""), num(""), after(""); while (tmp = getchar()) { if (tmp == '\n') { before += inp; after = (""); num = (""); for (int i = 0; i < before.length(); i++) { switch (before[i]) { case ' ': num += "101"; break; case '\'': num += "000000"; break; case ',': num += "000011"; break; case '-': num += "10010001"; break; case '.': num += "010001"; break; case '?': num += "000001"; break; case 'A': num += "100101"; break; case 'B': num += "10011010"; break; case 'C': num += "0101"; break; case 'D': num += "0001"; break; case 'E': num += "110"; break; case 'F': num += "01001"; break; case 'G': num += "10011011"; break; case 'H': num += "010000"; break; case 'I': num += "0111"; break; case 'J': num += "10011000"; break; case 'K': num += "0110"; break; case 'L': num += "00100"; break; case 'M': num += "10011001"; break; case 'N': num += "10011110"; break; case 'O': num += "00101"; break; case 'P': num += "111"; break; case 'Q': num += "10011111"; break; case 'R': num += "1000"; break; case 'S': num += "00110"; break; case 'T': num += "00111"; break; case 'U': num += "10011100"; break; case 'V': num += "10011101"; break; case 'W': num += "000010"; break; case 'X': num += "10010010"; break; case 'Y': num += "10010011"; break; case 'Z': num += "10010000"; break; } } while (num.length() % 5 != 0) { num += '0'; } for (int i = 0; i < num.length(); i += 5) { sum = (num[i] - '0') * 16 + (num[i + 1] - '0') * 8 + (num[i + 2] - '0') * 4 + (num[i + 3] - '0') * 2 + (num[i + 4] - '0') * 1; switch (sum) { case 0: after += 'A'; break; case 1: after += 'B'; break; case 2: after += 'C'; break; case 3: after += 'D'; break; case 4: after += 'E'; break; case 5: after += 'F'; break; case 6: after += 'G'; break; case 7: after += 'H'; break; case 8: after += 'I'; break; case 9: after += 'J'; break; case 10: after += 'K'; break; case 11: after += 'L'; break; case 12: after += 'M'; break; case 13: after += 'N'; break; case 14: after += 'O'; break; case 15: after += 'P'; break; case 16: after += 'Q'; break; case 17: after += 'R'; break; case 18: after += 'S'; break; case 19: after += 'T'; break; case 20: after += 'U'; break; case 21: after += 'V'; break; case 22: after += 'W'; break; case 23: after += 'X'; break; case 24: after += 'Y'; break; case 25: after += 'Z'; break; case 26: after += ' '; break; case 27: after += '.'; break; case 28: after += ','; break; case 29: after += '-'; break; case 30: after += '\''; break; case 31: after += '?'; break; } } cout << after << endl; before = (""); } else before += tmp; } return 0; }
#include <cstdio> #include <iostream> #include <string> using namespace std; int main(void) { char tmp; int sum; string inp; string before(""), num(""), after(""); while (scanf("%c", &tmp) != EOF) { if (tmp == '\n') { before += inp; after = (""); num = (""); for (int i = 0; i < before.length(); i++) { switch (before[i]) { case ' ': num += "101"; break; case '\'': num += "000000"; break; case ',': num += "000011"; break; case '-': num += "10010001"; break; case '.': num += "010001"; break; case '?': num += "000001"; break; case 'A': num += "100101"; break; case 'B': num += "10011010"; break; case 'C': num += "0101"; break; case 'D': num += "0001"; break; case 'E': num += "110"; break; case 'F': num += "01001"; break; case 'G': num += "10011011"; break; case 'H': num += "010000"; break; case 'I': num += "0111"; break; case 'J': num += "10011000"; break; case 'K': num += "0110"; break; case 'L': num += "00100"; break; case 'M': num += "10011001"; break; case 'N': num += "10011110"; break; case 'O': num += "00101"; break; case 'P': num += "111"; break; case 'Q': num += "10011111"; break; case 'R': num += "1000"; break; case 'S': num += "00110"; break; case 'T': num += "00111"; break; case 'U': num += "10011100"; break; case 'V': num += "10011101"; break; case 'W': num += "000010"; break; case 'X': num += "10010010"; break; case 'Y': num += "10010011"; break; case 'Z': num += "10010000"; break; } } while (num.length() % 5 != 0) { num += '0'; } for (int i = 0; i < num.length(); i += 5) { sum = (num[i] - '0') * 16 + (num[i + 1] - '0') * 8 + (num[i + 2] - '0') * 4 + (num[i + 3] - '0') * 2 + (num[i + 4] - '0') * 1; switch (sum) { case 0: after += 'A'; break; case 1: after += 'B'; break; case 2: after += 'C'; break; case 3: after += 'D'; break; case 4: after += 'E'; break; case 5: after += 'F'; break; case 6: after += 'G'; break; case 7: after += 'H'; break; case 8: after += 'I'; break; case 9: after += 'J'; break; case 10: after += 'K'; break; case 11: after += 'L'; break; case 12: after += 'M'; break; case 13: after += 'N'; break; case 14: after += 'O'; break; case 15: after += 'P'; break; case 16: after += 'Q'; break; case 17: after += 'R'; break; case 18: after += 'S'; break; case 19: after += 'T'; break; case 20: after += 'U'; break; case 21: after += 'V'; break; case 22: after += 'W'; break; case 23: after += 'X'; break; case 24: after += 'Y'; break; case 25: after += 'Z'; break; case 26: after += ' '; break; case 27: after += '.'; break; case 28: after += ','; break; case 29: after += '-'; break; case 30: after += '\''; break; case 31: after += '?'; break; } } cout << after << endl; before = (""); } else before += tmp; } return 0; }
replace
13
14
13
14
MLE
p00088
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int>> vii; #define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--) #define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define vrep(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template <class T, class S> inline bool minup(T &m, S x) { return m > (T)x ? (m = (T)x, true) : false; } template <class T, class S> inline bool maxup(T &m, S x) { return m < (T)x ? (m = (T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; map<char, string> en; map<string, string> de; string s, t; string in; int n; void encode() { en[' '] = "101"; en['\''] = "000000"; en[','] = "000011"; en['-'] = "10010001"; en['.'] = "010001"; en['?'] = "000001"; en['A'] = "100101"; en['B'] = "10011010"; en['C'] = "0101"; en['D'] = "0001"; en['E'] = "110"; en['F'] = "01001"; en['G'] = "10011011"; en['H'] = "010000"; en['I'] = "0111"; en['J'] = "10011000"; en['K'] = "0110"; en['L'] = "00100"; en['M'] = "10011001"; en['N'] = "10011110"; en['O'] = "00101"; en['P'] = "111"; en['Q'] = "10011111"; en['R'] = "1000"; en['S'] = "00110"; en['T'] = "00111"; en['U'] = "10011100"; en['V'] = "10011101"; en['W'] = "000010"; en['X'] = "10010010"; en['Y'] = "10010011"; en['Z'] = "10010000"; } void decode() { de["00000"] = "A"; de["00001"] = "B"; de["00010"] = "C"; de["00011"] = "D"; de["00100"] = "E"; de["00101"] = "F"; de["00110"] = "G"; de["00111"] = "H"; de["01000"] = "I"; de["01001"] = "J"; de["01010"] = "K"; de["01011"] = "L"; de["01100"] = "M"; de["01101"] = "N"; de["01110"] = "O"; de["01111"] = "P"; de["10000"] = "Q"; de["10001"] = "R"; de["10010"] = "S"; de["10011"] = "T"; de["10100"] = "U"; de["10101"] = "V"; de["10110"] = "W"; de["10111"] = "X"; de["11000"] = "Y"; de["11001"] = "Z"; de["11010"] = " "; de["11011"] = "."; de["11100"] = ","; de["11101"] = "-"; de["11110"] = "'"; de["11111"] = "?"; } int main() { encode(); decode(); while (getline(cin, s)) { in += s + " "; rep(i, in.size() - 1) t += en[in[i]]; n = (5 - t.size() % 5) % 5; rep(i, n) t += "0"; n = t.size() / 5; rep(i, n) cout << de[t.substr(5 * i, 5)]; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pair<int, int>> vii; #define rrep(i, m, n) for (int(i) = (m); (i) < (n); (i)++) #define erep(i, m, n) for (int(i) = (m); (i) <= (n); (i)++) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rrev(i, m, n) for (int(i) = (n)-1; (i) >= (m); (i)--) #define erev(i, m, n) for (int(i) = (n); (i) >= (m); (i)--) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define vrep(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define ALL(v) (v).begin(), (v).end() #define mp make_pair #define pb push_back template <class T, class S> inline bool minup(T &m, S x) { return m > (T)x ? (m = (T)x, true) : false; } template <class T, class S> inline bool maxup(T &m, S x) { return m < (T)x ? (m = (T)x, true) : false; } const int INF = 1000000000; const ll MOD = 1000000007LL; const double EPS = 1E-12; map<char, string> en; map<string, string> de; string s, t; string in; int n; void encode() { en[' '] = "101"; en['\''] = "000000"; en[','] = "000011"; en['-'] = "10010001"; en['.'] = "010001"; en['?'] = "000001"; en['A'] = "100101"; en['B'] = "10011010"; en['C'] = "0101"; en['D'] = "0001"; en['E'] = "110"; en['F'] = "01001"; en['G'] = "10011011"; en['H'] = "010000"; en['I'] = "0111"; en['J'] = "10011000"; en['K'] = "0110"; en['L'] = "00100"; en['M'] = "10011001"; en['N'] = "10011110"; en['O'] = "00101"; en['P'] = "111"; en['Q'] = "10011111"; en['R'] = "1000"; en['S'] = "00110"; en['T'] = "00111"; en['U'] = "10011100"; en['V'] = "10011101"; en['W'] = "000010"; en['X'] = "10010010"; en['Y'] = "10010011"; en['Z'] = "10010000"; } void decode() { de["00000"] = "A"; de["00001"] = "B"; de["00010"] = "C"; de["00011"] = "D"; de["00100"] = "E"; de["00101"] = "F"; de["00110"] = "G"; de["00111"] = "H"; de["01000"] = "I"; de["01001"] = "J"; de["01010"] = "K"; de["01011"] = "L"; de["01100"] = "M"; de["01101"] = "N"; de["01110"] = "O"; de["01111"] = "P"; de["10000"] = "Q"; de["10001"] = "R"; de["10010"] = "S"; de["10011"] = "T"; de["10100"] = "U"; de["10101"] = "V"; de["10110"] = "W"; de["10111"] = "X"; de["11000"] = "Y"; de["11001"] = "Z"; de["11010"] = " "; de["11011"] = "."; de["11100"] = ","; de["11101"] = "-"; de["11110"] = "'"; de["11111"] = "?"; } int main() { encode(); decode(); while (getline(cin, s)) { t = ""; in = ""; in += s + " "; rep(i, in.size() - 1) t += en[in[i]]; n = (5 - t.size() % 5) % 5; rep(i, n) t += "0"; n = t.size() / 5; rep(i, n) cout << de[t.substr(5 * i, 5)]; cout << endl; } return 0; }
insert
110
110
110
112
TLE
p00088
C++
Time Limit Exceeded
#include <iostream> #include <string> #include <vector> using namespace std; string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; vector<string> s1 = {"100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000", "101", "010001", "000011", "10010001", "000000", "000001"}; vector<string> s2 = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"}; string s; int main() { while (true) { s = ""; while (s == "") getline(cin, s); string t; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < e.size(); j++) { if (s[i] == e[j]) t += s1[j]; } } while (t.size() % 5 != 0) t += "0"; string ret = ""; for (int i = 0; i < t.size(); i += 5) { string u = t.substr(i, 5); for (int j = 0; j < e.size(); j++) { if (u == s2[j]) ret += e[j]; } } cout << ret << endl; } return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?"; vector<string> s1 = {"100101", "10011010", "0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000", "0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000", "00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000", "101", "010001", "000011", "10010001", "000000", "000001"}; vector<string> s2 = { "00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001", "01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011", "10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101", "11110", "11111"}; string s; int main() { while (s = "", getline(cin, s)) { string t; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < e.size(); j++) { if (s[i] == e[j]) t += s1[j]; } } while (t.size() % 5 != 0) t += "0"; string ret = ""; for (int i = 0; i < t.size(); i += 5) { string u = t.substr(i, 5); for (int j = 0; j < e.size(); j++) { if (u == s2[j]) ret += e[j]; } } cout << ret << endl; } return 0; }
replace
19
23
19
20
TLE
p00089
C++
Runtime Error
#include <math.h> #include <stack> #include <stdio.h> using namespace std; int main() { int dp[100][1000], row = 0, tmp, index, width[100], max_width = 0, max_width_row; char buf[55]; while (scanf("%s", buf) != EOF) { index = tmp = 0; for (int i = 0; buf[i] != '\0'; i++) { if (buf[i] >= '0' && buf[i] <= '9') { tmp = tmp * 10 + (buf[i] - '0'); if (buf[i + 1] == '\0') { dp[row][index++] = tmp; } } else { dp[row][index++] = tmp; tmp = 0; } } if (max_width < index) { max_width = index; max_width_row = row; } width[row] = index; row++; } for (int i = 1; i <= max_width_row; i++) { for (int k = 0; k < width[i]; k++) { if (k == 0) { dp[i][0] += dp[i - 1][0]; } else if (k == width[i] - 1) { dp[i][k] += dp[i - 1][width[i - 1] - 1]; } else { dp[i][k] += max(dp[i - 1][k - 1], dp[i - 1][k]); } } } for (int i = max_width_row + 1; i < row; i++) { for (int k = 0; k < width[i]; k++) { dp[i][k] += max(dp[i - 1][k], dp[i - 1][k + 1]); } } printf("%d\n", dp[row - 1][0]); return 0; }
#include <math.h> #include <stack> #include <stdio.h> using namespace std; int main() { int dp[100][200], row = 0, tmp, index, width[100], max_width = 0, max_width_row; char buf[200]; while (scanf("%s", buf) != EOF) { index = tmp = 0; for (int i = 0; buf[i] != '\0'; i++) { if (buf[i] >= '0' && buf[i] <= '9') { tmp = tmp * 10 + (buf[i] - '0'); if (buf[i + 1] == '\0') { dp[row][index++] = tmp; } } else { dp[row][index++] = tmp; tmp = 0; } } if (max_width < index) { max_width = index; max_width_row = row; } width[row] = index; row++; } for (int i = 1; i <= max_width_row; i++) { for (int k = 0; k < width[i]; k++) { if (k == 0) { dp[i][0] += dp[i - 1][0]; } else if (k == width[i] - 1) { dp[i][k] += dp[i - 1][width[i - 1] - 1]; } else { dp[i][k] += max(dp[i - 1][k - 1], dp[i - 1][k]); } } } for (int i = max_width_row + 1; i < row; i++) { for (int k = 0; k < width[i]; k++) { dp[i][k] += max(dp[i - 1][k], dp[i - 1][k + 1]); } } printf("%d\n", dp[row - 1][0]); return 0; }
replace
8
11
8
11
0
p00089
C++
Runtime Error
#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; vi split(string s, char sep) { vi res; int a = 0; rep(i, s.size()) { if (s[i] == sep) { res.pb(a); a = 0; } else { a = a * 10 + s[i] - '0'; } } if (s[s.size() - 1] != sep) res.pb(a); return res; } int main() { vector<vi> a; for (string s; getline(cin, s);) a.pb(split(s, ',')); int n = a.size() / 2; int dp[100][100]; memset(dp, 0, sizeof(dp)); debug(a[0][0]) REP(i, 1, n) rep(j, i + 1) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]); REP(i, n + 1, a.size() - 1) rep(j, a.size() - i) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]); cout << dp[a.size() - 1][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; vi split(string s, char sep) { vi res; int a = 0; rep(i, s.size()) { if (s[i] == sep) { res.pb(a); a = 0; } else { a = a * 10 + s[i] - '0'; } } if (s[s.size() - 1] != sep) res.pb(a); return res; } int main() { vector<vi> a; for (string s; getline(cin, s);) a.pb(split(s, ',')); int n = a.size() / 2; int dp[100][100]; memset(dp, 0, sizeof(dp)); dp[0][0] = a[0][0]; REP(i, 1, n) rep(j, i + 1) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j - 1]); REP(i, n + 1, a.size() - 1) rep(j, a.size() - i) dp[i][j] = a[i][j] + max(dp[i - 1][j], dp[i - 1][j + 1]); cout << dp[a.size() - 1][0] << endl; return 0; }
replace
64
66
64
67
0
> a[0][0] = 7
p00089
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cctype> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> using namespace std; int n[99][50], m[99][50]; string s[99]; int main() { int l = 0; while (getline(cin, s[l])) l++; for (int i = 0; i < l; i++) { int pos = 0, cur = 0; while (pos < s[i].size()) { if (isdigit(s[i][pos])) n[i][cur] = n[i][cur] * 10 + s[i][pos] - '0'; else cur++; pos++; } } m[0][0] = n[0][0]; for (int i = 1; i <= l / 2; i++) { m[i][0] = m[i - 1][0] + n[i][0]; m[i][i] = m[i - 1][i - 1] + n[i][i]; for (int j = 1; j < i; j++) m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + n[i][j]; } for (int i = l / 2 + 1; i < l; i++) { for (int j = 0; j < l - i; j++) { m[i][j] = max(m[i - 1][j], m[i - 1][j + 1]) + n[i][j]; } } cout << m[l - 1][0] << endl; }
#include <algorithm> #include <cassert> #include <cctype> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> using namespace std; int n[99][50], m[99][50]; string s[100]; int main() { int l = 0; while (getline(cin, s[l])) l++; for (int i = 0; i < l; i++) { int pos = 0, cur = 0; while (pos < s[i].size()) { if (isdigit(s[i][pos])) n[i][cur] = n[i][cur] * 10 + s[i][pos] - '0'; else cur++; pos++; } } m[0][0] = n[0][0]; for (int i = 1; i <= l / 2; i++) { m[i][0] = m[i - 1][0] + n[i][0]; m[i][i] = m[i - 1][i - 1] + n[i][i]; for (int j = 1; j < i; j++) m[i][j] = max(m[i - 1][j - 1], m[i - 1][j]) + n[i][j]; } for (int i = l / 2 + 1; i < l; i++) { for (int j = 0; j < l - i; j++) { m[i][j] = max(m[i - 1][j], m[i - 1][j + 1]) + n[i][j]; } } cout << m[l - 1][0] << endl; }
replace
12
13
12
13
0
p00090
C++
Time Limit Exceeded
/* template.cpp [[[ */ #include <bits/stdc++.h> using namespace std; #define get_macro(a, b, c, d, name, ...) name #define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(...) \ get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define rep1(n) rep2(i_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s) #define rrep1(n) rrep2(i_, n) #define rrep2(i, n) rrep3(i, 0, n) #define rrep3(i, a, b) rrep4(i, a, b, 1) #define rrep4(i, a, b, s) for (ll i = (ll)(b)-1; i >= (ll)(a); i -= (ll)s) #define each(x, c) for (auto &&x : c) #define fs first #define sc second #define all(c) begin(c), end(c) using ui = unsigned; using ll = long long; using ul = unsigned long long; using ld = long double; const int INF = 1e9 + 10; const ll INF_LL = 1e18 + 10; const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1}; const int dy[]{0, -1, 0, 1, -1, -1, 1, 1}; template <class T, class U> void chmin(T &x, const U &y) { x = min<T>(x, y); } template <class T, class U> void chmax(T &x, const U &y) { x = max<T>(x, y); } /* ]]] */ using P = complex<double>; const double PI = acos(-1.0); const double EPS = 1e-6; int n; P p[100]; int main() { while (cin >> n, n) { rep(i, n) { double x, y; scanf("%lf,%lf", &x, &y); p[i] = P(x, y); } int mx = 0; rep(i, n) rep(j, 101) rep(k, 50) { P q = p[i] + polar(j * 0.01, k * PI / 50); int c = 0; rep(l, n) c += abs(p[l] - q) < 1.0 + EPS; chmax(mx, c); } cout << mx << endl; } }
/* template.cpp [[[ */ #include <bits/stdc++.h> using namespace std; #define get_macro(a, b, c, d, name, ...) name #define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(...) \ get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__) #define rep1(n) rep2(i_, n) #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s) #define rrep1(n) rrep2(i_, n) #define rrep2(i, n) rrep3(i, 0, n) #define rrep3(i, a, b) rrep4(i, a, b, 1) #define rrep4(i, a, b, s) for (ll i = (ll)(b)-1; i >= (ll)(a); i -= (ll)s) #define each(x, c) for (auto &&x : c) #define fs first #define sc second #define all(c) begin(c), end(c) using ui = unsigned; using ll = long long; using ul = unsigned long long; using ld = long double; const int INF = 1e9 + 10; const ll INF_LL = 1e18 + 10; const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1}; const int dy[]{0, -1, 0, 1, -1, -1, 1, 1}; template <class T, class U> void chmin(T &x, const U &y) { x = min<T>(x, y); } template <class T, class U> void chmax(T &x, const U &y) { x = max<T>(x, y); } /* ]]] */ using P = complex<double>; const double PI = acos(-1.0); const double EPS = 1e-6; int n; P p[100]; int main() { while (cin >> n, n) { rep(i, n) { double x, y; scanf("%lf,%lf", &x, &y); p[i] = P(x, y); } int mx = 0; rep(i, n) rep(j, 51) rep(k, 50) { P q = p[i] + polar(j * 0.02, k * PI / 50); int c = 0; rep(l, n) c += abs(p[l] - q) < 1.0 + EPS; chmax(mx, c); } cout << mx << endl; } }
replace
47
49
47
49
TLE
p00090
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1}; const int INF = 1 << 30; const double EPS = 1e-15; #define PB push_back #define mk make_pair #define fi first #define se second #define ll long long #define reps(i, j, k) for (int i = (j); i < (k); i++) #define rep(i, j) reps(i, 0, j) #define MOD 1000000007 typedef pair<int, int> Pii; typedef pair<int, Pii> P; typedef vector<int> vi; typedef vector<vi> vvi; struct Point { double x, y; Point() {} Point(double _x, double _y) { 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 k) { return Point(k * x, k * y); } Point operator*(Point p) { return Point(p.x * x - p.y * y, p.x * y + p.y * x); } Point operator/(double k) { return Point(x / k, y / k); } Point operator=(Point p) { x = p.x; y = p.y; return *this; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } }; double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; } double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; } double norm(Point p) { // ベクトルの大きさの2乗 return p.x * p.x + p.y * p.y; } double pabs(Point p) { // ベクトルの大きさ return sqrt(norm(p)); } Point UnitVector(Point a) { // 単位ベクトル return a / pabs(a); } typedef vector<Point> Polygon; struct Line : Polygon { Line() {} Line(Point p, Point q) { PB(p); PB(q); } }; struct Circle { Point p; // 中心点 double r; // 半径 Circle() {} Circle(Point _p, double _r) { p = _p; r = _r; } }; int ccw(Point a, Point b, Point c) { b = b - a; c = c - a; if (cross(b, c) > 0) return +1; // a→b で反時計に折れてc ccw if (cross(b, c) < 0) return -1; // a→b で時計に折れてc ccw if (dot(b, c) < 0) return +2; // c--a--b; if (pabs(b) < pabs(c)) return -2; // a--b--c return 0; // a--c--b } bool intersectSS(Line l, Line m) { // lとmが交差してるかどうか return (ccw(l[0], l[1], m[0]) * ccw(l[0], l[1], m[1]) < EPS) && (ccw(m[0], m[1], l[0]) * ccw(m[0], m[1], l[1]) < EPS); } bool intersectSP(Line l, Point p) { // 線分lと点pが交差してるか return !ccw(l[0], l[1], p); } bool intersectLL(Line l, Line m) { return fabs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // 平行でない fabs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // 同一の線 } int intercectCC(Circle a, Circle b, Point *p, Point *q) { double dist = pabs(a.p - b.p); if (dist < fabs(a.r - b.r) || dist > a.r + b.r) { // 円の中心が一致しているとき // 円の交点が存在しないとき *p = Point(1e15, 1e15); *q = Point(1e15, 1e15); return 0; } else if (fabs(dist - a.r - b.r) < EPS) { // 円が1点で交わっているとき Point way; way = b.p - a.p; *p = a.p + UnitVector(way) * a.r; *q = *p; return 1; } else { // 円が2点で交わっているとき if (a.r < b.r) { swap(a.r, b.r); swap(a.p, b.p); } double s = (a.r + b.r + dist) / 2.0; double area = sqrt(s * (s - a.r) * (s - b.r) * (s - dist)); double h = 2.0 * area / dist; Point v = b.p - a.p; v = UnitVector(v); Point m = a.p + (v * sqrt(a.r * a.r - h * h)); Point n = v * Point(0.0, 1.0); *p = m + (n * h); *q = m - (n * h); return 2; } } double TriangleArea(Point a, Point b, Point c) { b = b - a; c = c - a; return cross(b, c) * 0.5; // 負になることもあるので注意 } double VertexArea(Polygon v) { double subArea = 0.0; rep(i, v.size() - 1) { subArea += TriangleArea(v[0], v[i], v[i + 1]); } return subArea; // 負になることもあるので注意 } Point crosspoint(Line l, Line m) { // 線分lと線分mの交点 if (intersectSS(l, m) == false) return Point(INF, INF); return m[0] + (m[1] - m[0]) * cross(l[1] - l[0], l[1] - m[0]) / cross(l[1] - l[0], m[1] - m[0]); } Polygon ConvexHull(Polygon v) { int n = v.size(); int k = 0; sort(v.begin(), v.end()); Polygon e(2 * n); for (int i = 0; i < n; e[k++] = v[i++]) while (k >= 2 && ccw(e[k - 2], e[k - 1], v[i]) <= 0) k--; for (int i = n - 2, t = k + 1; i >= 0; e[k++] = v[i--]) while (k >= t && ccw(e[k - 2], e[k - 1], v[i]) <= 0) k--; e.resize(k - 1); return e; } int main() { int N; while (scanf("%d", &N), N) { Circle C[328]; vector<Point> points; rep(i, N) { double x, y; scanf("%lf %lf", &x, &y); C[i] = Circle(Point(x, y), 1.); } int len = 0; rep(i, N) { reps(j, i + 1, N) { Point p, q; int tmp = 0; tmp = intercectCC(C[i], C[j], &p, &q); if (tmp > 0) { points.PB(p); points.PB(q); /* cout << i << " " << j << "->\n"; cout << "1:"<< p.x << " " << p.y << "\n"; cout << "2:"<< q.x << " " << q.y << "\n"; */ } } } int ans = 1; rep(i, points.size()) { Point tar = points[i]; int cnt = 0; rep(j, N) { Point base = C[j].p; // cout << pabs(base-tar) << " "; if (pabs(base - tar) - 1. < EPS) { cnt++; } } ans = max(ans, cnt); } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1}; const int INF = 1 << 30; const double EPS = 1e-15; #define PB push_back #define mk make_pair #define fi first #define se second #define ll long long #define reps(i, j, k) for (int i = (j); i < (k); i++) #define rep(i, j) reps(i, 0, j) #define MOD 1000000007 typedef pair<int, int> Pii; typedef pair<int, Pii> P; typedef vector<int> vi; typedef vector<vi> vvi; struct Point { double x, y; Point() {} Point(double _x, double _y) { 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 k) { return Point(k * x, k * y); } Point operator*(Point p) { return Point(p.x * x - p.y * y, p.x * y + p.y * x); } Point operator/(double k) { return Point(x / k, y / k); } Point operator=(Point p) { x = p.x; y = p.y; return *this; } bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; } }; double dot(Point p, Point q) { return p.x * q.x + p.y * q.y; } double cross(Point p, Point q) { return p.x * q.y - q.x * p.y; } double norm(Point p) { // ベクトルの大きさの2乗 return p.x * p.x + p.y * p.y; } double pabs(Point p) { // ベクトルの大きさ return sqrt(norm(p)); } Point UnitVector(Point a) { // 単位ベクトル return a / pabs(a); } typedef vector<Point> Polygon; struct Line : Polygon { Line() {} Line(Point p, Point q) { PB(p); PB(q); } }; struct Circle { Point p; // 中心点 double r; // 半径 Circle() {} Circle(Point _p, double _r) { p = _p; r = _r; } }; int ccw(Point a, Point b, Point c) { b = b - a; c = c - a; if (cross(b, c) > 0) return +1; // a→b で反時計に折れてc ccw if (cross(b, c) < 0) return -1; // a→b で時計に折れてc ccw if (dot(b, c) < 0) return +2; // c--a--b; if (pabs(b) < pabs(c)) return -2; // a--b--c return 0; // a--c--b } bool intersectSS(Line l, Line m) { // lとmが交差してるかどうか return (ccw(l[0], l[1], m[0]) * ccw(l[0], l[1], m[1]) < EPS) && (ccw(m[0], m[1], l[0]) * ccw(m[0], m[1], l[1]) < EPS); } bool intersectSP(Line l, Point p) { // 線分lと点pが交差してるか return !ccw(l[0], l[1], p); } bool intersectLL(Line l, Line m) { return fabs(cross(l[1] - l[0], m[1] - m[0])) > EPS || // 平行でない fabs(cross(l[1] - l[0], m[0] - l[0])) < EPS; // 同一の線 } int intercectCC(Circle a, Circle b, Point *p, Point *q) { double dist = pabs(a.p - b.p); if (dist < fabs(a.r - b.r) || dist > a.r + b.r) { // 円の中心が一致しているとき // 円の交点が存在しないとき *p = Point(1e15, 1e15); *q = Point(1e15, 1e15); return 0; } else if (fabs(dist - a.r - b.r) < EPS) { // 円が1点で交わっているとき Point way; way = b.p - a.p; *p = a.p + UnitVector(way) * a.r; *q = *p; return 1; } else { // 円が2点で交わっているとき if (a.r < b.r) { swap(a.r, b.r); swap(a.p, b.p); } double s = (a.r + b.r + dist) / 2.0; double area = sqrt(s * (s - a.r) * (s - b.r) * (s - dist)); double h = 2.0 * area / dist; Point v = b.p - a.p; v = UnitVector(v); Point m = a.p + (v * sqrt(a.r * a.r - h * h)); Point n = v * Point(0.0, 1.0); *p = m + (n * h); *q = m - (n * h); return 2; } } double TriangleArea(Point a, Point b, Point c) { b = b - a; c = c - a; return cross(b, c) * 0.5; // 負になることもあるので注意 } double VertexArea(Polygon v) { double subArea = 0.0; rep(i, v.size() - 1) { subArea += TriangleArea(v[0], v[i], v[i + 1]); } return subArea; // 負になることもあるので注意 } Point crosspoint(Line l, Line m) { // 線分lと線分mの交点 if (intersectSS(l, m) == false) return Point(INF, INF); return m[0] + (m[1] - m[0]) * cross(l[1] - l[0], l[1] - m[0]) / cross(l[1] - l[0], m[1] - m[0]); } Polygon ConvexHull(Polygon v) { int n = v.size(); int k = 0; sort(v.begin(), v.end()); Polygon e(2 * n); for (int i = 0; i < n; e[k++] = v[i++]) while (k >= 2 && ccw(e[k - 2], e[k - 1], v[i]) <= 0) k--; for (int i = n - 2, t = k + 1; i >= 0; e[k++] = v[i--]) while (k >= t && ccw(e[k - 2], e[k - 1], v[i]) <= 0) k--; e.resize(k - 1); return e; } int main() { int N; while (scanf("%d", &N), N) { Circle C[328]; vector<Point> points; rep(i, N) { double x, y; scanf("%lf,%lf", &x, &y); C[i] = Circle(Point(x, y), 1.); } int len = 0; rep(i, N) { reps(j, i + 1, N) { Point p, q; int tmp = 0; tmp = intercectCC(C[i], C[j], &p, &q); if (tmp > 0) { points.PB(p); points.PB(q); /* cout << i << " " << j << "->\n"; cout << "1:"<< p.x << " " << p.y << "\n"; cout << "2:"<< q.x << " " << q.y << "\n"; */ } } } int ans = 1; rep(i, points.size()) { Point tar = points[i]; int cnt = 0; rep(j, N) { Point base = C[j].p; // cout << pabs(base-tar) << " "; if (pabs(base - tar) - 1. < EPS) { cnt++; } } ans = max(ans, cnt); } printf("%d\n", ans); } return 0; }
replace
186
187
186
187
TLE
p00090
C++
Runtime Error
#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(10) typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> P; typedef long long ll; const int INF = 114514810; const int MOD = 1000000007; const double EPS = 1e-10; struct edge { int to, cost; bool operator<(const edge &e) const { return cost < e.cost; } bool operator>(const edge &e) const { return cost > e.cost; } }; int dx[] = {-1, 0, 0, 1}; int dy[] = {0, -1, 1, 0}; template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); } bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h && y < w); } int place(int x, int y, int w) { return w * x + y; } ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// const double PI = acos(-1.0); bool eq(double a, double b) { return fabs(a - b) < EPS; } typedef complex<double> Point; typedef vector<Point> Polygon; namespace std { bool operator<(const Point &a, const Point &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } // namespace std struct Line { Point a, b; Line(Point p, Point q) : a(p), b(q){}; Line(double x1, double y1, double x2, double y2) : a(Point(x1, y1)), b(Point(x2, y2)){}; }; struct Circle { Point p; double r; int n; Circle(Point a, double b) : p(a), r(b){}; }; double dot(Point a, Point b) { return real(conj(a) * b); } double cross(Point a, Point b) { return imag(conj(a) * b); } int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > EPS) return 1; // counter cloclwise if (cross(b, c) < -EPS) return -1; // cloclwise if (dot(b, c) < 0) return 2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; // a--c--b on line } bool isis_ll(Line l, Line m) { return abs(cross(l.b - l.a, m.b - m.a)) > EPS; } bool isis_ls(Line l, Line s) { return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS; } bool isis_ss(Line s, Line t) { return (ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0); } bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < EPS); } bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a)) < EPS; } Point projection(Line l, Point p) { Point base = l.b - l.a; double r = dot(p - l.a, base) / norm(base); return l.a + base * r; } Point mirror(Line l, Point p) { return 2.0 * projection(l, p) - p; } double dist_lp(Line l, Point p) { return abs(p - projection(l, p)); } double dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } double dist_ls(Line l, Line s) { if (isis_ls(l, s)) return 0; return min(dist_lp(l, s.a), dist_lp(l, s.b)); } double dist_sp(Line s, Point p) { Point r = projection(s, p); if (isis_sp(s, r)) return abs(r - p); return min(abs(s.a - p), abs(s.b - p)); } double dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min(min(dist_sp(s, t.a), dist_sp(s, t.b)), min(dist_sp(t, s.a), dist_sp(t, s.b))); } Point is_ll(Line s, Line t) { double a = cross(s.b - s.a, t.b - t.a); double b = cross(s.b - s.a, s.b - t.a); return t.a + b / a * (t.b - t.a); } vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; double d = abs(c1.p - c2.p); double rc = (d * d + pow(c1.r, 2) - pow(c2.r, 2)) / (2 * d); double dfr = pow(c1.r, 2) - rc * rc; if (abs(dfr) < EPS) dfr = 0; if (dfr < 0.0) return res; double rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } int main() { int n; while (cin >> n, n) { vector<Circle> cs; REP(i, n) { double x, y; char c; cin >> x >> c >> y; cs.push_back(Circle(Point(x, y), 1)); } vector<Point> ps; REP(i, cs.size()) REP(j, i) { auto tmp = is_cc(cs[i], cs[j]); REP(k, tmp.size()) { ps.push_back(tmp[k]); } } vi cnt(ps.size()); REP(i, ps.size()) { REP(j, cs.size()) { if (abs(ps[i] - cs[j].p) - 1 < EPS) { cnt[i]++; } } } if (cnt.size() == 0) cout << 1 << endl; cout << *max_element(ALL(cnt)) << 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(10) typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> P; typedef long long ll; const int INF = 114514810; const int MOD = 1000000007; const double EPS = 1e-10; struct edge { int to, cost; bool operator<(const edge &e) const { return cost < e.cost; } bool operator>(const edge &e) const { return cost > e.cost; } }; int dx[] = {-1, 0, 0, 1}; int dy[] = {0, -1, 1, 0}; template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); } bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h && y < w); } int place(int x, int y, int w) { return w * x + y; } ///*************************************************************************************/// ///*************************************************************************************/// ///*************************************************************************************/// const double PI = acos(-1.0); bool eq(double a, double b) { return fabs(a - b) < EPS; } typedef complex<double> Point; typedef vector<Point> Polygon; namespace std { bool operator<(const Point &a, const Point &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } // namespace std struct Line { Point a, b; Line(Point p, Point q) : a(p), b(q){}; Line(double x1, double y1, double x2, double y2) : a(Point(x1, y1)), b(Point(x2, y2)){}; }; struct Circle { Point p; double r; int n; Circle(Point a, double b) : p(a), r(b){}; }; double dot(Point a, Point b) { return real(conj(a) * b); } double cross(Point a, Point b) { return imag(conj(a) * b); } int ccw(Point a, Point b, Point c) { b -= a; c -= a; if (cross(b, c) > EPS) return 1; // counter cloclwise if (cross(b, c) < -EPS) return -1; // cloclwise if (dot(b, c) < 0) return 2; // c--a--b on line if (norm(b) < norm(c)) return -2; // a--b--c on line return 0; // a--c--b on line } bool isis_ll(Line l, Line m) { return abs(cross(l.b - l.a, m.b - m.a)) > EPS; } bool isis_ls(Line l, Line s) { return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS; } bool isis_ss(Line s, Line t) { return (ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0); } bool isis_lp(Line l, Point p) { return (abs(cross(l.b - p, l.a - p)) < EPS); } bool isis_sp(Line s, Point p) { return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a)) < EPS; } Point projection(Line l, Point p) { Point base = l.b - l.a; double r = dot(p - l.a, base) / norm(base); return l.a + base * r; } Point mirror(Line l, Point p) { return 2.0 * projection(l, p) - p; } double dist_lp(Line l, Point p) { return abs(p - projection(l, p)); } double dist_ll(Line l, Line m) { return isis_ll(l, m) ? 0 : dist_lp(l, m.a); } double dist_ls(Line l, Line s) { if (isis_ls(l, s)) return 0; return min(dist_lp(l, s.a), dist_lp(l, s.b)); } double dist_sp(Line s, Point p) { Point r = projection(s, p); if (isis_sp(s, r)) return abs(r - p); return min(abs(s.a - p), abs(s.b - p)); } double dist_ss(Line s, Line t) { if (isis_ss(s, t)) return 0; return min(min(dist_sp(s, t.a), dist_sp(s, t.b)), min(dist_sp(t, s.a), dist_sp(t, s.b))); } Point is_ll(Line s, Line t) { double a = cross(s.b - s.a, t.b - t.a); double b = cross(s.b - s.a, s.b - t.a); return t.a + b / a * (t.b - t.a); } vector<Point> is_cc(Circle c1, Circle c2) { vector<Point> res; double d = abs(c1.p - c2.p); double rc = (d * d + pow(c1.r, 2) - pow(c2.r, 2)) / (2 * d); double dfr = pow(c1.r, 2) - rc * rc; if (abs(dfr) < EPS) dfr = 0; if (dfr < 0.0) return res; double rs = sqrt(dfr); Point diff = (c2.p - c1.p) / d; res.push_back(c1.p + diff * Point(rc, rs)); if (dfr != 0.0) res.push_back(c1.p + diff * Point(rc, -rs)); return res; } int main() { int n; while (cin >> n, n) { vector<Circle> cs; REP(i, n) { double x, y; char c; cin >> x >> c >> y; cs.push_back(Circle(Point(x, y), 1)); } vector<Point> ps; REP(i, cs.size()) REP(j, i) { auto tmp = is_cc(cs[i], cs[j]); REP(k, tmp.size()) { ps.push_back(tmp[k]); } } vi cnt(ps.size()); REP(i, ps.size()) { REP(j, cs.size()) { if (abs(ps[i] - cs[j].p) - 1 < EPS) { cnt[i]++; } } } if (cnt.size() == 0) cout << 1 << endl; else cout << *max_element(ALL(cnt)) << endl; } return 0; }
replace
172
173
172
174
0