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
p01137
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { int e; while (cin >> e && e > 0) { int min; min = 1000000; for (int y = 0; y <= sqrt(e); y++) { for (int z = 0; z <= pow(e, 1.0 / 3.0); z++) { int m, x; m = e - y * y + y - z * z * z + z; x = e - y * y - z * z * z; if (min > m && x >= 0) { min = m; } } } cout << min << endl; } }
#include <iostream> #include <math.h> using namespace std; int main() { int e; while (cin >> e && e > 0) { int min; min = 1000000; for (int y = 0; y <= 1000; y++) { for (int z = 0; z <= 100; z++) { int m, x; m = e - y * y + y - z * z * z + z; x = e - y * y - z * z * z; if (min > m && x >= 0) { min = m; } } } cout << min << endl; } }
replace
10
12
10
12
TLE
p01137
C++
Time Limit Exceeded
// b #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define REP(i, b, n) for (int i = b; i < n; i++) #define REPR(i, b, n) for (int i = n - 1; i >= b; i--) #define CLR(mat) memset(mat, 0, sizeof(mat)) #define NCLR(mat) memset(mat, -1, sizeof(mat)) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define BIT(n, b) ((n >> b) & 1) #define PB push_back #define MP make_pair using namespace std; static const double PI = acos(-1.0); static const double EPS = 1e-9; typedef long long ll; typedef pair<int, int> pii; int main() { ll e; while (cin >> e, e) { ll mn = e; for (ll y = 0; y < e; ++y) { for (ll z = 0; z < e; ++z) { if (e - y * y - z * z * z >= 0) { mn = min(mn, e - y * y - z * z * z + y + z); } } } cout << mn << endl; } return 0; }
// b #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #define REP(i, b, n) for (int i = b; i < n; i++) #define REPR(i, b, n) for (int i = n - 1; i >= b; i--) #define CLR(mat) memset(mat, 0, sizeof(mat)) #define NCLR(mat) memset(mat, -1, sizeof(mat)) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define BIT(n, b) ((n >> b) & 1) #define PB push_back #define MP make_pair using namespace std; static const double PI = acos(-1.0); static const double EPS = 1e-9; typedef long long ll; typedef pair<int, int> pii; int main() { ll e; while (cin >> e, e) { ll mn = e; for (ll y = 0; e - y * y >= 0; ++y) { for (ll z = 0; e - z * z * z >= 0; ++z) { if (e - y * y - z * z * z >= 0) { mn = min(mn, e - y * y - z * z * z + y + z); } } } cout << mn << endl; } return 0; }
replace
49
51
49
51
TLE
p01137
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { int ans = 1000000; for (int i = 0; i < 1000; i++) { if (n < pow(i, 2)) break; for (int j = 0; j < 100; j++) { if (n - pow(i, 2) - pow(j, 3) < 0) continue; ans = min(ans, i + j + (int)(n - pow(i, 2) - pow(j, 3))); } } cout << ans << endl; } }
#include <cmath> #include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { int ans = 1 << 30; for (int i = 0; i * i * i <= n; i++) { int j = sqrt(n - i * i * i); if (n < i * i * i + j * j) continue; ans = min(ans, i + j + (n - i * i * i - j * j)); } cout << ans << endl; } }
replace
7
16
7
13
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define RREP(i, a) for (int(i) = (a)-1; (i) >= 0; (i)--) #define FORR(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; void solve(int E) { int m = INF; for (int y = 0; (y * y) <= E; y++) for (int z = 0; (y * y) + (z * z * z) <= E; z++) { int x = E - (y * y) - pow(z, 3); if (x < 0) continue; m = min(m, x + y + z); } cout << m << endl; } signed main(void) { int n, m, p, a, b, c, x, y, z, q; string s; while (cin >> n, n) { solve(n); // return 0; } }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (n); (i)++) #define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define RREP(i, a) for (int(i) = (a)-1; (i) >= 0; (i)--) #define FORR(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define DEBUG(C) cerr << #C << " = " << C << endl; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<LL>; using VVL = vector<VL>; using VD = vector<double>; using VVD = vector<VD>; using PII = pair<int, int>; using PDD = pair<double, double>; using PLL = pair<LL, LL>; using VPII = vector<PII>; #define ALL(a) begin((a)), end((a)) #define RALL(a) rbegin((a)), rend((a)) #define SORT(a) sort(ALL((a))) #define RSORT(a) sort(RALL((a))) #define REVERSE(a) reverse(ALL((a))) #define MP make_pair #define FORE(a, b) for (auto &&a : (b)) #define FIND(s, e) ((s).find(e) != (s).end()) #define EB emplace_back const int INF = 1e9; const int MOD = INF + 7; const LL LLINF = 1e18; void solve(int E) { int m = INF; for (int y = 0; (y * y) <= E; y++) for (int z = 0; (y * y) + (z * z * z) <= E; z++) { int x = E - (y * y) - (z * z * z); m = min(m, x + y + z); } cout << m << endl; } signed main(void) { int n, m, p, a, b, c, x, y, z, q; string s; while (cin >> n, n) { solve(n); // return 0; } }
replace
63
66
63
64
TLE
p01137
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using LL = long long; using P = pair<int, int>; using Tapris = tuple<int, int, int>; #define REP(i, n) for (LL i = 0; i < n; ++i) #define FOR(i, a, n) for (LL i = a; i < n; ++i) #define pb(a) push_back(a) #define all(x) (x).begin(), (x).end() const int INF = (int)1e9; const LL INFL = (LL)1e15; const int MOD = 1e9 + 7; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; // #define int long long /*************** using variables ***************/ int e; int m = INF; /**********************************************/ signed main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> e, e) { m = INF; for (int x = 0; x <= e; x++) { for (int y = 0; y * y <= e - x; y++) { int z3 = e - x - y * y; int z = cbrt(z3); if (z3 == z * z * z) { if (x + y * y + z * z * z == e) { // cout << x << " " << y << " " << z << endl; m = min(m, x + y + z); } } } } cout << m << endl; } }
#include <bits/stdc++.h> using namespace std; using LL = long long; using P = pair<int, int>; using Tapris = tuple<int, int, int>; #define REP(i, n) for (LL i = 0; i < n; ++i) #define FOR(i, a, n) for (LL i = a; i < n; ++i) #define pb(a) push_back(a) #define all(x) (x).begin(), (x).end() const int INF = (int)1e9; const LL INFL = (LL)1e15; const int MOD = 1e9 + 7; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; // #define int long long /*************** using variables ***************/ int e; int m = INF; /**********************************************/ signed main() { cin.tie(0); ios::sync_with_stdio(false); while (cin >> e, e) { m = INF; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y <= e - z * z * z; y++) { int x = e - y * y - z * z * z; if (x + y * y + z * z * z == e) { // cout << x << " " << y << " " << z << endl; m = min(m, x + y + z); } } } cout << m << endl; } }
replace
32
41
32
38
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; 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(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) const double EPS = 1e-10; int main() { int e; while (cin >> e, e) { int min = INT_MAX; for (int z = 100; z >= 0; z--) { for (int y = sqrt((double)e - z * z * z); y >= 0; y--) { for (int x = e - z * z * z - y * y; x >= 0; x--) { if (e == x + y * y + z * z * z) { if (min > x + y + z) { min = x + y + z; } } } } } cout << min << endl; } }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; 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(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) const double EPS = 1e-10; int main() { int e; while (cin >> e, e) { int min = INT_MAX; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y + z * z * z <= e; y++) { int x = e - z * z * z - y * y; if (x >= 0) { if (min > x + y + z) { min = x + y + z; } } } } cout << min << endl; } }
replace
55
62
55
61
TLE
p01137
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { bool f = 1; for (int N = 1; f; N++) for (int x = 0; f && x <= N; x++) for (int y = 0; f && y <= N - x; y++) { int z = N - x - y; if (z * z * z + y * y + x == e) { cout << N << endl; f = 0; break; } } } }
#include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ans = 1000000; for (int z = 0; z * z * z <= e; z++) for (int y = 0; y * y <= e - z * z * z; y++) { int x = e - y * y - z * z * z; ans = min(ans, x + y + z); } cout << ans << endl; } }
replace
6
17
6
14
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int e; while (cin >> e && e > 0) { int min_sum = 100000; for (int i = 0; i <= e; i++) { int j = sqrt(e - i * i * i); int k = e - i * i * i - j * j; int temp = i + j + k; min_sum = min(temp, min_sum); } cout << min_sum << endl; } }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int e; while (cin >> e && e > 0) { int min_sum = 100000; for (int i = 0; i * i * i <= e; i++) { int j = sqrt(e - i * i * i); int k = e - i * i * i - j * j; int temp = i + j + k; min_sum = min(temp, min_sum); } cout << min_sum << endl; } }
replace
9
10
9
10
TLE
p01137
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++) 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}; int e; int main() { while (cin >> e, e) { int ans = 10000000; int m; bool flag = true; for (int i = 0; i <= 1000000 && flag; i++) { if (i >= e + 1) { break; } for (int j = 0; j <= 1000000 && flag; j++) { if (i + j >= e + 1 || i + j * j >= e + 1) { break; } for (int k = 0; k <= 1000000 && flag; k++) { if (i + j * j + k >= e + 1 || i + j * j + k * k >= e + 1 || i + j * j + k * k * k >= e + 1) { break; } if (i + j * j + k * k * k == e) { m = i + j + k; ans = min(ans, m); } } } } cout << ans << 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++) 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}; int e; int main() { while (cin >> e, e) { int ans = 10000000; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y + z * z * z <= e; y++) { int x = e - y * y - z * z * z; if (ans > x + y + z) { ans = x + y + z; } } } cout << ans << endl; } return 0; }
replace
41
60
41
46
TLE
p01137
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int e, ans; while (1) { cin >> e; if (!e) break; ans = (1e9); for (int z = 0; z * z * z <= e; z++) { int Z = z * z * z; for (int y = 0; y * y <= e - Z; y++) { int Y = y * y; for (int x = 0; x <= e - Y - Z; x++) { int X = x; if (X + Y + Z != e) continue; ans = min(ans, x + y + z); } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int e, ans; while (1) { cin >> e; if (!e) break; ans = (1e9); for (int z = 0; z * z * z <= e; z++) { int Z = z * z * z; for (int y = 0; y * y <= e - Z; y++) { int Y = y * y; int X = e - Y - Z; if (X + Y + Z != e) continue; ans = min(ans, X + y + z); } } cout << ans << endl; } return 0; }
replace
14
20
14
18
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <string> #include <vector> #define PB push_back #define in scanf #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; void solve() { int e; while (cin >> e, e != 0) { int m = 1000000000; int x; REP(z, (int)pow(e, 0.333) + 1) { REP(y, (int)pow(e, 0.5) + 1) { x = e - pow(y, 2) - pow(z, 3); if (x >= 0) m = min(x + y + z, m); } } cout << m << endl; } } int main() { solve(); }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> #include <string> #include <vector> #define PB push_back #define in scanf #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) using namespace std; void solve() { int e; while (cin >> e, e != 0) { int m = 1000000000; int x; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y + z * z * z <= e; y++) { x = e - y * y - z * z * z; m = min(x + y + z, m); } } cout << m << endl; } } int main() { solve(); }
replace
20
25
20
24
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ans = 1000000; for (int z = 0; z <= e; ++z) { for (int y = 0; y * y + z * z * z <= e; ++y) { int x = e - y * y - z * z * z; ans = min(ans, x + y + z); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ans = 1000000; for (int z = 0; z * z * z <= e; ++z) { for (int y = 0; y * y + z * z * z <= e; ++y) { int x = e - y * y - z * z * z; ans = min(ans, x + y + z); } } cout << ans << endl; } return 0; }
replace
7
8
7
8
TLE
p01137
C++
Time Limit Exceeded
#include <iostream> using namespace std; int solve(int E) { int ans = 1000000; for (int y = 0; y <= E; ++y) { for (int z = 0; z <= E; ++z) { int x = E - y * y - z * z; ans = min(ans, x + y + z); } } return ans; } int main() { int E; while (cin >> E && E > 0) { cout << solve(E) << endl; } }
#include <iostream> using namespace std; int solve(int E) { int ans = 1000000; int x; for (int y = 0; y * y <= E; ++y) { for (int z = 0; z * z * z <= E; ++z) { x = E - y * y - z * z * z; if (x >= 0) ans = min(ans, x + y + z); } } return ans; } int main() { int E; while (cin >> E && E > 0) { cout << solve(E) << endl; } }
replace
5
9
5
11
TLE
p01137
C++
Time Limit Exceeded
#include <iostream> using namespace std; int E; int main() { while (cin >> E && E > 0) { int min = 1000001; for (int z = 0; z < E; ++z) { for (int y = 0; y * y < E - z * z * z; ++y) { int x = E - z * z * z - y * y; if (x + y + z < min) min = x + y + z; } } cout << min << endl; } return 0; }
#include <iostream> using namespace std; int E; int main() { while (cin >> E) { if (E == 0) break; int min = 100000001; for (int z = 0; z * z * z < E + 1; ++z) { for (int y = 0; y * y < E - z * z * z + 1; ++y) { int x = E - z * z * z - y * y; if (x + y + z < min) min = x + y + z; } } cout << min << endl; } return 0; }
replace
6
10
6
12
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int e; int main() { vector<int> ans; while (cin >> e, e) { int m = 1000000; for (int i = 0; i <= e; ++i) { if (i * i * i > e) break; for (int j = 0; j <= e; ++j) { if (i * i * i + j * j > e) break; for (int k = 0; k <= e; ++k) { if (i * i * i + j * j + k == e) m = min(m, i + j + k); } } } ans.push_back(m); } for (int i = 0; i < ans.size(); ++i) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int e; int main() { vector<int> ans; while (cin >> e, e) { int m = 1000000; for (int i = 0; i <= e; ++i) { if (i * i * i > e) break; for (int j = 0; j <= e; ++j) { if (i * i * i + j * j > e) break; if (e - i * i * i - j * j >= 0) m = min(m, i + j + e - i * i * i - j * j); } } ans.push_back(m); } for (int i = 0; i < ans.size(); ++i) { cout << ans[i] << endl; } return 0; }
replace
17
21
17
19
TLE
p01137
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { int ene; while (cin >> ene && ene > 0) { int min = 1000000; for (int z = 0; z <= 100; z++) { int xy = ene - z * z * z; if (xy >= 0) for (int y = 0; y <= xy; y++) { int x = xy - y * y; if (x >= 0) if (x + y + z < min) min = x + y + z; } } cout << min << endl; } }
#include <iostream> #include <math.h> using namespace std; int main() { int ene; while (cin >> ene && ene > 0) { int min = 1000000; for (int z = 0; z <= 100; z++) { int xy = ene - z * z * z; if (xy >= 0) for (int y = 0; y <= 10000; y++) { int x = xy - y * y; if (x >= 0) if (x + y + z < min) min = x + y + z; } } cout << min << endl; } }
replace
10
11
10
11
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef unsigned int UI; 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; typedef istringstream ISS; typedef ostringstream OSS; const int INF = INT_MAX / 4; const double EPS = 1e-12; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define EACH(v, c) for (auto &v : c) #define ITER(c) __typeof((c).begin()) #define IREP(c, it) for (ITER(c) it = c.begin(); it != c.end(); ++it) #define ALL(c) (c).begin(), (c).end() #define PB(n) push_back(n) #define MP(a, b) make_pair((a), (b)) #define EXIST(c, e) ((c).find(e) != (c).end()) #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl int main() { while (true) { int e; cin >> e; if (!e) { break; } ULL min = INT_MAX; for (ULL x = 0; x <= e; x++) { for (ULL y = 0; y * y <= e; y++) { for (ULL z = 0; z * z * z <= e; z++) { if (x + y * y + z * z * z == e) { min = std::min(min, x + y + z); } } } } cout << min << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef unsigned int UI; 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; typedef istringstream ISS; typedef ostringstream OSS; const int INF = INT_MAX / 4; const double EPS = 1e-12; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define EACH(v, c) for (auto &v : c) #define ITER(c) __typeof((c).begin()) #define IREP(c, it) for (ITER(c) it = c.begin(); it != c.end(); ++it) #define ALL(c) (c).begin(), (c).end() #define PB(n) push_back(n) #define MP(a, b) make_pair((a), (b)) #define EXIST(c, e) ((c).find(e) != (c).end()) #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl int main() { while (true) { int e; cin >> e; if (!e) { break; } ULL min = INT_MAX; for (ULL y = 0; y * y <= e; y++) { for (ULL z = 0; z * z * z <= e; z++) { LL x = e - z * z * z - y * y; if (x < 0) { break; } if (x + y * y + z * z * z == e) { min = std::min(min, x + y + z); } } } cout << min << endl; } return 0; }
replace
65
71
65
75
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, s, e) for (int i = (s); i < (e); i++) #define REPI(i, s, e) for (int i = (s); i <= (e); i++) #define rep(i, n) REP(i, 0, n) #define repi(i, n) REPI(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define dump(x) (cout << #x << " = " << x << endl) #define dump2(x, y) \ (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl) #define dump3(x, y, z) \ (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y \ << ", " << z << ")" << endl) typedef long long ll; typedef pair<int, int> pii; #define MAX 1000000 int main(void) { int e; vector<pii> vs; for (int y = 0;; y++) { int k = y * y; if (k > MAX) break; for (int z = 0;; z++) { int l = z * z * z; if (k + l > MAX) break; vs.push_back(pii(k + l, y + z)); } } sort(ALL(vs)); while (cin >> e, e) { int ans = (1 << 29); for (int x = 0; x <= max(e / 3 + 1, 3); x++) { int e_x = e - x; int a = 0, b = vs.size(); while (b - a > 1) { int m = (a + b) / 2; if (vs[m].first >= e_x) b = m; else a = m; } if (vs[b].first == e_x) ans = min(ans, x + vs[b].second); } cout << ans << endl; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, s, e) for (int i = (s); i < (e); i++) #define REPI(i, s, e) for (int i = (s); i <= (e); i++) #define rep(i, n) REP(i, 0, n) #define repi(i, n) REPI(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define dump(x) (cout << #x << " = " << x << endl) #define dump2(x, y) \ (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl) #define dump3(x, y, z) \ (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y \ << ", " << z << ")" << endl) typedef long long ll; typedef pair<int, int> pii; #define MAX 1000000 int main(void) { int e; vector<pii> vs; for (int y = 0;; y++) { int k = y * y; if (k > MAX) break; for (int z = 0;; z++) { int l = z * z * z; if (k + l > MAX) break; vs.push_back(pii(k + l, y + z)); } } sort(ALL(vs)); while (cin >> e, e) { int ans = (1 << 29); rep(i, vs.size()) { int x = e - vs[i].first; if (x < 0) continue; ans = min(ans, x + vs[i].second); } cout << ans << endl; } return 0; }
replace
51
64
51
56
TLE
p01137
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n != 0) { int a; a = 1e9; for (int i = 0; i < pow(n, 0.34); i++) { for (int j = 0; j <= pow(n, 0.5); j++) { int t = (n - i * i * i - j * j); if (t >= 0) a = min(i + j + t, a); } } cout << a << endl; cin >> n; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n != 0) { int a; a = 1e9; for (int i = 0; i * i * i <= n; i++) { for (int j = 0; j * j + i * i * i <= n; j++) { int t = (n - i * i * i - j * j); if (t >= 0) a = min(i + j + t, a); } } cout << a << endl; cin >> n; } return 0; }
replace
9
11
9
11
TLE
p01137
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, j, k) for (int i = (int)j; i < (int)k; i++) #define itrep(x) for (auto it = (x).begin(); it != (x).end(); it++) #define Sort(x) sort((x).begin(), (x).end()) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define vi vector<int> #define INF (int)1e9 #define INFL 1e18 #define MOD 1000000007 #define pb push_back #define MP make_pair typedef long long int ll; typedef std::pair<int, int> P; int D = 1; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; using namespace std; int main() { while (1) { int e; int ans = 1e9 + 7; cin >> e; if (e == 0) break; for (int i = 0; i <= e; i++) { for (int j = 0; i + j * j <= e; j++) { for (int k = 0; i + j * j + k * k * k <= e; k++) { if (i + j * j + k * k * k == e) ans = min(ans, i + j + k); } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, j, k) for (int i = (int)j; i < (int)k; i++) #define itrep(x) for (auto it = (x).begin(); it != (x).end(); it++) #define Sort(x) sort((x).begin(), (x).end()) #define all(x) (x).begin(), (x).end() #define fi first #define se second #define vi vector<int> #define INF (int)1e9 #define INFL 1e18 #define MOD 1000000007 #define pb push_back #define MP make_pair typedef long long int ll; typedef std::pair<int, int> P; int D = 1; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; using namespace std; int main() { while (1) { int e; int ans = 1e9 + 7; cin >> e; if (e == 0) break; rep(i, 0, 1000) { rep(j, 0, 1000) { int k = e - i * i - j * j * j; if (k < 0) continue; ans = min(ans, i + j + k); } } cout << ans << endl; } return 0; }
replace
28
34
28
34
TLE
p01137
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int inf = 1000000000; int main(void) { int e; while (cin >> e) { if (e == 0) break; int ans = 10000000; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; z * z * z + y <= e; y++) { int x = e - z * z * z - y * y; if (x >= 0) { ans = min(ans, x + y + z); } } } cout << ans << endl; } return 0; } // EOF
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int inf = 1000000000; int main(void) { int e; while (cin >> e) { if (e == 0) break; int ans = 10000000; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; z * z * z + y * y <= e; y++) { int x = e - z * z * z - y * y; if (x >= 0) { ans = min(ans, x + y + z); } } } cout << ans << endl; } return 0; } // EOF
replace
24
25
24
25
TLE
p01137
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) int read() { int i; scanf("%lld", &i); return i; } signed main() { while (true) { int e = read(); int ans = 100000; int m; if (e == 0) break; int z, y, x; for (z = 1; z * z * z < e; z++) { } for (y = 1; y * y < e; y++) { } for (int i = 0; i <= z; i++) { for (int j = 0; j <= y; j++) { for (x = 0; x + j * j + i * i * i <= e; x++) { if (x + j * j + i * i * i == e) ans = min(ans, x + j + i); } } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) int read() { int i; scanf("%lld", &i); return i; } signed main() { while (true) { int e = read(); int ans = 100000; int m; if (e == 0) break; int z, y, x; for (z = 1; z * z * z < e; z++) { } for (y = 1; y * y < e; y++) { } for (int i = 0; i <= z; i++) { for (int j = 0; j <= y; j++) { if (e - i * i * i - j * j >= 0) { x = e - i * i * i - j * j; ans = min(ans, x + j + i); } } } cout << ans << endl; } }
replace
29
32
29
32
TLE
p01137
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { int e, m; while (cin >> e && e > 0) { m = e; for (int z = 0; pow(z, 3) <= e; z++) { for (int y = 0; pow(z, 3) + pow(y, 2) <= e; y++) { // int z=e-x-pow(y,2); int x = e - (pow(z, 3) + pow(y, 2)); if (x + y + z < m) m = x + y + z; } } cout << m << endl; } }
#include <cmath> #include <iostream> using namespace std; int main() { int e, m; while (cin >> e && e > 0) { m = e; for (int z = 0; pow(z, 3) <= e; z++) { int pz = pow(z, 3); for (int y = 0; pz + pow(y, 2) <= e; y++) { int x = e - (pz + pow(y, 2)); if (x + y + z < m) m = x + y + z; } } cout << m << endl; } }
replace
9
12
9
12
TLE
p01138
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { int imos[86410] = {}; for (int i = 0; i < n; i++) { int a, b, c, d, e, f; scanf("%d:%d:%d", a, b, c); scanf("%d:%d:%d", d, e, f); imos[a * 3600 + b * 60 + c]++; imos[d * 3600 + e * 60 + f]--; } int ans = imos[0]; for (int i = 1; i <= 86400; i++) { imos[i] += imos[i - 1]; ans = max(ans, imos[i]); } cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { int imos[86410] = {}; for (int i = 0; i < n; i++) { int a, b, c, d, e, f; char ch; cin >> a >> ch >> b >> ch >> c; cin >> d >> ch >> e >> ch >> f; imos[a * 3600 + b * 60 + c]++; imos[d * 3600 + e * 60 + f]--; } int ans = imos[0]; for (int i = 1; i <= 86400; i++) { imos[i] += imos[i - 1]; ans = max(ans, imos[i]); } cout << ans << endl; } }
replace
9
11
9
12
-11
p01138
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> using namespace std; typedef pair<int, int> P; int N; P G[10000]; int solve() { int res = 0; int c = 0; for (int i = 0; i < 2 * N; i++) { if (G[i].second) { c++; res = max(c, res); } else { c--; } } return res; } int main() { while (1) { cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { char str[10]; cin >> str; int a = (str[0] - '0') * 10 + str[1] - '0'; int b = (str[3] - '0') * 10 + str[4] - '0'; int c = (str[6] - '0') * 10 + str[7] - '0'; G[i * 2 + j] = P(a * 60 * 60 + b * 60 + c, 1 - j); } } sort(G, G + 2 * N); cout << solve() << endl; } }
#include <algorithm> #include <iostream> #include <map> using namespace std; typedef pair<int, int> P; int N; P G[20000]; int solve() { int res = 0; int c = 0; for (int i = 0; i < 2 * N; i++) { if (G[i].second) { c++; res = max(c, res); } else { c--; } } return res; } int main() { while (1) { cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { char str[10]; cin >> str; int a = (str[0] - '0') * 10 + str[1] - '0'; int b = (str[3] - '0') * 10 + str[4] - '0'; int c = (str[6] - '0') * 10 + str[7] - '0'; G[i * 2 + j] = P(a * 60 * 60 + b * 60 + c, 1 - j); } } sort(G, G + 2 * N); cout << solve() << endl; } }
replace
7
8
7
8
0
p01138
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int n; int imos[86400]; void solve() { rep(i, n) { int s[3]; int t[3]; scanf("%d:%d:%d", &s[0], &s[1], &s[2]); scanf("%d:%d:%d", &t[0], &t[1], &t[2]); // hh:mm:ss を 秒に変換 int S = s[2] + 60 * (s[1] + s[0] * 60); int T = t[2] + 60 * (t[1] + t[0] * 60); // 入る時間に +1 imos[S]++; // 出る時間+1に -1 imos[T + 1]--; // ナイーブな実装 (写経しなくて良い) // for(int j = S; j <= T; j++) imos[j]++; } // 累積和を計算する rep(i, 86400) if (i) imos[i] += imos[i - 1]; int ans = 0; rep(i, 86400) ans = max(ans, imos[i]); cout << ans << endl; } int main() { // こう書くとn==0のときにwhileループが停止する while (cin >> n, n) { rep(i, 86400) imos[i] = 0; solve(); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int n; int imos[86400]; void solve() { rep(i, n) { int s[3]; int t[3]; scanf("%d:%d:%d", &s[0], &s[1], &s[2]); scanf("%d:%d:%d", &t[0], &t[1], &t[2]); // hh:mm:ss を 秒に変換 int S = s[2] + 60 * (s[1] + s[0] * 60); int T = t[2] + 60 * (t[1] + t[0] * 60); // 入る時間に +1 imos[S]++; // 出る時間に -1 imos[T]--; // ナイーブな実装 (写経しなくて良い) // for(int j = S; j <= T; j++) imos[j]++; } // 累積和を計算する rep(i, 86400) if (i) imos[i] += imos[i - 1]; int ans = 0; rep(i, 86400) ans = max(ans, imos[i]); cout << ans << endl; } int main() { // こう書くとn==0のときにwhileループが停止する while (cin >> n, n) { rep(i, 86400) imos[i] = 0; solve(); } }
replace
23
25
23
25
0
p01138
C++
Runtime Error
#include <bits/stdc++.h> #define _ \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; const int MAX_N = 1000; pair<int, int> p[MAX_N + 1]; int main() { _; int n, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0; while (scanf("%d", &n), n != 0) { REP(i, n) { scanf("%02d:%02d:%02d %02d:%02d:%02d", &a, &b, &c, &d, &e, &f); p[i] = make_pair(a * 3600 + b * 60 + c, d * 3600 + e * 60 + f); } priority_queue<int, vector<int>, greater<int>> que; int maxTrain = 0; sort(p, p + n); REP(i, n) { while (!que.empty() && que.top() <= p[i].first) que.pop(); que.push(p[i].second); maxTrain = max(maxTrain, (int)que.size()); } cout << maxTrain << endl; } }
#include <bits/stdc++.h> #define _ \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define REP(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; const int MAX_N = 10000; pair<int, int> p[MAX_N + 1]; int main() { _; int n, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0; while (scanf("%d", &n), n != 0) { REP(i, n) { scanf("%02d:%02d:%02d %02d:%02d:%02d", &a, &b, &c, &d, &e, &f); p[i] = make_pair(a * 3600 + b * 60 + c, d * 3600 + e * 60 + f); } priority_queue<int, vector<int>, greater<int>> que; int maxTrain = 0; sort(p, p + n); REP(i, n) { while (!que.empty() && que.top() <= p[i].first) que.pop(); que.push(p[i].second); maxTrain = max(maxTrain, (int)que.size()); } cout << maxTrain << endl; } }
replace
8
9
8
9
0
p01138
C++
Time Limit Exceeded
#include <iostream> #define secondMAX (23 * 60 * 59 + 60 * 60 + 59) using namespace std; int main() { int n; int h, m, s; char gav; int table[secondMAX + 1]; int max; while (1) { cin >> n; if (n == 0) break; for (int i = 0; i <= secondMAX; i++) table[i] = 0; for (int i = 0; i < n; i++) { cin >> h >> gav >> m >> gav >> s; table[h * 60 * 60 + m * 60 + s] += 1; cin >> h >> gav >> m >> gav >> s; table[h * 60 * 60 + m * 60 + s] -= 1; } for (int i = 1; i <= secondMAX; i++) table[i] += table[i - 1]; max = 0; for (int i = 0; i <= secondMAX; i++) { if (max < table[i]) max = table[i]; } cout << max << endl; } return 0; }
#include <iostream> #define secondMAX (23 * 60 * 60 + 59 * 60 + 59) using namespace std; int main() { int n; int h, m, s; char gav; int table[secondMAX + 1]; int max; while (1) { cin >> n; if (n == 0) break; for (int i = 0; i <= secondMAX; i++) table[i] = 0; for (int i = 0; i < n; i++) { cin >> h >> gav >> m >> gav >> s; table[h * 60 * 60 + m * 60 + s] += 1; cin >> h >> gav >> m >> gav >> s; table[h * 60 * 60 + m * 60 + s] -= 1; } for (int i = 1; i <= secondMAX; i++) table[i] += table[i - 1]; max = 0; for (int i = 0; i <= secondMAX; i++) { if (max < table[i]) max = table[i]; } cout << max << endl; } return 0; }
replace
2
3
2
3
TLE
p01138
C++
Time Limit Exceeded
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < n; ++i) #define RREP(i, n) for (ll i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i) #define ALL(v) (v).begin(), (v).end() #define PB(a) push_back(a) #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define DUMP(v) \ REP(aa, (v).size()) { \ cout << v[a]; \ if (a != v.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll max(ll a, int b) { return max(a, ll(b)); } ll max(int a, ll b) { return max(ll(a), b); } ll min(ll a, int b) { return min(a, ll(b)); } ll min(int a, ll b) { return min(ll(a), b); } ///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)/// int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int n; cin >> n; if (!n) break; vi v(24 * 60 * 60 + 1, 0); REP(i, n) { int h, m, s; char c; cin >> h >> c >> m >> c >> s; v[h * 60 * 60 + m * 60 + s]++; cin >> h >> c >> m >> c >> s; v[h * 60 * 60 + m * 60 + s]--; } REP(i, 24 * 60 * 60) { cout << *max_element(ALL(v)) << endl; } } return 0; }
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < n; ++i) #define RREP(i, n) for (ll i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i) #define ALL(v) (v).begin(), (v).end() #define PB(a) push_back(a) #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define DUMP(v) \ REP(aa, (v).size()) { \ cout << v[a]; \ if (a != v.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll max(ll a, int b) { return max(a, ll(b)); } ll max(int a, ll b) { return max(ll(a), b); } ll min(ll a, int b) { return min(a, ll(b)); } ll min(int a, ll b) { return min(ll(a), b); } ///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)/// int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int n; cin >> n; if (!n) break; vi v(24 * 60 * 60 + 1, 0); REP(i, n) { int h, m, s; char c; cin >> h >> c >> m >> c >> s; v[h * 60 * 60 + m * 60 + s]++; cin >> h >> c >> m >> c >> s; v[h * 60 * 60 + m * 60 + s]--; } REP(i, 24 * 60 * 60) { v[i + 1] += v[i]; } cout << *max_element(ALL(v)) << endl; } return 0; }
replace
54
55
54
56
TLE
p01139
C++
Runtime Error
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2014 #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <vector> #define ALL(v) (v).begin(), (v).end() #define REP(i, p, n) for (int i = p; i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define dump(a) (cerr << #a << "=" << (a) << endl) #define DUMP(list) \ cout << "{ "; \ for (auto nth : list) { \ cout << nth << " "; \ } \ cout << "}" << endl; using namespace std; #define MAX 10 char area[MAX][MAX]; int ans[MAX][MAX]; int visit[MAX][MAX]; int W, H; void init() { fill_n((char *)area, sizeof(area) / sizeof(char), '.'); fill_n((int *)ans, sizeof(ans) / sizeof(int), 0); fill_n((int *)visit, sizeof(visit) / sizeof(int), 0); } void clear() { fill_n((int *)visit, sizeof(visit) / sizeof(int), 0); } void dfs(int x, int y, char color) { int mark = (color == 'W') ? 1 : 2; char rival = (color == 'W') ? 'B' : 'W'; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; if (x < 0 || x >= W || y < 0 || y >= H) { return; } if (area[y][x] == rival) { return; } if (!visit[y][x]) { visit[y][x] = 1; if (area[y][x] != 'W' && area[y][x] != 'B') { ans[y][x] |= mark; } rep(i, 4) { dfs(x + dx[i], y + dy[i], color); } } return; } int main() { while (cin >> W >> H && W) { int black = 0, white = 0; init(); rep(h, H) { rep(w, W) { cin >> area[h][w]; } } rep(h, H) { rep(w, W) { if (area[h][w] != '.') { clear(); dfs(w, h, area[h][w]); } } } rep(h, H) { rep(w, W) { int num = ans[h][w]; if (num == 1) { white++; } if (num == 2) { black++; } } } cout << black << " " << white << endl; } return 0; }
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2014 #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <numeric> #include <vector> #define ALL(v) (v).begin(), (v).end() #define REP(i, p, n) for (int i = p; i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define dump(a) (cerr << #a << "=" << (a) << endl) #define DUMP(list) \ cout << "{ "; \ for (auto nth : list) { \ cout << nth << " "; \ } \ cout << "}" << endl; using namespace std; #define MAX 52 char area[MAX][MAX]; int ans[MAX][MAX]; int visit[MAX][MAX]; int W, H; void init() { fill_n((char *)area, sizeof(area) / sizeof(char), '.'); fill_n((int *)ans, sizeof(ans) / sizeof(int), 0); fill_n((int *)visit, sizeof(visit) / sizeof(int), 0); } void clear() { fill_n((int *)visit, sizeof(visit) / sizeof(int), 0); } void dfs(int x, int y, char color) { int mark = (color == 'W') ? 1 : 2; char rival = (color == 'W') ? 'B' : 'W'; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; if (x < 0 || x >= W || y < 0 || y >= H) { return; } if (area[y][x] == rival) { return; } if (!visit[y][x]) { visit[y][x] = 1; if (area[y][x] != 'W' && area[y][x] != 'B') { ans[y][x] |= mark; } rep(i, 4) { dfs(x + dx[i], y + dy[i], color); } } return; } int main() { while (cin >> W >> H && W) { int black = 0, white = 0; init(); rep(h, H) { rep(w, W) { cin >> area[h][w]; } } rep(h, H) { rep(w, W) { if (area[h][w] != '.') { clear(); dfs(w, h, area[h][w]); } } } rep(h, H) { rep(w, W) { int num = ans[h][w]; if (num == 1) { white++; } if (num == 2) { black++; } } } cout << black << " " << white << endl; } return 0; }
replace
26
27
26
27
0
p01139
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int w, h; vector<string> ss; bool is_white[103][103]; bool is_black[103][103]; void dfs(int x_, int y_, bool (*f_)[103], bool f2) { // cout<<x_<<","<<y_<<endl; if (f_[x_][y_] || (ss[x_][y_] != '.' && f2)) return; f_[x_][y_] = true; rep(i, 4) { int x = x_ + dx[i]; int y = y_ + dy[i]; if (0 <= x && x < ss.size() && 0 <= y && y < ss[x].size()) { dfs(x, y, f_, true); } } } void solve() { rep(i, 103) rep(j, 103) is_white[i][j] = is_black[i][j] = false; ss.resize(w); rep(i, h) { string t; cin >> t; ss[i] = t; } int ans_b = 0, ans_w = 0; rep(i, ss.size()) { rep(j, ss[i].size()) { if (ss[i][j] == 'B') dfs(i, j, is_black, false); if (ss[i][j] == 'W') dfs(i, j, is_white, false); } } rep(i, ss.size()) rep(j, ss[i].size()) { // cout<<i<<","<<j<<":"<<is_white[i][j]<<","<<is_black[i][j]<<ss[i][j]<<endl; if (ss[i][j] == '.' && (is_white[i][j] ^ is_black[i][j])) { if (is_white[i][j]) ans_w++; else ans_b++; } } cout << ans_b << " " << ans_w << endl; ss.clear(); } int main() { while (cin >> w >> h) { if (w + h == 0) return 0; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int w, h; vector<string> ss; bool is_white[103][103]; bool is_black[103][103]; void dfs(int x_, int y_, bool (*f_)[103], bool f2) { // cout<<x_<<","<<y_<<endl; if (f_[x_][y_] || (ss[x_][y_] != '.' && f2)) return; f_[x_][y_] = true; rep(i, 4) { int x = x_ + dx[i]; int y = y_ + dy[i]; if (0 <= x && x < ss.size() && 0 <= y && y < ss[x].size()) { dfs(x, y, f_, true); } } } void solve() { rep(i, 103) rep(j, 103) is_white[i][j] = is_black[i][j] = false; ss.resize(h); rep(i, h) { string t; cin >> t; ss[i] = t; } int ans_b = 0, ans_w = 0; rep(i, ss.size()) { rep(j, ss[i].size()) { if (ss[i][j] == 'B') dfs(i, j, is_black, false); if (ss[i][j] == 'W') dfs(i, j, is_white, false); } } rep(i, ss.size()) rep(j, ss[i].size()) { // cout<<i<<","<<j<<":"<<is_white[i][j]<<","<<is_black[i][j]<<ss[i][j]<<endl; if (ss[i][j] == '.' && (is_white[i][j] ^ is_black[i][j])) { if (is_white[i][j]) ans_w++; else ans_b++; } } cout << ans_b << " " << ans_w << endl; ss.clear(); } int main() { while (cin >> w >> h) { if (w + h == 0) return 0; solve(); } return 0; }
replace
28
29
28
29
0
p01139
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <vector> using namespace std; #define INF 999999999 vector<string> a(52); queue<pair<int, int>> q[2]; bool c[2][52][52]; int f[2]; void search(int x, int y, int z) { pair<int, int> r; if (a[x][y] == '.') f[z]++; if (a[x + 1][y] == '.' && c[z][x + 1][y] == 0) { c[z][x + 1][y] = 1; r.first = x + 1; r.second = y; q[z].push(r); } if (a[x - 1][y] == '.' && c[z][x - 1][y] == 0) { c[z][x - 1][y] = 1; r.first = x - 1; r.second = y; q[z].push(r); } if (a[x][y - 1] == '.' && c[z][x][y - 1] == 0) { c[z][x][y - 1] = 1; r.first = x; r.second = y - 1; q[z].push(r); } if (a[x][y + 1] == '.' && c[z][x][y + 1] == 0) { c[z][x][y + 1] = 1; r.first = x; r.second = y + 1; q[z].push(r); } q[z].pop(); if (!q[z].empty()) search(q[z].front().first, q[z].front().second, z); } int main() { int i, j, w, h; string s; pair<int, int> d; while (1) { cin >> w >> h; if (!w) break; for (i = 0; i <= h + 1; i++) { for (j = 0; j <= w; j++) { c[0][i][j] = 0; c[1][i][j] = 0; if (i == 0 || i == h + 1) a[i][j] = '#'; } } for (i = 1; i <= h; i++) { cin >> s; a[i] = "#" + s + "#"; } int common = 0; f[0] = 0; f[1] = 0; for (i = 1; i <= h; i++) { for (j = 1; j <= w; j++) { d.first = i; d.second = j; if (a[i][j] == 'B') { c[0][i][j] = 1; q[0].push(d); } else if (a[i][j] == 'W') { c[1][i][j] = 1; q[1].push(d); } else common++; } } if (q[0].empty() && q[1].empty()) { cout << "0 0" << endl; } else { if (!q[0].empty()) search(q[0].front().first, q[0].front().second, 0); if (!q[1].empty()) search(q[1].front().first, q[1].front().second, 1); // cout << common << " " << f[0] << " " << f[1] << endl; cout << common - f[1] << " " << common - f[0] << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <vector> using namespace std; #define INF 999999999 vector<string> a(52); queue<pair<int, int>> q[2]; bool c[2][52][52]; int f[2]; void search(int x, int y, int z) { pair<int, int> r; if (a[x][y] == '.') f[z]++; if (a[x + 1][y] == '.' && c[z][x + 1][y] == 0) { c[z][x + 1][y] = 1; r.first = x + 1; r.second = y; q[z].push(r); } if (a[x - 1][y] == '.' && c[z][x - 1][y] == 0) { c[z][x - 1][y] = 1; r.first = x - 1; r.second = y; q[z].push(r); } if (a[x][y - 1] == '.' && c[z][x][y - 1] == 0) { c[z][x][y - 1] = 1; r.first = x; r.second = y - 1; q[z].push(r); } if (a[x][y + 1] == '.' && c[z][x][y + 1] == 0) { c[z][x][y + 1] = 1; r.first = x; r.second = y + 1; q[z].push(r); } q[z].pop(); if (!q[z].empty()) search(q[z].front().first, q[z].front().second, z); } int main() { int i, j, w, h; string s; pair<int, int> d; while (1) { cin >> w >> h; if (!w) break; for (i = 0; i <= h + 1; i++) { for (j = 0; j <= w; j++) { c[0][i][j] = 0; c[1][i][j] = 0; if (i == 0 || i == h + 1) a[i] = "####################################################"; } } for (i = 1; i <= h; i++) { cin >> s; a[i] = "#" + s + "#"; } int common = 0; f[0] = 0; f[1] = 0; for (i = 1; i <= h; i++) { for (j = 1; j <= w; j++) { d.first = i; d.second = j; if (a[i][j] == 'B') { c[0][i][j] = 1; q[0].push(d); } else if (a[i][j] == 'W') { c[1][i][j] = 1; q[1].push(d); } else common++; } } if (q[0].empty() && q[1].empty()) { cout << "0 0" << endl; } else { if (!q[0].empty()) search(q[0].front().first, q[0].front().second, 0); if (!q[1].empty()) search(q[1].front().first, q[1].front().second, 1); // cout << common << " " << f[0] << " " << f[1] << endl; cout << common - f[1] << " " << common - f[0] << endl; } } return 0; }
replace
63
64
63
64
0
p01139
C++
Memory Limit Exceeded
#define DEBUG_ON #define CONDITION true using namespace std; /*{{{*/ #include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/time.h> #include <vector> #define INF (1e9) static const double PI = acos(-1.0); static const double EPS = 1e-10; typedef long long int LL; typedef unsigned long long int ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<string> VS; typedef pair<int, int> PII; typedef complex<double> P; #define FOR(i, b, e) for (typeof(e) i = (b); i != (e); i < (e) ? ++i : --i) #define REP(i, n) FOR(i, 0, n) #define IFC(c) \ if (c) \ continue; #define IFB(c) \ if (c) \ break; #define IFR(c, r) \ if (c) \ return r; #define OPOVER(_op, _type) inline bool operator _op(const _type &t) const #define arrsz(a) (sizeof(a) / sizeof(a[0])) #define F first #define S second #define MP(a, b) make_pair(a, b) #define SZ(a) ((LL)a.size()) #define PB(e) push_back(e) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(c, it) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define EXIST(s, e) ((s).find(e) != (s).end()) #define BIT(n) (assert(n < 64), (1ULL << (n))) #define BITOF(n, m) (assert(m < 64), ((ULL)(n) >> (m)&1)) #define RANGE(a, b, c) ((a) <= (b) && (b) <= (c)) #define PQ priority_queue #define SC static_cast #ifdef DEBUG_ON #define dprt(fmt, ...) \ if (CONDITION) \ fprintf(stderr, fmt, ##__VA_ARGS__) #define darr(a) \ if (CONDITION) \ copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \ cerr << endl #define darr_range(a, f, t) \ if (CONDITION) \ copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \ cerr << endl #define dvec(v) \ if (CONDITION) \ copy(ALL(v), ostream_iterator<int>(cerr, " ")); \ cerr << endl #define darr2(a, n, m) \ if (CONDITION) \ FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); } #define dvec2(v) \ if (CONDITION) \ FOR(i, 0, SZ(v)) { dvec((v)[i]); } #define WAIT() \ if (CONDITION) { \ string _wait_; \ cerr << "(hit return to continue)" << endl; \ getline(cin, _wait_); \ } #define dump(x) \ if (CONDITION) \ cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; #define dumpf() \ if (CONDITION) \ cerr << __PRETTY_FUNCTION__ << endl; #define dumpv(x) \ if (CONDITION) \ cerr << " [L:" << __LINE__ << "] " << #x << " = "; \ REP(q, (x).size()) cerr << (x)[q] << " "; \ cerr << endl; #define where() \ if (CONDITION) \ cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \ << "]" << endl; #define show_bits(b, s) \ if (CONDITION) { \ REP(i, s) { \ cerr << BITOF(b, s - 1 - i); \ if (i % 4 == 3) \ cerr << ' '; \ } \ cerr << endl; \ } #else #define cerr \ if (0) \ cerr #define dprt(fmt, ...) #define darr(a) #define darr_range(a, f, t) #define dvec(v) #define darr2(a, n, m) #define dvec2(v) #define WAIT() #define dump(x) #define dumpf() #define dumpv(x) #define where() #define show_bits(b, s) #endif /* Inline functions */ inline int onbits_count(ULL b) { int c = 0; while (b != 0) { c += (b & 1); b >>= 1; } return c; } inline int bits_count(ULL b) { int c = 0; while (b != 0) { ++c; b >>= 1; } return c; } 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(); } inline double now() { struct timeval tv; gettimeofday(&tv, NULL); return (static_cast<double>(tv.tv_sec) + static_cast<double>(tv.tv_usec) * 1e-6); } inline VS split(string s, char delimiter) { VS v; string t; REP(i, s.length()) { if (s[i] == delimiter) v.PB(t), t = ""; else t += s[i]; } v.PB(t); return v; } /* Tweaks */ template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &d) { return s << "(" << d.first << ", " << d.second << ")"; } /* Frequent stuffs */ int n_dir = 4; int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; /* CSS order */ enum direction { UP, RIGHT, DOWN, LEFT }; // int n_dir = 8; // int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy[] = {-1, -1, 0, 1, 1, 1, 0, -1}; // enum direction { // UP, UPRIGHT, RIGHT, DOWNRIGHT, DOWN, DOWNLEFT, LEFT, UPLEFT // } #define FORDIR(d) REP(d, n_dir) /*}}}*/ int w, h; VVC field; VVB adj_white; VVB adj_black; void spread(char color, int sy, int sx) { VVB visited = VVB(h, VB(w, false)); queue<PII> q; q.push(MP(sy, sx)); while (!q.empty()) { int y = q.front().F, x = q.front().S; q.pop(); visited[y][x] = true; if (color == 'W') { adj_white[y][x] = true; } else { adj_black[y][x] = true; } REP(d, 4) { int ny = y + dy[d], nx = x + dx[d]; IFC(!(0 <= ny && ny < h) || !(0 <= nx && nx < w)); if (!visited[ny][nx] && field[ny][nx] == '.') { q.push(MP(ny, nx)); } } } } int main() { std::ios_base::sync_with_stdio(false); while (cin >> w >> h, w | h) { field = VVC(h, VC(w)); REP(i, h) { REP(j, w) { cin >> field[i][j]; } } adj_black = VVB(h, VB(w, false)); adj_white = VVB(h, VB(w, false)); REP(i, h) { REP(j, w) { if (field[i][j] != '.') { spread(field[i][j], i, j); } } } int white = 0, black = 0; REP(i, h) { REP(j, w) { if (field[i][j] == '.') { if (adj_white[i][j] && !adj_black[i][j]) { ++white; } if (!adj_white[i][j] && adj_black[i][j]) { ++black; } } } } cout << black << " " << white << endl; } } // vim: foldmethod=marker
#define DEBUG_ON #define CONDITION true using namespace std; /*{{{*/ #include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/time.h> #include <vector> #define INF (1e9) static const double PI = acos(-1.0); static const double EPS = 1e-10; typedef long long int LL; typedef unsigned long long int ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<string> VS; typedef pair<int, int> PII; typedef complex<double> P; #define FOR(i, b, e) for (typeof(e) i = (b); i != (e); i < (e) ? ++i : --i) #define REP(i, n) FOR(i, 0, n) #define IFC(c) \ if (c) \ continue; #define IFB(c) \ if (c) \ break; #define IFR(c, r) \ if (c) \ return r; #define OPOVER(_op, _type) inline bool operator _op(const _type &t) const #define arrsz(a) (sizeof(a) / sizeof(a[0])) #define F first #define S second #define MP(a, b) make_pair(a, b) #define SZ(a) ((LL)a.size()) #define PB(e) push_back(e) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(c, it) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define EXIST(s, e) ((s).find(e) != (s).end()) #define BIT(n) (assert(n < 64), (1ULL << (n))) #define BITOF(n, m) (assert(m < 64), ((ULL)(n) >> (m)&1)) #define RANGE(a, b, c) ((a) <= (b) && (b) <= (c)) #define PQ priority_queue #define SC static_cast #ifdef DEBUG_ON #define dprt(fmt, ...) \ if (CONDITION) \ fprintf(stderr, fmt, ##__VA_ARGS__) #define darr(a) \ if (CONDITION) \ copy((a), (a) + arrsz(a), ostream_iterator<int>(cerr, " ")); \ cerr << endl #define darr_range(a, f, t) \ if (CONDITION) \ copy((a) + (f), (a) + (t), ostream_iterator<int>(cerr, " ")); \ cerr << endl #define dvec(v) \ if (CONDITION) \ copy(ALL(v), ostream_iterator<int>(cerr, " ")); \ cerr << endl #define darr2(a, n, m) \ if (CONDITION) \ FOR(i, 0, (n)) { darr_range((a)[i], 0, (m)); } #define dvec2(v) \ if (CONDITION) \ FOR(i, 0, SZ(v)) { dvec((v)[i]); } #define WAIT() \ if (CONDITION) { \ string _wait_; \ cerr << "(hit return to continue)" << endl; \ getline(cin, _wait_); \ } #define dump(x) \ if (CONDITION) \ cerr << " [L" << __LINE__ << "] " << #x << " = " << (x) << endl; #define dumpf() \ if (CONDITION) \ cerr << __PRETTY_FUNCTION__ << endl; #define dumpv(x) \ if (CONDITION) \ cerr << " [L:" << __LINE__ << "] " << #x << " = "; \ REP(q, (x).size()) cerr << (x)[q] << " "; \ cerr << endl; #define where() \ if (CONDITION) \ cerr << __FILE__ << ": " << __PRETTY_FUNCTION__ << " [L: " << __LINE__ \ << "]" << endl; #define show_bits(b, s) \ if (CONDITION) { \ REP(i, s) { \ cerr << BITOF(b, s - 1 - i); \ if (i % 4 == 3) \ cerr << ' '; \ } \ cerr << endl; \ } #else #define cerr \ if (0) \ cerr #define dprt(fmt, ...) #define darr(a) #define darr_range(a, f, t) #define dvec(v) #define darr2(a, n, m) #define dvec2(v) #define WAIT() #define dump(x) #define dumpf() #define dumpv(x) #define where() #define show_bits(b, s) #endif /* Inline functions */ inline int onbits_count(ULL b) { int c = 0; while (b != 0) { c += (b & 1); b >>= 1; } return c; } inline int bits_count(ULL b) { int c = 0; while (b != 0) { ++c; b >>= 1; } return c; } 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(); } inline double now() { struct timeval tv; gettimeofday(&tv, NULL); return (static_cast<double>(tv.tv_sec) + static_cast<double>(tv.tv_usec) * 1e-6); } inline VS split(string s, char delimiter) { VS v; string t; REP(i, s.length()) { if (s[i] == delimiter) v.PB(t), t = ""; else t += s[i]; } v.PB(t); return v; } /* Tweaks */ template <typename T1, typename T2> ostream &operator<<(ostream &s, const pair<T1, T2> &d) { return s << "(" << d.first << ", " << d.second << ")"; } /* Frequent stuffs */ int n_dir = 4; int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; /* CSS order */ enum direction { UP, RIGHT, DOWN, LEFT }; // int n_dir = 8; // int dx[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy[] = {-1, -1, 0, 1, 1, 1, 0, -1}; // enum direction { // UP, UPRIGHT, RIGHT, DOWNRIGHT, DOWN, DOWNLEFT, LEFT, UPLEFT // } #define FORDIR(d) REP(d, n_dir) /*}}}*/ int w, h; VVC field; VVB adj_white; VVB adj_black; void spread(char color, int sy, int sx) { VVB visited = VVB(h, VB(w, false)); queue<PII> q; q.push(MP(sy, sx)); while (!q.empty()) { int y = q.front().F, x = q.front().S; q.pop(); visited[y][x] = true; if (color == 'W') { adj_white[y][x] = true; } else { adj_black[y][x] = true; } REP(d, 4) { int ny = y + dy[d], nx = x + dx[d]; IFC(!(0 <= ny && ny < h) || !(0 <= nx && nx < w)); IFC(color == 'W' && adj_white[ny][nx]); IFC(color == 'B' && adj_black[ny][nx]); if (!visited[ny][nx] && field[ny][nx] == '.') { q.push(MP(ny, nx)); } } } } int main() { std::ios_base::sync_with_stdio(false); while (cin >> w >> h, w | h) { field = VVC(h, VC(w)); REP(i, h) { REP(j, w) { cin >> field[i][j]; } } adj_black = VVB(h, VB(w, false)); adj_white = VVB(h, VB(w, false)); REP(i, h) { REP(j, w) { if (field[i][j] != '.') { spread(field[i][j], i, j); } } } int white = 0, black = 0; REP(i, h) { REP(j, w) { if (field[i][j] == '.') { if (adj_white[i][j] && !adj_black[i][j]) { ++white; } if (!adj_white[i][j] && adj_black[i][j]) { ++black; } } } } cout << black << " " << white << endl; } } // vim: foldmethod=marker
insert
242
242
242
244
MLE
p01139
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) int A[60][60]; int B[60][60]; int x, y; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int dfs(int x, int y) { A[x][y] = 3; int ans = 0; REP(i, 4) { int xx = dx[i] + x; int yy = dy[i] + y; if (A[xx][yy] == 0) { ans += dfs(xx, yy); } } return ans + 1; } int dfs2(int x, int y) { B[x][y] = 3; int ans = 0; REP(i, 4) { int xx = dx[i] + x; int yy = dy[i] + y; if (B[xx][yy] == 0) { ans += dfs2(xx, yy); } } return ans + 1; } int main() { int W, H; while (cin >> W >> H, W + H) { REP(i, 30) { REP(j, 30) { A[i][j] = 1; B[i][j] = 1; } } REP(i, H) { string s; cin >> s; REP(j, W) { if (s[j] == '.') { A[i + 1][j + 1] = 0; B[i + 1][j + 1] = 0; } if (s[j] == 'B') { A[i + 1][j + 1] = 2; } if (s[j] == 'W') { B[i + 1][j + 1] = 2; } } } REP(i, H + 1) { REP(j, W + 1) { if (A[i][j] == 2) { REP(k, 4) { int x = i + dx[k]; int y = j + dy[k]; if (A[x][y] == 0) { dfs(x, y); } } } } } REP(i, H + 1) { REP(j, W + 1) { if (B[i][j] == 2) { REP(k, 4) { int x = i + dx[k]; int y = j + dy[k]; if (B[x][y] == 0) { dfs2(x, y); } } } } } int w = 0; int b = 0; REP(i, H + 1) { REP(j, W + 1) { if (A[i][j] == 3 && B[i][j] != 3) b++; if (A[i][j] != 3 && B[i][j] == 3) w++; } } cout << b << " " << w << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++) int A[60][60]; int B[60][60]; int x, y; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int dfs(int x, int y) { A[x][y] = 3; int ans = 0; REP(i, 4) { int xx = dx[i] + x; int yy = dy[i] + y; if (A[xx][yy] == 0) { ans += dfs(xx, yy); } } return ans + 1; } int dfs2(int x, int y) { B[x][y] = 3; int ans = 0; REP(i, 4) { int xx = dx[i] + x; int yy = dy[i] + y; if (B[xx][yy] == 0) { ans += dfs2(xx, yy); } } return ans + 1; } int main() { int W, H; while (cin >> W >> H, W + H) { REP(i, 60) { REP(j, 60) { A[i][j] = 1; B[i][j] = 1; } } REP(i, H) { string s; cin >> s; REP(j, W) { if (s[j] == '.') { A[i + 1][j + 1] = 0; B[i + 1][j + 1] = 0; } if (s[j] == 'B') { A[i + 1][j + 1] = 2; } if (s[j] == 'W') { B[i + 1][j + 1] = 2; } } } REP(i, H + 1) { REP(j, W + 1) { if (A[i][j] == 2) { REP(k, 4) { int x = i + dx[k]; int y = j + dy[k]; if (A[x][y] == 0) { dfs(x, y); } } } } } REP(i, H + 1) { REP(j, W + 1) { if (B[i][j] == 2) { REP(k, 4) { int x = i + dx[k]; int y = j + dy[k]; if (B[x][y] == 0) { dfs2(x, y); } } } } } int w = 0; int b = 0; REP(i, H + 1) { REP(j, W + 1) { if (A[i][j] == 3 && B[i][j] != 3) b++; if (A[i][j] != 3 && B[i][j] == 3) w++; } } cout << b << " " << w << endl; } return 0; }
replace
37
39
37
39
0
p01140
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int w[1500], h[1500]; cin >> n >> m; for (int i = 0; i < n; i++) scanf("%d", &w[i]); for (int i = 0; i < m; i++) scanf("%d", &h[i]); while (n) { vector<int> x; vector<int> y; for (int i = 0; i < n; i++) { int a = 0; for (int j = i; j < n; j++) { a += w[j]; x[a]++; } } for (int i = 0; i < m; i++) { int b = 0; for (int j = i; j < m; j++) { b += h[j]; y[b]++; } } int ave = 0; for (int i = 0; i < 1500 * 1000; i++) { // if(y[i]!=0)cout << i << " " << y[i] << " / "; ave += x[i] * y[i]; } cout << ave << endl; cin >> n >> m; for (int i = 0; i < n; i++) scanf("%d", &w[i]); for (int i = 0; i < m; i++) scanf("%d", &h[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int w[1500], h[1500]; cin >> n >> m; for (int i = 0; i < n; i++) scanf("%d", &w[i]); for (int i = 0; i < m; i++) scanf("%d", &h[i]); while (n) { vector<int> x(1501 * 1001); vector<int> y(1501 * 1001); for (int i = 0; i < n; i++) { int a = 0; for (int j = i; j < n; j++) { a += w[j]; x[a]++; } } for (int i = 0; i < m; i++) { int b = 0; for (int j = i; j < m; j++) { b += h[j]; y[b]++; } } int ave = 0; for (int i = 0; i < 1500 * 1000; i++) { // if(y[i]!=0)cout << i << " " << y[i] << " / "; ave += x[i] * y[i]; } cout << ave << endl; cin >> n >> m; for (int i = 0; i < n; i++) scanf("%d", &w[i]); for (int i = 0; i < m; i++) scanf("%d", &h[i]); } return 0; }
replace
12
14
12
14
-11
p01140
C++
Runtime Error
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1e9 + 7 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long using namespace std; int main() { int n, m; while (cin >> n >> m, n) { int num[2500100] = {}; int takasa[1600] = {}; short num2[1600] = {}; ll ans = 0; for (int i = 1; i <= n; i++) { int a; cin >> a; takasa[i] = takasa[i - 1] + a; } for (int i = 1; i <= m; i++) { int a; cin >> a; num2[i] = num2[i - 1] + a; for (int j = 0; j < i; j++) { num[num2[i] - num2[j]]++; } } for (int i = 0; i <= n; i++) { for (int j = 0; j < i; j++) { ans += num[takasa[i] - takasa[j]]; } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define INF 1e9 #define llINF 1e18 #define MOD 1e9 + 7 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long using namespace std; int main() { int n, m; while (cin >> n >> m, n) { int num[2500100] = {}; int takasa[10600] = {}; int num2[10600] = {}; ll ans = 0; for (int i = 1; i <= n; i++) { int a; cin >> a; takasa[i] = takasa[i - 1] + a; } for (int i = 1; i <= m; i++) { int a; cin >> a; num2[i] = num2[i - 1] + a; for (int j = 0; j < i; j++) { num[num2[i] - num2[j]]++; } } for (int i = 0; i <= n; i++) { for (int j = 0; j < i; j++) { ans += num[takasa[i] - takasa[j]]; } } cout << ans << endl; } return 0; }
replace
15
17
15
17
-11
p01140
C++
Runtime Error
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <stack> #include <string> #include <vector> #define rep(i, x) for (int i = 0; i < x; i++) #define rrep(i, x) for (int i = x - 1; i >= 0; i--) #define rep_to(a, i, x) for (int i = a; i < x; i++) using namespace std; int main() { int N, M; while (cin >> N >> M && M && N) { int h[10000] = {}; int w[10000] = {}; unsigned long long sum_h[10000] = {}; unsigned long long sum_w[10000] = {}; long long h_c[225000] = {}; long long w_c[225000] = {}; rep(i, N) { cin >> h[i]; sum_h[i + 1] = sum_h[i] + h[i]; } rep(i, M) { cin >> w[i]; sum_w[i + 1] = sum_w[i] + w[i]; } rep(i, N) rep(j, N - i) h_c[sum_h[j + i + 1] - sum_h[j]]++; rep(i, M) rep(j, M - i) w_c[sum_w[j + i + 1] - sum_w[j]]++; long long count = 0; rep(i, min(sum_h[N], sum_w[M]) + 1) count += h_c[i] * w_c[i]; cout << count << endl; } return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <stack> #include <string> #include <vector> #define rep(i, x) for (int i = 0; i < x; i++) #define rrep(i, x) for (int i = x - 1; i >= 0; i--) #define rep_to(a, i, x) for (int i = a; i < x; i++) using namespace std; int main() { int N, M; while (cin >> N >> M && M && N) { int h[10000] = {}; int w[10000] = {}; unsigned long long sum_h[10000] = {}; unsigned long long sum_w[10000] = {}; long long h_c[510000] = {}; long long w_c[500000] = {}; rep(i, N) { cin >> h[i]; sum_h[i + 1] = sum_h[i] + h[i]; } rep(i, M) { cin >> w[i]; sum_w[i + 1] = sum_w[i] + w[i]; } rep(i, N) rep(j, N - i) h_c[sum_h[j + i + 1] - sum_h[j]]++; rep(i, M) rep(j, M - i) w_c[sum_w[j + i + 1] - sum_w[j]]++; long long count = 0; rep(i, min(sum_h[N], sum_w[M]) + 1) count += h_c[i] * w_c[i]; cout << count << endl; } return 0; }
replace
24
26
24
26
0
p01140
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAX = 100000; int main() { for (int n, m; cin >> n >> m, n && m;) { int h[1500], w[1500], a0[MAX + 10] = {}, a1[MAX + 10] = {}; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < m; i++) cin >> w[i]; for (int i = 1; i <= n; i++) for (int j = 0; j < n - i + 1; j++) { int r = 0; for (int k = 0; k < i; k++) r += h[j + k]; a0[r]++; } for (int i = 1; i <= m; i++) for (int j = 0; j < m - i + 1; j++) { int r = 0; for (int k = 0; k < i; k++) r += w[j + k]; a1[r]++; } int r = 0; for (int i = 1; i <= MAX; i++) r += a0[i] * a1[i]; cout << r << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX = 1500000; int main() { for (int n, m; cin >> n >> m, n && m;) { int h[1500], w[1500], a0[MAX + 10] = {}, a1[MAX + 10] = {}; for (int i = 0; i < n; i++) cin >> h[i]; for (int i = 0; i < m; i++) cin >> w[i]; for (int i = 1; i <= n; i++) for (int j = 0; j < n - i + 1; j++) { int r = 0; for (int k = 0; k < i; k++) r += h[j + k]; a0[r]++; } for (int i = 1; i <= m; i++) for (int j = 0; j < m - i + 1; j++) { int r = 0; for (int k = 0; k < i; k++) r += w[j + k]; a1[r]++; } int r = 0; for (int i = 1; i <= MAX; i++) r += a0[i] * a1[i]; cout << r << endl; } return 0; }
replace
2
3
2
3
0
p01140
Python
Time Limit Exceeded
from collections import Counter while True: N, M = map(int, input().split()) if N == 0 and M == 0: break H = [int(input()) for _ in range(N)] W = [int(input()) for _ in range(M)] all_H = Counter( sorted([sum(H[i:j]) for i in range(N) for j in range(i + 1, N + 1)]) ) all_W = Counter( sorted([sum(W[i:j]) for i in range(M) for j in range(i + 1, M + 1)]) ) ans = 0 for k, v in all_H.items(): if k in all_H: ans += v * all_W[k] print(ans)
from collections import Counter while True: N, M = map(int, input().split()) if N == 0 and M == 0: break H = [int(input()) for _ in range(N)] W = [int(input()) for _ in range(M)] all_H = [] for i in range(N): s = 0 for j in range(i, N): s += H[j] all_H.append(s) all_W = [] for i in range(M): s = 0 for j in range(i, M): s += W[j] all_W.append(s) all_H = Counter(all_H) all_W = Counter(all_W) ans = 0 for k, v in all_H.items(): if k in all_H: ans += v * all_W[k] print(ans)
replace
8
14
8
25
TLE
p01140
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int w, h; cin >> w >> h; int wl[1501] = {}, hl[1501] = {}; int wb, hb; int i, j, k; while (w != 0) { for (i = 0; i < w; i++) { cin >> wb; wl[i + 1] = wl[i] + wb; } for (i = 0; i < h; i++) { cin >> hb; hl[i + 1] = hl[i] + hb; } vector<int> ws, hs; for (i = 0; i <= w; i++) { for (j = i + 1; j <= w; j++) { ws.push_back(wl[j] - wl[i]); } } for (i = 0; i <= h; i++) { for (j = i + 1; j <= h; j++) { hs.push_back(hl[j] - hl[i]); } } sort(ws.begin(), ws.end()); sort(hs.begin(), hs.end()); /* for(i=0;i<ws.size();i++) cout << ws[i] << ","; cout << endl; for(i=0;i<hs.size();i++) cout << hs[i] << ","; cout << endl; */ int wc = 0, hc = 0; int x, y; int o = 0; while (!(wc + 1 >= ws.size() && hc + 1 >= hs.size())) { if (ws[wc] == hs[hc]) { x = 0; y = 0; while (ws[wc + x] == ws[wc] && wc + x < ws.size()) x++; while (hs[hc + y] == hs[hc] && hc + y < hs.size()) y++; // cout << x*y << endl; o += x * y; wc += x; hc += y; } else if (ws[wc] > hs[hc]) { while (ws[wc] > hs[hc] && hc < hs.size()) hc++; } else { while (ws[wc] < hs[hc] && wc < ws.size()) wc++; } // cout << wc<<":"<<hc<<endl; } cout << o << endl; cin >> w >> h; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int w, h; cin >> w >> h; int wl[1501] = {}, hl[1501] = {}; int wb, hb; int i, j, k; while (w != 0) { for (i = 0; i < w; i++) { cin >> wb; wl[i + 1] = wl[i] + wb; } for (i = 0; i < h; i++) { cin >> hb; hl[i + 1] = hl[i] + hb; } vector<int> ws, hs; for (i = 0; i <= w; i++) { for (j = i + 1; j <= w; j++) { ws.push_back(wl[j] - wl[i]); } } for (i = 0; i <= h; i++) { for (j = i + 1; j <= h; j++) { hs.push_back(hl[j] - hl[i]); } } sort(ws.begin(), ws.end()); sort(hs.begin(), hs.end()); /* for(i=0;i<ws.size();i++) cout << ws[i] << ","; cout << endl; for(i=0;i<hs.size();i++) cout << hs[i] << ","; cout << endl; */ int wc = 0, hc = 0; int x, y; int o = 0; while (!(wc >= ws.size() || hc >= hs.size())) { if (ws[wc] == hs[hc]) { x = 0; y = 0; while (ws[wc + x] == ws[wc] && wc + x < ws.size()) x++; while (hs[hc + y] == hs[hc] && hc + y < hs.size()) y++; // cout << x*y << endl; o += x * y; wc += x; hc += y; } else if (ws[wc] > hs[hc]) { while (ws[wc] > hs[hc] && hc < hs.size()) hc++; } else { while (ws[wc] < hs[hc] && wc < ws.size()) wc++; } // cout << wc<<":"<<hc<<endl; } cout << o << endl; cin >> w >> h; } return 0; }
replace
44
45
44
45
TLE
p01140
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int w[1501] = {0}, h[1501] = {0}; int W[2250000] = {0}, H[2250000] = {0}; int sum(int *a, int i, int n, int size) { int s = 0; for (int j = n; j--;) { if (i >= size) { return 0; } s += a[i++]; } return s; } int main() { int n, m, w_, h_; while (cin >> n >> m, n || m) { // int cnt_h[1001] = {0} int cnt_w[100000] = {0}; for (int i = 0; i < n; i++) { cin >> h[i]; } int i_ = 0; for (int j = 1; j <= n; j++) { for (int i = 0; i + j <= n; i++) { H[i_++] = sum(h, i, j, n); } } /*for(int i=0 ; i<i_ ; i++ ){ cnt_h[ H[i] ]++; }*/ for (int i = 0; i < m; i++) { cin >> w[i]; } int j_ = 0; for (int j = 1; j <= m; j++) { for (int i = 0; i + j <= m; i++) { W[j_++] = sum(w, i, j, m); } } for (int i = 0; i < j_; i++) { cnt_w[W[i]] += 1; } /*for(int i=0 ; i<j_ ; i++ ){ cout << "W[" << i << "] : " << W[i] << endl; }*/ int ans = 0; for (int i = 0; i < i_; i++) { // if( H[i] <= 1000 && H[i] >= 0 ) ans += cnt_w[H[i]]; // for(int j=0 ; j < j_ ; j++ ){ // if( W[j] == H[i] ) ans++; // } } // cout << "ans : " << ans << endl; cout << ans << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int w[1501] = {0}, h[1501] = {0}; int W[2250000] = {0}, H[2250000] = {0}; int sum(int *a, int i, int n, int size) { int s = 0; for (int j = n; j--;) { if (i >= size) { return 0; } s += a[i++]; } return s; } int main() { int n, m, w_, h_; while (cin >> n >> m, n || m) { // int cnt_h[1001] = {0} int cnt_w[1000000] = {0}; for (int i = 0; i < n; i++) { cin >> h[i]; } int i_ = 0; for (int j = 1; j <= n; j++) { for (int i = 0; i + j <= n; i++) { H[i_++] = sum(h, i, j, n); } } /*for(int i=0 ; i<i_ ; i++ ){ cnt_h[ H[i] ]++; }*/ for (int i = 0; i < m; i++) { cin >> w[i]; } int j_ = 0; for (int j = 1; j <= m; j++) { for (int i = 0; i + j <= m; i++) { W[j_++] = sum(w, i, j, m); } } for (int i = 0; i < j_; i++) { cnt_w[W[i]] += 1; } /*for(int i=0 ; i<j_ ; i++ ){ cout << "W[" << i << "] : " << W[i] << endl; }*/ int ans = 0; for (int i = 0; i < i_; i++) { // if( H[i] <= 1000 && H[i] >= 0 ) ans += cnt_w[H[i]]; // for(int j=0 ; j < j_ ; j++ ){ // if( W[j] == H[i] ) ans++; // } } // cout << "ans : " << ans << endl; cout << ans << endl; } }
replace
23
24
23
24
0
p01140
C++
Time Limit Exceeded
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #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; // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; while (cin >> N >> M, N) { VI h(N + 1, 0), w(M + 1, 0); REP(i, N) { int x; cin >> x; h[i + 1] = h[i] + x; } REP(i, M) { int x; cin >> x; w[i + 1] = w[i] + x; } int ans = 0; if (N < M) { for (int i = 0; i <= N; ++i) for (int j = 0; j < i; ++j) { int sz = h[i] - h[j], s = 0, e = 0; for (; e <= M;) { int tmp = w[e] - w[s]; if (tmp == sz) { ++ans; ++e, ++s; } else if (tmp < sz) { ++e; } else { ++s; } } } } else { for (int i = 0; i <= M; ++i) for (int j = 0; j < i; ++j) { int sz = w[i] - w[j], s = 0, e = 0; for (; e <= N;) { int tmp = h[e] - h[s]; if (tmp == sz) { ++ans; ++e, ++s; } else if (tmp < sz) { ++e; } else { ++s; } } } } cout << ans << endl; } return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #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; // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; while (cin >> N >> M, N) { VI h(N + 1, 0), w(M + 1, 0); REP(i, N) { int x; cin >> x; h[i + 1] = h[i] + x; } REP(i, M) { int x; cin >> x; w[i + 1] = w[i] + x; } LL ans = 0; map<int, int> szx, szy; for (int i = 0; i <= M; ++i) for (int j = 0; j < i; ++j) szx[w[i] - w[j]]++; for (int i = 0; i <= N; ++i) for (int j = 0; j < i; ++j) { ans += szx[h[i] - h[j]]; } cout << ans << endl; } return 0; }
replace
75
109
75
86
TLE
p01140
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> using namespace std; int main() { int H, W; while (cin >> H >> W, H + W) { int h[1001] = {}; int w[1001] = {}; map<int, int> setH; map<int, int> setW; for (int i = 1; i <= H; i++) cin >> h[i]; for (int i = 1; i <= W; i++) cin >> w[i]; for (int i = 1; i <= H; i++) h[i] += h[i - 1]; for (int i = 1; i <= W; i++) w[i] += w[i - 1]; for (int i = 0; i < H; i++) { for (int j = i + 1; j <= H; j++) { int t = h[j] - h[i]; if (setH.count(t)) setH[t]++; else setH[t] = 1; } } for (int i = 0; i < W; i++) { for (int j = i + 1; j <= W; j++) { int t = w[j] - w[i]; if (setW.count(t)) setW[t]++; else setW[t] = 1; } } int cnt = 0; for (auto i : setH) { if (setW.count(i.first)) cnt += setW[i.first] * i.second; } cout << cnt << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> using namespace std; int main() { int H, W; while (cin >> H >> W, H + W) { int h[1501] = {}; int w[1501] = {}; map<int, int> setH; map<int, int> setW; for (int i = 1; i <= H; i++) cin >> h[i]; for (int i = 1; i <= W; i++) cin >> w[i]; for (int i = 1; i <= H; i++) h[i] += h[i - 1]; for (int i = 1; i <= W; i++) w[i] += w[i - 1]; for (int i = 0; i < H; i++) { for (int j = i + 1; j <= H; j++) { int t = h[j] - h[i]; if (setH.count(t)) setH[t]++; else setH[t] = 1; } } for (int i = 0; i < W; i++) { for (int j = i + 1; j <= W; j++) { int t = w[j] - w[i]; if (setW.count(t)) setW[t]++; else setW[t] = 1; } } int cnt = 0; for (auto i : setH) { if (setW.count(i.first)) cnt += setW[i.first] * i.second; } cout << cnt << endl; } return 0; }
replace
9
11
9
11
0
p01140
C++
Runtime Error
#include <stdio.h> #include <string.h> int main(void) { int sw[150001], sum, n, m, i, j, k, count, w[1500], h[1500]; while (1) { scanf("%d%d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < n; i++) scanf("%d", &h[i]); for (i = 0; i < m; i++) scanf("%d", &w[i]); memset(sw, 0, sizeof(sw)); for (i = 0; i < m; i++) { for (j = i; j < m; j++) { sum = 0; for (k = i; k <= j; k++) sum += w[k]; sw[sum]++; } } count = 0; for (i = 0; i < n; i++) { for (j = i; j < n; j++) { sum = 0; for (k = i; k <= j; k++) sum += h[k]; if (sw[sum]) count += sw[sum]; } } printf("%d\n", count); } return 0; }
#include <stdio.h> #include <string.h> int main(void) { int sw[1500001], sum, n, m, i, j, k, count, w[1500], h[1500]; while (1) { scanf("%d%d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < n; i++) scanf("%d", &h[i]); for (i = 0; i < m; i++) scanf("%d", &w[i]); memset(sw, 0, sizeof(sw)); for (i = 0; i < m; i++) { for (j = i; j < m; j++) { sum = 0; for (k = i; k <= j; k++) sum += w[k]; sw[sum]++; } } count = 0; for (i = 0; i < n; i++) { for (j = i; j < n; j++) { sum = 0; for (k = i; k <= j; k++) sum += h[k]; if (sw[sum]) count += sw[sum]; } } printf("%d\n", count); } return 0; }
replace
4
5
4
5
0
p01140
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int h[1024 * 1500]; int w[1024 * 1500]; int getInt() { int c = getchar(); int ret = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) { ret += c - '0'; c = getchar(); } return ret; } int main() { int n, m; while (n = getInt(), m = getInt(), n + m) { int hh[n]; int ww[m]; int mm = 0; for (int i = 0; i < n; i++) hh[i] = getInt(); for (int i = 0; i < m; i++) ww[i] = getInt(); for (int i = 0; i < n; i++) { int sum = 0; for (int j = i; j < n; j++) { sum += hh[j]; h[sum]++; } mm = max(mm, sum); } for (int i = 0; i < m; i++) { int sum = 0; for (int j = i; j < m; j++) { sum += ww[j]; if (sum > mm) break; w[sum]++; } } long long ans = 0; for (int i = 0; i <= mm; i++) { if (w[i] | h[i]) { ans += (long long)w[i] * h[i]; w[i] = h[i] = 0; } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int h[1024 * 1500]; int w[1024 * 1500]; int getInt() { int c = getchar(); int ret = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) { ret *= 10; ret += c - '0'; c = getchar(); } return ret; } int main() { int n, m; while (n = getInt(), m = getInt(), n + m) { int hh[n]; int ww[m]; int mm = 0; for (int i = 0; i < n; i++) hh[i] = getInt(); for (int i = 0; i < m; i++) ww[i] = getInt(); for (int i = 0; i < n; i++) { int sum = 0; for (int j = i; j < n; j++) { sum += hh[j]; h[sum]++; } mm = max(mm, sum); } for (int i = 0; i < m; i++) { int sum = 0; for (int j = i; j < m; j++) { sum += ww[j]; if (sum > mm) break; w[sum]++; } } long long ans = 0; for (int i = 0; i <= mm; i++) { if (w[i] | h[i]) { ans += (long long)w[i] * h[i]; w[i] = h[i] = 0; } } cout << ans << endl; } return 0; }
insert
16
16
16
17
TLE
p01140
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; bool solve() { int n, m; cin >> n >> m; if (n == 0 && m == 0) return false; vector<int> h(n + 1), w(m + 1); for (int i = 1; i <= n; i++) { cin >> h[i]; h[i] += h[i - 1]; } for (int i = 1; i <= m; i++) { cin >> w[i]; w[i] += w[i - 1]; } vector<int> hei(2001); for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { hei[h[j] - h[i]]++; } } int cnt = 0; for (int i = 0; i <= m; i++) { for (int j = i + 1; j <= m; j++) { cnt += hei[w[j] - w[i]]; } } cout << cnt << endl; return true; } int main(void) { while (solve()) { } return 0; } //????????????
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; bool solve() { int n, m; cin >> n >> m; if (n == 0 && m == 0) return false; vector<int> h(n + 1), w(m + 1); for (int i = 1; i <= n; i++) { cin >> h[i]; h[i] += h[i - 1]; } for (int i = 1; i <= m; i++) { cin >> w[i]; w[i] += w[i - 1]; } vector<int> hei(1500001); for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { hei[h[j] - h[i]]++; } } int cnt = 0; for (int i = 0; i <= m; i++) { for (int j = i + 1; j <= m; j++) { cnt += hei[w[j] - w[i]]; } } cout << cnt << endl; return true; } int main(void) { while (solve()) { } return 0; } //????????????
replace
20
21
20
21
0
p01140
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define inf 1e9 #define ll long long #define ull unsigned long long #define M 1000000007 #define P pair<int, int> #define PLL pair<ll, ll> #define FOR(i, m, n) for (int i = m; i < n; i++) #define RFOR(i, m, n) for (int i = m; i >= n; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n, 0) const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; #define PI 3.14159265 void search(int n, int m) { int h[2000], w[2000]; rep(i, n) { cin >> h[i]; } rep(i, m) { cin >> w[i]; } map<int, int> a, b; rep(i, n) { int sum = 0; FOR(j, i, n) { sum += h[j]; a[sum]++; } } rep(i, m) { int sum = 0; FOR(j, i, m) { sum += w[j]; b[sum]++; } } int ans = 0; rep(i, 1e6) { ans += a[i] * b[i]; } cout << ans << endl; } int main() { int n, m; while (1) { cin >> n >> m; if (n == 0) break; search(n, m); } return 0; }
#include <bits/stdc++.h> using namespace std; #define inf 1e9 #define ll long long #define ull unsigned long long #define M 1000000007 #define P pair<int, int> #define PLL pair<ll, ll> #define FOR(i, m, n) for (int i = m; i < n; i++) #define RFOR(i, m, n) for (int i = m; i >= n; i--) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) RFOR(i, n, 0) const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; #define PI 3.14159265 void search(int n, int m) { int h[2000], w[2000]; rep(i, n) { cin >> h[i]; } rep(i, m) { cin >> w[i]; } map<int, int> a, b; rep(i, n) { int sum = 0; FOR(j, i, n) { sum += h[j]; a[sum]++; } } rep(i, m) { int sum = 0; FOR(j, i, m) { sum += w[j]; b[sum]++; } } int ans = 0; for (auto itr = a.begin(); itr != a.end(); itr++) { ans += itr->second * b[itr->first]; } cout << ans << endl; } int main() { int n, m; while (1) { cin >> n >> m; if (n == 0) break; search(n, m); } return 0; }
replace
41
42
41
44
TLE
p01140
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; int main() { int n, m; while (cin >> n >> m and (n or m)) { int h[1001], w[1001]; vector<int> hh(1500001, 0), ww(1500001, 0); rep(i, n) cin >> h[i]; rep(i, m) cin >> w[i]; rep(i, n) { int s = 0; for (int j = i; j < n; ++j) { s += h[j]; hh[s]++; } } rep(i, m) { int s = 0; for (int j = i; j < m; ++j) { s += w[j]; ww[s]++; } } int ans = 0; rep(i, 1500001) { ans += hh[i] * ww[i]; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = (0); (i) < (int)(n); ++(i)) using ll = long long; int main() { int n, m; while (cin >> n >> m and (n or m)) { int h[1501], w[1501]; vector<int> hh(1500001, 0), ww(1500001, 0); rep(i, n) cin >> h[i]; rep(i, m) cin >> w[i]; rep(i, n) { int s = 0; for (int j = i; j < n; ++j) { s += h[j]; hh[s]++; } } rep(i, m) { int s = 0; for (int j = i; j < m; ++j) { s += w[j]; ww[s]++; } } int ans = 0; rep(i, 1500001) { ans += hh[i] * ww[i]; } cout << ans << endl; } return 0; }
replace
10
11
10
11
0
p01140
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 1000000000; #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; while (cin >> N >> M && N) { vector<int> h(N + 1), w(M + 1); h[0] = 0, w[0] = 0; rep(i, N) cin >> h[i + 1]; rep(i, M) cin >> w[i + 1]; rep(i, N) h[i + 1] += h[i]; rep(i, M) w[i + 1] += w[i]; vector<int> hs(h.back() + 1, 0), ws(w.back() + 1, 0); rep(i, N) REP(j, i + 1, N + 1) hs[h[j] - h[i]]++; rep(i, M) REP(j, i + 1, M + 1) ws[w[j] - w[i]]++; int ans = 0; rep(i, max(h.back(), w.back()) + 1) ans += hs[i] * ws[i]; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int INF = 1000000000; #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; while (cin >> N >> M && N) { vector<int> h(N + 1), w(M + 1); h[0] = 0, w[0] = 0; rep(i, N) cin >> h[i + 1]; rep(i, M) cin >> w[i + 1]; rep(i, N) h[i + 1] += h[i]; rep(i, M) w[i + 1] += w[i]; vector<int> hs(h.back() + 1, 0), ws(w.back() + 1, 0); rep(i, N) REP(j, i + 1, N + 1) hs[h[j] - h[i]]++; rep(i, M) REP(j, i + 1, M + 1) ws[w[j] - w[i]]++; int ans = 0; rep(i, min(h.back(), w.back()) + 1) ans += hs[i] * ws[i]; cout << ans << endl; } return 0; }
replace
21
22
21
22
0
p01140
C++
Memory Limit Exceeded
#include <iostream> #include <map> #include <vector> using namespace std; int combi(int n) { return n * (n - 1) / 2; } int main() { int n, m; while (cin >> n >> m, n || m) { vector<int> x, y; x.push_back(0); y.push_back(0); for (int i = 0; i < n; i++) { int h; cin >> h; h += y[i]; y.push_back(h); } for (int i = 0; i < m; i++) { int w; cin >> w; w += x[i]; y.push_back(w); } // y=x+b → y-x=bとなる map<int, int> cnt; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < m + 1; j++) { int diff = y[i] - x[j]; cnt[diff]++; } } // 全探索 int ans = 0; for (int i = -x[m]; i < y[n] + 1; i++) { ans += combi(cnt[i]); } cout << ans << endl; } }
#include <iostream> #include <map> #include <vector> using namespace std; int combi(int n) { return n * (n - 1) / 2; } int main() { int n, m; while (cin >> n >> m, n || m) { vector<int> x, y; x.push_back(0); y.push_back(0); for (int i = 0; i < n; i++) { int h; cin >> h; h += y[i]; y.push_back(h); } for (int i = 0; i < m; i++) { int w; cin >> w; w += x[i]; x.push_back(w); } // y=x+b → y-x=bとなる map<int, int> cnt; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < m + 1; j++) { int diff = y[i] - x[j]; cnt[diff]++; } } // 全探索 int ans = 0; for (int i = -x[m]; i < y[n] + 1; i++) { ans += combi(cnt[i]); } cout << ans << endl; } }
replace
26
27
26
27
MLE
p01140
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fi first #define se second #define fcout(n) cout << fixed << setprecision((n)) #define cinl(str) getline(cin, (str)) using namespace std; bool value(int y, int x, int R, int C) { return 0 <= y && y < R && 0 <= x && x < C; } typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<vi> vvi; double pie = acos(-1); int INF = 1000000007; int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0, 1, 0}; long long hsum2[1500005], wsum2[1500005]; int main() { int n, m; long long ans = 0; int h[1505], w[1505]; long long hsum1[1505], wsum1[1505]; while (true) { cin >> n >> m; if (n + m == 0) return 0; else { for (int i = 0; i < 1505; i++) { hsum1[i] = 0; wsum1[i] = 0; } fill(hsum2, hsum2 + 1500005, 0); fill(wsum2, wsum2 + 1500005, 0); for (int i = 0; i < n; i++) { cin >> h[i]; if (i == 0) { hsum1[i] += h[i]; } else { hsum1[i] = hsum1[i - 1] + h[i]; } } for (int i = 0; i < m; i++) { cin >> w[i]; if (i == 0) { wsum1[i] += w[i]; } else { wsum1[i] += wsum1[i - 1] + w[i]; } } for (int i = 0; i < n; i++) { hsum2[hsum1[i]]++; for (int j = i + 1; j < n; j++) { hsum2[hsum1[j] - hsum1[i]]++; } } for (int i = 0; i < m; i++) { wsum2[wsum1[i]]++; for (int j = 0; j < m; j++) { wsum2[wsum1[j] - wsum1[i]]++; } } } for (int i = 0; i < 1500005; i++) { ans += hsum2[i] * wsum2[i]; } cout << ans << endl; ans = 0; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fi first #define se second #define fcout(n) cout << fixed << setprecision((n)) #define cinl(str) getline(cin, (str)) using namespace std; bool value(int y, int x, int R, int C) { return 0 <= y && y < R && 0 <= x && x < C; } typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<vi> vvi; double pie = acos(-1); int INF = 1000000007; int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0, 1, 0}; long long hsum2[1500005], wsum2[1500005]; int main() { int n, m; long long ans = 0; int h[1505], w[1505]; long long hsum1[1505], wsum1[1505]; while (true) { cin >> n >> m; if (n + m == 0) return 0; else { for (int i = 0; i < 1505; i++) { hsum1[i] = 0; wsum1[i] = 0; } fill(hsum2, hsum2 + 1500005, 0); fill(wsum2, wsum2 + 1500005, 0); for (int i = 0; i < n; i++) { cin >> h[i]; if (i == 0) { hsum1[i] += h[i]; } else { hsum1[i] = hsum1[i - 1] + h[i]; } } for (int i = 0; i < m; i++) { cin >> w[i]; if (i == 0) { wsum1[i] += w[i]; } else { wsum1[i] += wsum1[i - 1] + w[i]; } } for (int i = 0; i < n; i++) { hsum2[hsum1[i]]++; for (int j = i + 1; j < n; j++) { hsum2[hsum1[j] - hsum1[i]]++; } } for (int i = 0; i < m; i++) { wsum2[wsum1[i]]++; for (int j = i + 1; j < m; j++) { wsum2[wsum1[j] - wsum1[i]]++; } } } for (int i = 0; i < 1500005; i++) { ans += hsum2[i] * wsum2[i]; } cout << ans << endl; ans = 0; } }
replace
75
76
75
76
0
p01140
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int s1[2000], s2[2000]; int main() { int n, m; while (scanf("%d%d", &n, &m), n) { rep(i, n) scanf("%d", &s1[i + 1]); rep(i, m) scanf("%d", &s2[i + 1]); for (int i = 1; i <= n; i++) s1[i] += s1[i - 1]; for (int i = 1; i <= m; i++) s2[i] += s2[i - 1]; int cnt = 0; rep(i, n + 1) rep(j, m + 1) rep(k, i) rep(l, j) { if (s1[i] - s1[k] == s2[j] - s2[l]) cnt++; } printf("%d\n", cnt); } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int s1[2000], s2[2000]; int main() { int n, m; while (scanf("%d%d", &n, &m), n) { rep(i, n) scanf("%d", &s1[i + 1]); rep(i, m) scanf("%d", &s2[i + 1]); for (int i = 1; i <= n; i++) s1[i] += s1[i - 1]; for (int i = 1; i <= m; i++) s2[i] += s2[i - 1]; int cnt = 0; map<int, int> mp1, mp2; rep(i, n + 1) rep(j, i) mp1[s1[i] - s1[j]]++; rep(i, m + 1) rep(j, i) mp2[s2[i] - s2[j]]++; for (auto p : mp1) { cnt += p.second * mp2[p.first]; } printf("%d\n", cnt); } }
replace
15
18
15
20
TLE
p01140
C++
Memory Limit Exceeded
#include <map> #include <stdio.h> #include <vector> auto solve(int N, int M) -> int { using namespace std; vector<int> h(N); vector<int> w(M); for (int i = 0; i < N; i++) { int x; scanf("%d", &x); h[i] = x; } for (int i = 0; i < M; i++) { int x; scanf("%d", &x); w[i] = x; } map<int, int> &eh = *(new map<int, int>()); map<int, int> &ew = *(new map<int, int>()); for (int i = 0; i < N; i++) { int sum = 0; for (int j = i; j < N; j++) { sum += h[j]; if (eh.find(sum) != ew.end()) eh[sum]++; else eh[sum] = 1; } } for (int i = 0; i < M; i++) { int sum = 0; for (int j = i; j < M; j++) { sum += w[j]; if (ew.find(sum) != ew.end()) ew[sum]++; else ew[sum] = 1; } } int ans = 0; for (auto p : eh) { if (ew.find(p.first) != ew.end()) ans += p.second * ew[p.first]; } return ans; } auto main() -> int { int n, m; while (1) { scanf("%d%d", &n, &m); if (!(n | m)) break; printf("%d\n", solve(n, m)); } }
#include <map> #include <stdio.h> #include <vector> auto solve(int N, int M) -> int { using namespace std; vector<int> h(N); vector<int> w(M); for (int i = 0; i < N; i++) { int x; scanf("%d", &x); h[i] = x; } for (int i = 0; i < M; i++) { int x; scanf("%d", &x); w[i] = x; } map<int, int> eh; map<int, int> ew; for (int i = 0; i < N; i++) { int sum = 0; for (int j = i; j < N; j++) { sum += h[j]; if (eh.find(sum) != ew.end()) eh[sum]++; else eh[sum] = 1; } } for (int i = 0; i < M; i++) { int sum = 0; for (int j = i; j < M; j++) { sum += w[j]; if (ew.find(sum) != ew.end()) ew[sum]++; else ew[sum] = 1; } } int ans = 0; for (auto p : eh) { if (ew.find(p.first) != ew.end()) ans += p.second * ew[p.first]; } return ans; } auto main() -> int { int n, m; while (1) { scanf("%d%d", &n, &m); if (!(n | m)) break; printf("%d\n", solve(n, m)); } }
replace
20
22
20
22
MLE
p01140
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long i64; typedef long double ld; typedef pair<i64, i64> P; #define rep(i, s, e) for (int i = (s); i <= (e); i++) int n; int m; int hmp[1500 * 1000 + 1]; int wmp[1500 * 1000 + 1]; int main() { while (cin >> n >> m, n) { fill(hmp, hmp + 1 + 1500 * 1000, 0); fill(wmp, wmp + 1 + 1500 * 1000, 0); vector<int> h(n + 1, 0), w(n + 1, 0); for (int i = 1; i <= n; i++) { cin >> h[i]; h[i] += h[i - 1]; } for (int i = 1; i <= m; i++) { cin >> w[i]; w[i] += w[i - 1]; } for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int len = h[j] - h[i]; hmp[len]++; } } for (int i = 0; i <= m; i++) { for (int j = i + 1; j <= m; j++) { int len = w[j] - w[i]; wmp[len]++; } } i64 result = 0; for (int i = 1; i <= 1500 * 1000; i++) { result += hmp[i] * wmp[i]; } cout << result << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long i64; typedef long double ld; typedef pair<i64, i64> P; #define rep(i, s, e) for (int i = (s); i <= (e); i++) int n; int m; int hmp[1500 * 1000 + 1]; int wmp[1500 * 1000 + 1]; int main() { while (cin >> n >> m, n) { fill(hmp, hmp + 1 + 1500 * 1000, 0); fill(wmp, wmp + 1 + 1500 * 1000, 0); vector<int> h(n + 1, 0), w(m + 1, 0); for (int i = 1; i <= n; i++) { cin >> h[i]; h[i] += h[i - 1]; } for (int i = 1; i <= m; i++) { cin >> w[i]; w[i] += w[i - 1]; } for (int i = 0; i <= n; i++) { for (int j = i + 1; j <= n; j++) { int len = h[j] - h[i]; hmp[len]++; } } for (int i = 0; i <= m; i++) { for (int j = i + 1; j <= m; j++) { int len = w[j] - w[i]; wmp[len]++; } } i64 result = 0; for (int i = 1; i <= 1500 * 1000; i++) { result += hmp[i] * wmp[i]; } cout << result << endl; } }
replace
25
26
25
26
0
p01140
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define out(S) cout << (S) << endl; #define ShowAll(collection) \ for (auto i : collection) { \ out(i); \ } #define beginend(v) v.begin(), v.end() using pii = pair<int, int>; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vvi = vector<vi>; using vvc = vector<vector<char>>; using ti3 = tuple<int, int, int>; template <typename T> void removeAt(vector<T> &v, int index) { v.erase(v.begin() + index); } int solve(int n, int m) { vi w(m + 1, 0), h(n + 1, 0); rep(i, n) cin >> h[i + 1]; rep(i, m) cin >> w[i + 1]; rep(i, n) h[i + 1] += h[i]; rep(i, m) w[i + 1] += w[i]; map<int, int> hm, wm; rep(i, n + 1) for (int j = i + 1; j <= n; ++j) hm[h[j] - h[i]]++; rep(i, m + 1) for (int j = i + 1; j <= m; ++j) wm[w[j] - w[i]]++; int ans = 0; for (auto hh : hm) { int hk, hv; tie(hk, hv) = hh; for (auto ww : wm) { int wk, wv; tie(wk, wv) = ww; if (hk == wk) ans += wv * hv; } } return ans; } int main() { int N, M; while (cin >> N >> M, N | M) { out(solve(N, M)); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define out(S) cout << (S) << endl; #define ShowAll(collection) \ for (auto i : collection) { \ out(i); \ } #define beginend(v) v.begin(), v.end() using pii = pair<int, int>; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vvi = vector<vi>; using vvc = vector<vector<char>>; using ti3 = tuple<int, int, int>; template <typename T> void removeAt(vector<T> &v, int index) { v.erase(v.begin() + index); } int solve(int n, int m) { vi w(m + 1, 0), h(n + 1, 0); rep(i, n) cin >> h[i + 1]; rep(i, m) cin >> w[i + 1]; rep(i, n) h[i + 1] += h[i]; rep(i, m) w[i + 1] += w[i]; map<int, int> hm, wm; rep(i, n + 1) for (int j = i + 1; j <= n; ++j) hm[h[j] - h[i]]++; rep(i, m + 1) for (int j = i + 1; j <= m; ++j) wm[w[j] - w[i]]++; int ans = 0; rep(i, max(h[n], w[n]) + 1) ans += (hm[i] * wm[i]); return ans; } int main() { int N, M; while (cin >> N >> M, N | M) { out(solve(N, M)); } }
replace
36
46
36
37
TLE
p01140
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) const int N = 100; int h, w; int A[N]; int B[N]; void init() {} bool input() { cin >> h >> w; if (h == 0) return 0; rep(i, h) cin >> A[i]; rep(i, w) cin >> B[i]; return true; } int solve() { int C[N] = {0}; int D[N] = {0}; rep(i, h) { C[i + 1] = C[i] + A[i]; } rep(i, w) { D[i + 1] = D[i] + B[i]; } map<int, int> sum; rep(i, h) { reps(j, i, h) { int s = C[j + 1] - C[i]; sum[s]++; // printf("s %d %d\n",s,sum[s]); } } int ans = 0; rep(i, w) { reps(j, i, w) { int s = D[j + 1] - D[i]; ans += sum[s]; // printf("g %d %d\n",s,sum[s]); } } return ans; } int main() { while (init(), input()) printf("%d\n", solve()); }
#include <bits/stdc++.h> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) const int N = 1600; int h, w; int A[N]; int B[N]; void init() {} bool input() { cin >> h >> w; if (h == 0) return 0; rep(i, h) cin >> A[i]; rep(i, w) cin >> B[i]; return true; } int solve() { int C[N] = {0}; int D[N] = {0}; rep(i, h) { C[i + 1] = C[i] + A[i]; } rep(i, w) { D[i + 1] = D[i] + B[i]; } map<int, int> sum; rep(i, h) { reps(j, i, h) { int s = C[j + 1] - C[i]; sum[s]++; // printf("s %d %d\n",s,sum[s]); } } int ans = 0; rep(i, w) { reps(j, i, w) { int s = D[j + 1] - D[i]; ans += sum[s]; // printf("g %d %d\n",s,sum[s]); } } return ans; } int main() { while (init(), input()) printf("%d\n", solve()); }
replace
7
8
7
8
0
p01140
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; 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 + 0; //{{{ templates #define TT_ template <typename T> inline #define TTF_ template <typename T, typename F> inline TT_ T sq(T x) { return x * x; } TT_ T In() { T x; cin >> x; return x; } TT_ void Out(T &x) { cout << x; } TT_ void sort(T &v) { sort(begin(v), end(v)); } TT_ void revs(T &v) { reverse(begin(v), end(v)); } TT_ void uniq(T &v) { sort(v); v.erase(unique(begin(v), end(v)), end(v)); } TT_ int ubnd(T &v, typename T::value_type x) { return upper_bound(begin(v), end(v), x) - begin(v); } TT_ int lbnd(T &v, typename T::value_type x) { return lower_bound(begin(v), end(v), x) - begin(v); } TTF_ void inpt(T &v, int n, F f) { for (v.reserve(n); n--; v.emplace_back(f())) ; } TTF_ void show(T &v, F f, string d = " ", string e = "\n") { int i = 0; for (auto &x : v) i++ && (cout << d), f(x); cout << e; } TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); } TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); } inline void fast_io() { ios_base::sync_with_stdio(0); cin.tie(0); } inline int in() { int x; scanf("%d", &x); return x; } inline ll pow_mod(ll a, ll k, ll m) { ll r = 1; for (; k > 0; a = a * a % m, k >>= 1) if (k & 1) r = r * a % m; return r; } inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); } //}}} priority_queue queue deque front stringstream max_element min_element //insert count make_tuple short B[3000300]; int H[2048], W[2048]; int main() { int N, M; short K = 0; while (N = in(), M = in()) { K++; for (int i = 1; i <= N; i++) { H[i] = H[i - 1] + in(); B[H[i]] = K; } for (int i = 1; i <= M; i++) { W[i] = W[i - 1] + in(); } int ans = 0; for (int y = 0, y_ = N; y < y_; y++) { const int hy = H[y]; for (int x = 0, x_ = M; x < x_; x++) { const int wx = W[x]; for (int z = x + 1, z_ = M; z <= z_; z++) { int d = W[z] - wx; ans += B[hy + d] == K; } } } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef tuple<int, int> duo; 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 + 0; //{{{ templates #define TT_ template <typename T> inline #define TTF_ template <typename T, typename F> inline TT_ T sq(T x) { return x * x; } TT_ T In() { T x; cin >> x; return x; } TT_ void Out(T &x) { cout << x; } TT_ void sort(T &v) { sort(begin(v), end(v)); } TT_ void revs(T &v) { reverse(begin(v), end(v)); } TT_ void uniq(T &v) { sort(v); v.erase(unique(begin(v), end(v)), end(v)); } TT_ int ubnd(T &v, typename T::value_type x) { return upper_bound(begin(v), end(v), x) - begin(v); } TT_ int lbnd(T &v, typename T::value_type x) { return lower_bound(begin(v), end(v), x) - begin(v); } TTF_ void inpt(T &v, int n, F f) { for (v.reserve(n); n--; v.emplace_back(f())) ; } TTF_ void show(T &v, F f, string d = " ", string e = "\n") { int i = 0; for (auto &x : v) i++ && (cout << d), f(x); cout << e; } TT_ typename T::iterator minel(T &v) { return min_element(begin(v), end(v)); } TT_ typename T::iterator maxel(T &v) { return max_element(begin(v), end(v)); } inline void fast_io() { ios_base::sync_with_stdio(0); cin.tie(0); } inline int in() { int x; scanf("%d", &x); return x; } inline ll pow_mod(ll a, ll k, ll m) { ll r = 1; for (; k > 0; a = a * a % m, k >>= 1) if (k & 1) r = r * a % m; return r; } inline ll mod_inv(ll a, ll p) { return pow_mod(a, p - 2, p); } //}}} priority_queue queue deque front stringstream max_element min_element //insert count make_tuple short B[3000300]; int H[2048], W[2048]; int main() { int N, M; short K = 0; while (N = in(), M = in()) { K++; for (int i = 1; i <= N; i++) { H[i] = H[i - 1] + in(); B[H[i]] = K; } for (int i = 1; i <= M; i++) { W[i] = W[i - 1] + in(); } int ans = 0; for (int y = 0; y < N; y++) { for (int x = 0; x < M; x++) { for (int z = x + 1; z <= M; z++) { int d = W[z] - W[x]; if (H[N] - H[y] < d) break; ans += B[H[y] + d] == K; } } } printf("%d\n", ans); } return 0; }
replace
80
87
80
87
TLE
p01140
C++
Time Limit Exceeded
#include <iostream> #include <map> #include <set> using namespace std; int main() { while (1) { int N, M; cin >> N >> M; if (N == 0 && M == 0) break; int H[N], W[M]; for (int i = 0; i < N; i++) { cin >> H[i]; } for (int i = 0; i < M; i++) { cin >> W[i]; } set<int> v1, v2; map<int, int> m1, m2; for (int i = 0; i < N; i++) { int bfr = 0; for (int j = i; j < N; j++) { int temp; temp = bfr + H[j]; bfr = temp; v1.insert(temp); m1[temp]++; } } for (int i = 0; i < M; i++) { int bfr = 0; for (int j = i; j < M; j++) { int temp; temp = bfr + W[j]; bfr = temp; v2.insert(temp); m2[temp]++; } } int cnt = 0; set<int>::iterator it1 = v1.begin(); while (it1 != v1.end()) { set<int>::iterator it2 = v2.begin(); while (it2 != v2.end()) { if (*it1 == *it2) cnt += m1[*it1] * m2[*it2]; it2++; } it1++; } cout << cnt << endl; } return 0; }
#include <iostream> #include <map> #include <set> using namespace std; int main() { while (1) { int N, M; cin >> N >> M; if (N == 0 && M == 0) break; int H[N], W[M]; for (int i = 0; i < N; i++) { cin >> H[i]; } for (int i = 0; i < M; i++) { cin >> W[i]; } set<int> v1, v2; map<int, int> m1, m2; for (int i = 0; i < N; i++) { int bfr = 0; for (int j = i; j < N; j++) { int temp; temp = bfr + H[j]; bfr = temp; v1.insert(temp); m1[temp]++; } } for (int i = 0; i < M; i++) { int bfr = 0; for (int j = i; j < M; j++) { int temp; temp = bfr + W[j]; bfr = temp; v2.insert(temp); m2[temp]++; } } int cnt = 0; set<int>::iterator it1 = v1.begin(); while (it1 != v1.end()) { set<int>::iterator it2; it2 = v2.find(*it1); if (it2 != v2.end()) cnt += m1[*it1] * m2[*it2]; it1++; } cout << cnt << endl; } return 0; }
replace
46
52
46
50
TLE
p01142
C++
Memory Limit Exceeded
#include <algorithm> #include <cstring> #include <iostream> #include <queue> #include <tuple> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define REPS(i, n) for (int i = 1; i <= (int)n; i++) typedef vector<int> vi; typedef pair<int, int> pii; int d[10] = {0, -1, 0, 1, 0, -1, 0, 1, 0, -1}; int w, h, s1, s2, t1, t2; char ss[100][100]; int encode(int x, int y, int d) { return x * 16 * 4 + y * 4 + d; } int dp[64 * 16 * 4][64 * 16 * 4]; int dp2[64 * 16 * 4]; int main() { while (cin >> w >> h, w) { REP(i, h) cin >> ss[i]; vector<vi> g(64 * 16 * 4, vi(2, -1)); vector<vector<vi>> invg(64 * 16 * 4, vector<vi>(2)); REP(i, h) REP(j, w) if (ss[i][j] != '#') { REP(k, 4) if (ss[i + d[k]][j + d[k + 1]] == '.') { int dx = j, dy = i; while (ss[dy + d[k]][dx + d[k + 1]] != '#') { dy += d[k]; dx += d[k + 1]; } if (ss[i][j] == 'K') { s1 = encode(dx, dy, k); s2 = encode(j, i, k); } if (ss[i][j] == 'M') { t1 = encode(j, i, k ^ 2); t2 = encode(dx, dy, k); } } REP(k, 4) REP(l, 2) { int dx = j, dy = i; int dir = (k + 1 + l * 2) % 4; while (ss[dy + d[dir]][dx + d[dir + 1]] != '#') { dy += d[dir]; dx += d[dir + 1]; } int u = encode(j, i, k); int v = encode(dx, dy, dir); invg[v][!l].push_back(u); g[u][l] = v; } } memset(dp, 0, sizeof(dp)); memset(dp2, 0, sizeof(dp2)); queue<pii> q; REPS(i, 3) q.emplace(s1, s2 ^ i); int ans = 0; while (!q.empty()) { int u1, u2; tie(u1, u2) = q.front(); q.pop(); if ((u1 | 3) == (t1 | 3)) ans = 1; if ((u1 | 3) == (t1 | 3) && u2 == t2) { ans = 2; break; } REP(l, 2) { int v1 = g[u1][l]; if (u2 == -1 || invg[u2][l].empty()) { if (!dp2[v1]) { dp2[v1] = 1; q.emplace(v1, -1); } } else for (int v2 : invg[u2][l]) { if (!dp[v1][v2]) { dp[v1][v2] = 1; q.emplace(v1, v2); } } } } if (ans == 0) puts("He cannot bring tea to his master."); if (ans == 1) puts("He cannot return to the kitchen."); if (ans == 2) puts("He can accomplish his mission."); } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <queue> #include <tuple> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; i++) #define REPS(i, n) for (int i = 1; i <= (int)n; i++) typedef vector<int> vi; typedef pair<int, int> pii; int d[10] = {0, -1, 0, 1, 0, -1, 0, 1, 0, -1}; int w, h, s1, s2, t1, t2; char ss[100][100]; int encode(int x, int y, int d) { return x * 16 * 4 + y * 4 + d; } unsigned char dp[64 * 16 * 4][64 * 16 * 4]; unsigned char dp2[64 * 16 * 4]; int main() { while (cin >> w >> h, w) { REP(i, h) cin >> ss[i]; vector<vi> g(64 * 16 * 4, vi(2, -1)); vector<vector<vi>> invg(64 * 16 * 4, vector<vi>(2)); REP(i, h) REP(j, w) if (ss[i][j] != '#') { REP(k, 4) if (ss[i + d[k]][j + d[k + 1]] == '.') { int dx = j, dy = i; while (ss[dy + d[k]][dx + d[k + 1]] != '#') { dy += d[k]; dx += d[k + 1]; } if (ss[i][j] == 'K') { s1 = encode(dx, dy, k); s2 = encode(j, i, k); } if (ss[i][j] == 'M') { t1 = encode(j, i, k ^ 2); t2 = encode(dx, dy, k); } } REP(k, 4) REP(l, 2) { int dx = j, dy = i; int dir = (k + 1 + l * 2) % 4; while (ss[dy + d[dir]][dx + d[dir + 1]] != '#') { dy += d[dir]; dx += d[dir + 1]; } int u = encode(j, i, k); int v = encode(dx, dy, dir); invg[v][!l].push_back(u); g[u][l] = v; } } memset(dp, 0, sizeof(dp)); memset(dp2, 0, sizeof(dp2)); queue<pii> q; REPS(i, 3) q.emplace(s1, s2 ^ i); int ans = 0; while (!q.empty()) { int u1, u2; tie(u1, u2) = q.front(); q.pop(); if ((u1 | 3) == (t1 | 3)) ans = 1; if ((u1 | 3) == (t1 | 3) && u2 == t2) { ans = 2; break; } REP(l, 2) { int v1 = g[u1][l]; if (u2 == -1 || invg[u2][l].empty()) { if (!dp2[v1]) { dp2[v1] = 1; q.emplace(v1, -1); } } else for (int v2 : invg[u2][l]) { if (!dp[v1][v2]) { dp[v1][v2] = 1; q.emplace(v1, v2); } } } } if (ans == 0) puts("He cannot bring tea to his master."); if (ans == 1) puts("He cannot return to the kitchen."); if (ans == 2) puts("He can accomplish his mission."); } return 0; }
replace
21
23
21
23
MLE
p01143
C++
Runtime Error
#include <bits/stdc++.h> typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define DECIM8 fixed << setprecision(8) #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); // clear memory #define CLR(a) memset((a), 0, sizeof(a)) using namespace std; int main(void) { for (;;) { int n, m, p, sum = 0, div; cin >> n >> m >> p; if (!n && !m && !p) return 0; REP(i, n) { int tmp; cin >> tmp; sum += tmp; if (i + 1 == m) div = tmp; } cout << sum * (100 - p) / div << endl; } }
#include <bits/stdc++.h> typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define DECIM8 fixed << setprecision(8) #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); // clear memory #define CLR(a) memset((a), 0, sizeof(a)) using namespace std; int main(void) { for (;;) { int n, m, p, sum = 0, div; cin >> n >> m >> p; if (!n && !m && !p) return 0; REP(i, n) { int tmp; cin >> tmp; sum += tmp; if (i + 1 == m) div = tmp; } if (div == 0) sum = 0; else sum = sum * (100 - p) / div; cout << sum << endl; } }
replace
41
42
41
46
-8
p01143
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lp(i, n) for (int i = 0; i < n; i++) int main() { while (1) { int n, m, p; cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; int count = 0, ans, a; lp(i, n) { cin >> a; count += a; if (i == m - 1) ans = a; } count *= 100; count *= (100 - p); cout << count / a / 100 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define lp(i, n) for (int i = 0; i < n; i++) int main() { while (1) { int n, m, p; cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; int count = 0, ans, a; lp(i, n) { cin >> a; count += a; if (i == m - 1) ans = a; } count *= 100; count *= (100 - p); if (ans != 0) cout << count / ans / 100 << endl; else cout << "0" << endl; } return 0; }
replace
19
20
19
23
-8
p01143
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <utility> #include <vector> #define ll long long int #define ld long double #define INF 1000000000 #define EPS 0.0000000001 #define rep(i, n) for (i = 0; i < n; i++) using namespace std; typedef pair<int, int> pii; int main() { int n, m, p, x; int num[105] = {}; int i; while (1) { cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; ll sum = 0LL; rep(i, n) { cin >> x; num[x]++; sum += x; } sum = sum * (100 - p); if (num[m]) cout << sum / num[m] << endl; else cout << "0" << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <utility> #include <vector> #define ll long long int #define ld long double #define INF 1000000000 #define EPS 0.0000000001 #define rep(i, n) for (i = 0; i < n; i++) using namespace std; typedef pair<int, int> pii; int main() { int n, m, p, x; int num[105] = {}; int i; while (1) { cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; ll sum = 0LL; rep(i, n) { cin >> x; num[i + 1] = x; sum += x; } sum = sum * (100 - p); if (num[m]) cout << sum / num[m] << endl; else cout << "0" << endl; } }
replace
31
32
31
32
0
p01143
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m, p; int num[101]; while (cin >> n >> m >> p, n | m | p) { int total = 0; for (int i = 1; i <= n; i++) { cin >> num[i]; total += num[i] * (100 - p); } if (!num[n]) { cout << 0 << endl; continue; } cout << (total / num[m]) << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, p; int num[101]; while (cin >> n >> m >> p, n | m | p) { int total = 0; for (int i = 1; i <= n; i++) { cin >> num[i]; total += num[i] * (100 - p); } if (!num[m]) { cout << 0 << endl; continue; } cout << (total / num[m]) << endl; } return 0; }
replace
13
14
13
14
0
p01143
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m, p, x[1000]; while (1) { cin >> n >> m >> p; int sum = 0; if (n == 0 && m == 0 && p == 0) break; p = 100 - p; for (int i = 0; i < n; i++) { cin >> x[i]; sum += x[i]; } p *= sum; p = p / x[m - 1]; cout << p << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, p, x[1000]; while (1) { cin >> n >> m >> p; int sum = 0; if (n == 0 && m == 0 && p == 0) break; p = 100 - p; for (int i = 0; i < n; i++) { cin >> x[i]; sum += x[i]; } p *= sum; if (x[m - 1] == 0) p = 0; else p = p / x[m - 1]; cout << p << endl; } return 0; }
replace
20
21
20
25
-8
p01143
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N, M, P; while (1) { cin >> N >> M >> P; double A[N]; double sum = 0; double num = 0; double money; for (int i = 1; i <= N; i++) { cin >> A[i]; sum += A[i] * 100; if (i == M) { num = A[i]; } } money = (sum * (100 - P) / 100) / num; // cout << M << " " << num << " " << sum << " " << money << " " << P << // endl; if (num == 0) { cout << 0 << endl; } else if (num != 0) { cout << (int)money << endl; } } }
#include <iostream> using namespace std; int main() { int N, M, P; while (1) { cin >> N >> M >> P; if ((N == 0) && (M == 0) && (P == 0)) { break; } double A[N]; double sum = 0; double num = 0; double money; for (int i = 1; i <= N; i++) { cin >> A[i]; sum += A[i] * 100; if (i == M) { num = A[i]; } } money = (sum * (100 - P) / 100) / num; // cout << M << " " << num << " " << sum << " " << money << " " << P << // endl; if (num == 0) { cout << 0 << endl; } else if (num != 0) { cout << (int)money << endl; } } }
insert
8
8
8
11
TLE
p01144
C++
Runtime Error
#include <algorithm> #include <iostream> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; bool cmp(pair<int, int> &x, pair<int, int> &y) { return x.second > y.second; } int main(void) { int n, m; while (cin >> n >> m, n > 0) { int j = 0, ans = 0; vector<pair<int, int>> dp(n); rep(i, n) { int d, p; cin >> d >> p; dp[i] = make_pair(d, p); } sort(dp.begin(), dp.end(), cmp); while (m > 0) { if (m > dp[j].first) { m -= dp[j].first; dp[j].first = 0; j++; } else { dp[j].first -= m; m = 0; } } rep(i, n) { ans += dp[i].first * dp[i].second; } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; bool cmp(pair<int, int> &x, pair<int, int> &y) { return x.second > y.second; } int main(void) { int n, m; while (cin >> n >> m, n > 0) { int j = 0, ans = 0; vector<pair<int, int>> dp(n); rep(i, n) { int d, p; cin >> d >> p; dp[i] = make_pair(d, p); } sort(dp.begin(), dp.end(), cmp); while (m > 0) { if (m > dp[j].first) { m -= dp[j].first; dp[j].first = 0; j++; if (j == n) break; } else { dp[j].first -= m; m = 0; } } rep(i, n) { ans += dp[i].first * dp[i].second; } cout << ans << endl; } return 0; }
insert
27
27
27
29
0
p01144
C++
Runtime Error
/* Princess's Marriage http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp 20:10 */ #include <algorithm> #include <iostream> #include <vector> using std::cin; using std::cout; using std::min; using std::pair; using std::sort; using std::vector; #define INF 999999999; long long int N, M; vector<pair<int, int>> DaP; //(Dn, Pn) long long int ans; int main(void) { cin.tie(0); std::ios::sync_with_stdio(false); do { cin >> N >> M; if (N == 0 && M == 0) break; for (int i = 0; i < N; i++) { pair<int, int> inn; cin >> inn.first >> inn.second; ans += inn.first * inn.second; DaP.push_back(inn); } sort(DaP.begin(), DaP.end(), [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; }); int i = 0; while (M > 0) { long long int minus = min(M, (long long int)DaP[i].first); ans -= DaP[i].second * minus; M -= minus; i++; } cout << ans << "\n"; ans = 0; DaP.clear(); } while (true); return 0; }
/* Princess's Marriage http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2019&lang=jp 20:10 */ #include <algorithm> #include <iostream> #include <vector> using std::cin; using std::cout; using std::min; using std::pair; using std::sort; using std::vector; #define INF 999999999; long long int N, M; vector<pair<int, int>> DaP; //(Dn, Pn) long long int ans; int main(void) { cin.tie(0); std::ios::sync_with_stdio(false); do { cin >> N >> M; if (N == 0 && M == 0) break; for (int i = 0; i < N; i++) { pair<int, int> inn; cin >> inn.first >> inn.second; ans += inn.first * inn.second; DaP.push_back(inn); } sort(DaP.begin(), DaP.end(), [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; }); int i = 0; while (M > 0) { long long int minus = min(M, (long long int)DaP[i].first); ans -= DaP[i].second * minus; M -= minus; i++; if (i == DaP.size()) break; } cout << ans << "\n"; ans = 0; DaP.clear(); } while (true); return 0; }
insert
45
45
45
47
0
p01144
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> #define INF 2147483647 #define llINF 9223372036854775807 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long using namespace std; int main() { ll n, m; while (cin >> n >> m, n + m) { ll ans = 0; vector<pair<int, int>> pii(n); for (int i = 0; i < n; i++) { cin >> pii[i].S >> pii[i].F; ans += pii[i].S * pii[i].F; } int po = n - 1; sort(pii.begin(), pii.end()); while (m > 0) { if (m - pii[po].S >= 0) { ans -= pii[po].F * pii[po].S; m -= pii[po].S; } else { ans -= pii[po].F * m; break; } po--; } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> #define INF 2147483647 #define llINF 9223372036854775807 #define pb push_back #define mp make_pair #define F first #define S second #define ll long long using namespace std; int main() { ll n, m; while (cin >> n >> m, n + m) { ll ans = 0; vector<pair<int, int>> pii(n); for (int i = 0; i < n; i++) { cin >> pii[i].S >> pii[i].F; ans += pii[i].S * pii[i].F; } int po = n - 1; sort(pii.begin(), pii.end()); while (po >= 0) { if (m - pii[po].S >= 0) { ans -= pii[po].F * pii[po].S; m -= pii[po].S; } else { ans -= pii[po].F * m; break; } po--; } cout << ans << endl; } return 0; }
replace
32
33
32
33
0
p01144
C++
Time Limit Exceeded
#include <iostream> #include <set> using namespace std; int main() { while (true) { int n, m; int d, p; multiset<pair<int, int>, greater<pair<int, int>>> s; multiset<pair<int, int>, greater<pair<int, int>>>::iterator it; int e = 0; cin >> n >> m; if (!(n || m)) break; for (int i = 0; i < n; ++i) { cin >> d >> p; s.insert(make_pair(p, d)); } it = s.begin(); while (it != s.end() || m > 0) { m -= (*it).second; ++it; } if (m < 0) { --it; e += (*it).first * (-m); ++it; } while (it != s.end()) { e += (*it).second * (*it).first; ++it; } cout << e << endl; } }
#include <iostream> #include <set> using namespace std; int main() { while (true) { int n, m; int d, p; multiset<pair<int, int>, greater<pair<int, int>>> s; multiset<pair<int, int>, greater<pair<int, int>>>::iterator it; int e = 0; cin >> n >> m; if (!(n || m)) break; for (int i = 0; i < n; ++i) { cin >> d >> p; s.insert(make_pair(p, d)); } it = s.begin(); while (it != s.end() && m > 0) { m -= (*it).second; ++it; } if (m < 0) { --it; e += (*it).first * (-m); ++it; } while (it != s.end()) { e += (*it).second * (*it).first; ++it; } cout << e << endl; } }
replace
19
20
19
20
TLE
p01144
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; class Road { public: int d, p; Road() {} Road(int d = 0, int p = 0) : d(d), p(p) {} bool operator<(const Road r) const { return p < r.p; } }; int main() { int n, m; while (1) { cin >> n >> m; if (n == 0 && m == 0) break; vector<Road> r; int d, p; for (int i = 0; i < n; i++) { cin >> d >> p; Road tmp(d, p); r.push_back(tmp); } sort(r.begin(), r.end()); int i = n - 1; for (int j = 0; j < m; j++) { r[i].d--; if (r[i].d == 0) i--; } int sum = 0; for (int j = 0; j < n; j++) { sum += r[j].d * r[j].p; } cout << sum << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; class Road { public: int d, p; Road() {} Road(int d = 0, int p = 0) : d(d), p(p) {} bool operator<(const Road r) const { return p < r.p; } }; int main() { int n, m; while (1) { cin >> n >> m; if (n == 0 && m == 0) break; vector<Road> r; int d, p; for (int i = 0; i < n; i++) { cin >> d >> p; Road tmp(d, p); r.push_back(tmp); } sort(r.begin(), r.end()); int i = n - 1; for (int j = 0; j < m; j++) { r[i].d--; if (r[i].d == 0) { if (i > 0) i--; else break; } } int sum = 0; for (int j = 0; j < n; j++) { sum += r[j].d * r[j].p; } cout << sum << endl; } return 0; }
replace
31
33
31
37
0
p01144
C++
Time Limit Exceeded
#include <iostream> using namespace std; int ways[11]; int main() { loop: int n, m; for (int i = 0; i < 11; i++) ways[i] = 0; cin >> n >> m; if (!n) return 0; for (int i = 0; i < n; i++) { int d, p; cin >> d >> p; ways[p] += d; } while (m > 0) { for (int i = 10; i > 0; i--) { if (ways[i] < m) { m -= ways[i]; ways[i] = 0; } else { ways[i] -= m; m = 0; } } } int ans = 0; for (int i = 1; i <= 10; i++) ans += ways[i] * i; cout << ans << endl; goto loop; }
#include <iostream> using namespace std; int ways[11]; int main() { loop: int n, m; for (int i = 0; i < 11; i++) ways[i] = 0; cin >> n >> m; if (!n) return 0; for (int i = 0; i < n; i++) { int d, p; cin >> d >> p; ways[p] += d; } for (int i = 10; i > 0; i--) { if (ways[i] < m) { m -= ways[i]; ways[i] = 0; } else { ways[i] -= m; m = 0; } } int ans = 0; for (int i = 1; i <= 10; i++) ans += ways[i] * i; cout << ans << endl; goto loop; }
replace
19
28
19
26
TLE
p01144
C++
Runtime Error
// C #include <algorithm> #include <functional> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int n, m; while (true) { cin >> n >> m; if (n == 0 && m == 0) break; vector<pair<int, int>> t(0); // 危険度、距離 t.resize(11001); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; // 距離、北市 t[i] = (make_pair(b, a)); } sort(t.begin(), t.end(), greater<pair<int, int>>()); int iii = 0; while (m > 0) { if (m >= t[iii].second) { m -= t[iii].second; t[iii].second = 0; } else { t[iii].second -= m; m = 0; } iii++; } int ans = 0; for (int i = 0; i < n; i++) { ans += t[i].first * t[i].second; } cout << ans << endl; } return 0; }
// C #include <algorithm> #include <functional> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int n, m; while (true) { cin >> n >> m; if (n == 0 && m == 0) break; vector<pair<int, int>> t(0); // 危険度、距離 t.resize(11001); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; // 距離、北市 t[i] = (make_pair(b, a)); } sort(t.begin(), t.end(), greater<pair<int, int>>()); int iii = 0; while (m > 0) { bool f = 0; for (int j = 0; j < n; j++) if (t[j].second != 0) f = 1; if (f == 0) break; // cout<<"a"; if (m >= t[iii].second) { m -= t[iii].second; t[iii].second = 0; } else { t[iii].second -= m; m = 0; } iii++; } int ans = 0; for (int i = 0; i < n; i++) { ans += t[i].first * t[i].second; } cout << ans << endl; } return 0; }
insert
23
23
23
30
0
p01144
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (n == 0 && m == 0) break; int d[n], p[n]; for (int i = 0; i < n; i++) { cin >> d[i] >> p[i]; } int pm = 0, nowp; while (m > 0) { for (int i = 0; i < n; i++) { pm = max(pm, p[i]); if (pm == p[i]) nowp = i; } if (m >= d[nowp]) { m = m - d[nowp]; d[nowp] = 0; p[nowp] = 0; } else { d[nowp] = d[nowp] - m; m = 0; } pm = 0; } int ptotal = 0; for (int i = 0; i < n; i++) { ptotal = ptotal + p[i] * d[i]; } cout << ptotal << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n, m; while (cin >> n >> m) { if (n == 0 && m == 0) break; int d[n], p[n]; for (int i = 0; i < n; i++) { cin >> d[i] >> p[i]; } int pm = 0, nowp; while (m > 0) { for (int i = 0; i < n; i++) { pm = max(pm, p[i]); if (pm == p[i]) nowp = i; } if (pm == 0) break; if (m >= d[nowp]) { m = m - d[nowp]; d[nowp] = 0; p[nowp] = 0; } else { d[nowp] = d[nowp] - m; m = 0; } pm = 0; } int ptotal = 0; for (int i = 0; i < n; i++) { ptotal = ptotal + p[i] * d[i]; } cout << ptotal << endl; } return 0; }
insert
19
19
19
21
TLE
p01144
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; int main() { for (int tci = 0;; tci++) { int N, M; scanf("%d%d", &N, &M); if (!N) break; pair<int, int> *pd = new pair<int, int>[N]; int ept = 0; for (int i = 0; i < N; i++) { scanf("%d%d", &pd[i].second, &pd[i].first); ept += pd[i].second * pd[i].first; } sort(pd, pd + N); reverse(pd, pd + N); int x = M; for (int i = 0; i < M && x > 0; i++) { ept -= min(pd[i].second, x) * pd[i].first; x -= pd[i].second; } printf("%d\n", ept); } return 0; }
#include <algorithm> #include <cstdio> using namespace std; int main() { for (int tci = 0;; tci++) { int N, M; scanf("%d%d", &N, &M); if (!N) break; pair<int, int> *pd = new pair<int, int>[N]; int ept = 0; for (int i = 0; i < N; i++) { scanf("%d%d", &pd[i].second, &pd[i].first); ept += pd[i].second * pd[i].first; } sort(pd, pd + N); reverse(pd, pd + N); int x = M; for (int i = 0; i < N && x > 0; i++) { ept -= min(pd[i].second, x) * pd[i].first; x -= pd[i].second; } printf("%d\n", ept); } return 0; }
replace
19
20
19
20
0
p01144
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> using namespace std; typedef pair<int, int> P; int main() { int n; long long m; while (cin >> n >> m && (n || m)) { priority_queue<P> que; int d, p; for (int i = 0; i < n; ++i) { cin >> d >> p; que.push(P(p, d)); } long long ans = 0; while (1) { P p = que.top(); que.pop(); m -= p.second; if (m <= 0) { ans += p.first * abs(m); break; } } while (!que.empty()) { P p = que.top(); que.pop(); ans += p.first * p.second; } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <string> using namespace std; typedef pair<int, int> P; int main() { int n; long long m; while (cin >> n >> m && (n || m)) { priority_queue<P> que; int d, p; for (int i = 0; i < n; ++i) { cin >> d >> p; que.push(P(p, d)); } long long ans = 0; while (!que.empty()) { P p = que.top(); que.pop(); m -= p.second; if (m <= 0) { ans += p.first * abs(m); break; } } while (!que.empty()) { P p = que.top(); que.pop(); ans += p.first * p.second; } cout << ans << endl; } return 0; }
replace
21
22
21
22
0
p01144
C++
Time Limit Exceeded
#include "bits/stdc++.h" #define REP(i, n) for (int i = 0; i < n; ++i) #define RREP(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define RFOR(i, m, n) for (int i = n - 1; i >= m; --i) #define ALL(v) v.begin(), v.end() #define PB(a) push_back(a) #define INF 1000000001 #define MOD 1000000007 #define EPS 1e-9 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; typedef long long ll; using namespace std; bool paircmp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; } int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int n, m, ans = 0; cin >> n >> m; vector<pair<int, int>> v(n); REP(i, n) { int a, b; cin >> a >> b; v[i] = {a, b}; } sort(ALL(v), paircmp); REP(i, n) { int a = min(m, v[i].first); m -= a; v[i].first -= a; ans += v[i].first * v[i].second; } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" #define REP(i, n) for (int i = 0; i < n; ++i) #define RREP(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define RFOR(i, m, n) for (int i = n - 1; i >= m; --i) #define ALL(v) v.begin(), v.end() #define PB(a) push_back(a) #define INF 1000000001 #define MOD 1000000007 #define EPS 1e-9 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; typedef long long ll; using namespace std; bool paircmp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; } int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int n, m, ans = 0; cin >> n >> m; if (!n) break; vector<pair<int, int>> v(n); REP(i, n) { int a, b; cin >> a >> b; v[i] = {a, b}; } sort(ALL(v), paircmp); REP(i, n) { int a = min(m, v[i].first); m -= a; v[i].first -= a; ans += v[i].first * v[i].second; } cout << ans << endl; } return 0; }
replace
25
26
25
27
TLE
p01144
C++
Time Limit Exceeded
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int d[11], n, m, i, a, b, sum, e; int main() { while (true) { memset(d, 0, sizeof(d)); sum = 0; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a >> b; d[b] += a; } for (i = 10; i >= 0; i--) { e = min(d[i], m); m -= e; sum += i * (d[i] - e); } cout << sum << endl; } }
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int d[11], n, m, i, a, b, sum, e; int main() { while (true) { memset(d, 0, sizeof(d)); sum = 0; cin >> n >> m; if (!n) { break; } for (i = 0; i < n; i++) { cin >> a >> b; d[b] += a; } for (i = 10; i >= 0; i--) { e = min(d[i], m); m -= e; sum += i * (d[i] - e); } cout << sum << endl; } }
insert
10
10
10
13
TLE
p01144
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, m; while (cin >> n >> m, n) { vector<pair<int, int>> v; int ans = 0; for (int i = 0; i < n; i++) { int d, p; cin >> d >> p; ans += d * p; v.push_back(make_pair(p, d)); } sort(v.begin(), v.end()); int i = v.size() - 1; while (m > 0) { ans -= min(m, v[i].second) * v[i].first; m -= min(m, v[i].second); i--; } cout << ans << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, m; while (cin >> n >> m, n) { vector<pair<int, int>> v; int ans = 0; for (int i = 0; i < n; i++) { int d, p; cin >> d >> p; ans += d * p; v.push_back(make_pair(p, d)); } sort(v.begin(), v.end()); int i = v.size() - 1; while (m > 0) { ans -= min(m, v[i].second) * v[i].first; m -= min(m, v[i].second); i--; if (i < 0) break; } cout << ans << endl; } }
insert
21
21
21
23
0
p01144
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; vector<pii> ans; int main() { while (1) { int N, M; cin >> N >> M; if (!N) break; ans.clear(); for (int i = 0; i < N; i++) { int d, p; cin >> d >> p; ans.push_back(pii(p, d)); } sort(ans.begin(), ans.end()); long long sum = 0; while (M > 0) { int id = ans.size() - 1; if (M > ans[id].second) { M -= ans[id].second; ans.pop_back(); } else if (M > 0) { ans[id].second -= M; M = 0; } } for (auto x : ans) { sum += x.first * x.second; } cout << sum << endl; } }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; vector<pii> ans; int main() { while (1) { int N, M; cin >> N >> M; if (!N) break; ans.clear(); for (int i = 0; i < N; i++) { int d, p; cin >> d >> p; ans.push_back(pii(p, d)); } sort(ans.begin(), ans.end()); long long sum = 0; while (M > 0 and ans.size()) { int id = ans.size() - 1; if (M > ans[id].second) { M -= ans[id].second; ans.pop_back(); } else if (M > 0) { ans[id].second -= M; M = 0; } } for (auto x : ans) { sum += x.first * x.second; } cout << sum << endl; } }
replace
21
22
21
22
0
p01145
C++
Time Limit Exceeded
//////////////////////////////////////// /// tu3 pro-con template /// //////////////////////////////////////// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //// MACRO //// #define countof(a) (sizeof(a) / sizeof(a[0])) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, s, n) for (int i = (s); i < (n); i++) #define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--) #define pos(c, i) c.being() + (i) #define allof(c) c.begin(), c.end() #define aallof(a) a, countof(a) #define partof(c, i, n) c.begin() + (i), c.begin() + (i) + (n) #define apartof(a, i, n) a + (i), a + (i) + (n) #define EPS 1e-9 #define INF (1L << 30) #define LINF (1LL << 60) #define PREDICATE(t, a, exp) [&](const t &a) -> bool { return exp; } #define COMPARISON_T(t) bool (*)(const t &, const t &) #define COMPARISON(t, a, b, exp) \ [&](const t &a, const t &b) -> bool { return exp; } #define CONVERTER(TSrc, t, TDest, exp) \ [&](const TSrc &t) -> TDest { return exp; } inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } //// i/o helper //// struct _Reader { template <class T> _Reader operator,(T &rhs) { cin >> rhs; return *this; } }; struct _Writer { bool f; _Writer() : f(false) {} template <class T> _Writer operator,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } }; #define READ(t, ...) \ t __VA_ARGS__; \ _Reader(), __VA_ARGS__ #define WRITE(...) \ _Writer(), __VA_ARGS__; \ cout << endl template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) {} }; template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) {} }; template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {} }; template <class T> T read() { T t; cin >> t; return t; } template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; } template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; } template <class T> vevector<T> readjag() { return read<T>(read<int>()); } template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; } template <class T1, class T2> inline istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <class T1, class T2> inline ostream &operator<<(ostream &out, pair<T1, T2> &p) { out << p.first << p.second; return out; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &v) { ostringstream ss; for (auto x : v) ss << x << ' '; auto s = ss.str(); out << s.substr(0, s.length() - 1) << endl; return out; } //// start up //// void solve(); int main() { freopen("E:/My Documents/Downloads/judge-data/C/C2", "r", stdin); freopen("E:/My Documents/Downloads/judge-data/C/C2.out", "w", stdout); solve(); return 0; } //////////////////// /// template end /// //////////////////// void solve() { int cases = INF; REP(_, cases) { READ(string, X); if (X == "#") { break; } X += "$#?"; vector<bool> boin(256); vector<bool> musei_shiin(256); musei_shiin['k'] = musei_shiin['s'] = musei_shiin['t'] = musei_shiin['h'] = musei_shiin['p'] = musei_shiin['$'] = true; string result; result += X[0]; char hit = '#'; for (int i = 1; i < X.size() - 3; i++) { if (hit == '#') { switch (X[i]) { case 'i': case 'u': if ((musei_shiin[X[i - 1]] || i > 1 && X[i - 1] == 'y' && musei_shiin[X[i - 2]]) // 前が無声子音 && (musei_shiin[X[i + 1]] || X[i + 1] == 'y' && musei_shiin[X[i + 2]]) // 後ろが無声子音 ) hit = X[i]; break; case 'a': case 'o': if ((musei_shiin[X[i - 1]] || i > 1 && X[i - 1] == 'y' && musei_shiin[X[i - 2]]) // 前が無声子音 && (musei_shiin[X[i + 1]] || X[i + 1] == 'y' && musei_shiin[X[i + 2]]) // 後ろが無声子音 && (X[i + 2] == X[i] || X[i + 2] == 'y' && X[i + 3] == X[i]) // 後ろが同じ母音無声子音 ) hit = X[i]; break; } if (hit != '#') result += '('; result += X[i]; if (hit != '#') result += ')'; } else { if (X[i] == 'a' || X[i] == 'i' || X[i] == 'u' || X[i] == 'e' || X[i] == 'o') { hit = '#'; } result += X[i]; } } WRITE(result); } }
//////////////////////////////////////// /// tu3 pro-con template /// //////////////////////////////////////// #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; //// MACRO //// #define countof(a) (sizeof(a) / sizeof(a[0])) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, s, n) for (int i = (s); i < (n); i++) #define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--) #define pos(c, i) c.being() + (i) #define allof(c) c.begin(), c.end() #define aallof(a) a, countof(a) #define partof(c, i, n) c.begin() + (i), c.begin() + (i) + (n) #define apartof(a, i, n) a + (i), a + (i) + (n) #define EPS 1e-9 #define INF (1L << 30) #define LINF (1LL << 60) #define PREDICATE(t, a, exp) [&](const t &a) -> bool { return exp; } #define COMPARISON_T(t) bool (*)(const t &, const t &) #define COMPARISON(t, a, b, exp) \ [&](const t &a, const t &b) -> bool { return exp; } #define CONVERTER(TSrc, t, TDest, exp) \ [&](const TSrc &t) -> TDest { return exp; } inline int sign(double x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); } //// i/o helper //// struct _Reader { template <class T> _Reader operator,(T &rhs) { cin >> rhs; return *this; } }; struct _Writer { bool f; _Writer() : f(false) {} template <class T> _Writer operator,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } }; #define READ(t, ...) \ t __VA_ARGS__; \ _Reader(), __VA_ARGS__ #define WRITE(...) \ _Writer(), __VA_ARGS__; \ cout << endl template <class T> struct vevector : public vector<vector<T>> { vevector(int n = 0, int m = 0, const T &initial = T()) : vector<vector<T>>(n, vector<T>(m, initial)) {} }; template <class T> struct vevevector : public vector<vevector<T>> { vevevector(int n = 0, int m = 0, int l = 0, const T &initial = T()) : vector<vevector<T>>(n, vevector<T>(m, l, initial)) {} }; template <class T> struct vevevevector : public vector<vevevector<T>> { vevevevector(int n = 0, int m = 0, int l = 0, int k = 0, const T &initial = T()) : vector<vevevector<T>>(n, vevevector<T>(m, l, k, initial)) {} }; template <class T> T read() { T t; cin >> t; return t; } template <class T> vector<T> read(int n) { vector<T> v; REP(i, n) { v.push_back(read<T>()); } return v; } template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i, n) v.push_back(read<T>(m)); return v; } template <class T> vevector<T> readjag() { return read<T>(read<int>()); } template <class T> vevector<T> readjag(int n) { vevector<T> v; REP(i, n) v.push_back(readjag<T>()); return v; } template <class T1, class T2> inline istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <class T1, class T2> inline ostream &operator<<(ostream &out, pair<T1, T2> &p) { out << p.first << p.second; return out; } template <class T> inline ostream &operator<<(ostream &out, vector<T> &v) { ostringstream ss; for (auto x : v) ss << x << ' '; auto s = ss.str(); out << s.substr(0, s.length() - 1) << endl; return out; } //// start up //// void solve(); int main() { solve(); return 0; } //////////////////// /// template end /// //////////////////// void solve() { int cases = INF; REP(_, cases) { READ(string, X); if (X == "#") { break; } X += "$#?"; vector<bool> boin(256); vector<bool> musei_shiin(256); musei_shiin['k'] = musei_shiin['s'] = musei_shiin['t'] = musei_shiin['h'] = musei_shiin['p'] = musei_shiin['$'] = true; string result; result += X[0]; char hit = '#'; for (int i = 1; i < X.size() - 3; i++) { if (hit == '#') { switch (X[i]) { case 'i': case 'u': if ((musei_shiin[X[i - 1]] || i > 1 && X[i - 1] == 'y' && musei_shiin[X[i - 2]]) // 前が無声子音 && (musei_shiin[X[i + 1]] || X[i + 1] == 'y' && musei_shiin[X[i + 2]]) // 後ろが無声子音 ) hit = X[i]; break; case 'a': case 'o': if ((musei_shiin[X[i - 1]] || i > 1 && X[i - 1] == 'y' && musei_shiin[X[i - 2]]) // 前が無声子音 && (musei_shiin[X[i + 1]] || X[i + 1] == 'y' && musei_shiin[X[i + 2]]) // 後ろが無声子音 && (X[i + 2] == X[i] || X[i + 2] == 'y' && X[i + 3] == X[i]) // 後ろが同じ母音無声子音 ) hit = X[i]; break; } if (hit != '#') result += '('; result += X[i]; if (hit != '#') result += ')'; } else { if (X[i] == 'a' || X[i] == 'i' || X[i] == 'u' || X[i] == 'e' || X[i] == 'o') { hit = '#'; } result += X[i]; } } WRITE(result); } }
delete
133
135
133
133
TLE
p01146
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iostream> #include <queue> #include <vector> using namespace std; #define loop(i, a, b) for (int i = (a); i < int(b); i++) #define rep(i, b) loop(i, 0, b) #define all(c) (c).begin(), (c).end() int const inf = 1 << 29; struct Edge { Edge(int dst, int weight) : dst(dst), weight(weight) {} int dst, weight; }; struct State { State(int dst, int weight, int rest) : dst(dst), weight(weight), rest(rest) {} int dst, weight, rest; bool operator<(const State &s) const { return weight > s.weight; } }; typedef vector<vector<Edge>> Graph; // M : 制限時間 // L : 冷凍できる頂点の数 // A : 始点 // H : 終点 int V, M, L, E, A, H; bool isL[128]; Graph g; int dp[100][100]; int solve() { priority_queue<State> q; rep(i, V) rep(j, M + 1) dp[i][j] = inf; dp[A][M] = 0; q.emplace(A, 0, M); while (q.size()) { State s = q.top(); q.pop(); int src = s.dst, weight = s.weight, rest = s.rest; if (src == H) return weight; if (dp[src][rest] < weight) continue; rep(i, g[src].size()) { int dst = g[src][i].dst; int weight = g[src][i].weight; if (rest - weight >= 0 && dp[dst][rest - weight] > dp[src][rest] + weight) { dp[dst][rest - weight] = dp[src][rest] + weight; q.push(State(dst, dp[src][rest] + weight, rest - weight)); } if (isL[src]) { for (int j = 1; rest + j <= M; j++) { if (rest + j - weight >= 0 && dp[dst][rest + j - weight] > dp[src][rest] + weight + j) { dp[dst][rest + j - weight] = dp[src][rest] + weight + j; q.push(State(dst, dp[src][rest] + weight + j, rest - weight + j)); } } } } } return inf; } int main() { while (cin >> V >> M >> L >> E >> A >> H && V) { memset(isL, 0, sizeof(isL)); g.assign(V, {}); isL[A] = isL[H] = true; rep(i, L) { int v; cin >> v; isL[v] = true; } rep(i, E) { int u, v, t; cin >> u >> v >> t; g[u].push_back(Edge(v, t)); g[v].push_back(Edge(u, t)); } int ans = solve(); if (ans >= inf) cout << "Help!"; else cout << ans; cout << endl; } }
#include <algorithm> #include <cstring> #include <iostream> #include <queue> #include <vector> using namespace std; #define loop(i, a, b) for (int i = (a); i < int(b); i++) #define rep(i, b) loop(i, 0, b) #define all(c) (c).begin(), (c).end() int const inf = 1 << 29; struct Edge { Edge(int dst, int weight) : dst(dst), weight(weight) {} int dst, weight; }; struct State { State(int dst, int weight, int rest) : dst(dst), weight(weight), rest(rest) {} int dst, weight, rest; bool operator<(const State &s) const { return weight > s.weight; } }; typedef vector<vector<Edge>> Graph; // M : 制限時間 // L : 冷凍できる頂点の数 // A : 始点 // H : 終点 int V, M, L, E, A, H; bool isL[128]; Graph g; int dp[128][128]; int solve() { priority_queue<State> q; rep(i, V) rep(j, M + 1) dp[i][j] = inf; dp[A][M] = 0; q.emplace(A, 0, M); while (q.size()) { State s = q.top(); q.pop(); int src = s.dst, weight = s.weight, rest = s.rest; if (src == H) return weight; if (dp[src][rest] < weight) continue; rep(i, g[src].size()) { int dst = g[src][i].dst; int weight = g[src][i].weight; if (rest - weight >= 0 && dp[dst][rest - weight] > dp[src][rest] + weight) { dp[dst][rest - weight] = dp[src][rest] + weight; q.push(State(dst, dp[src][rest] + weight, rest - weight)); } if (isL[src]) { for (int j = 1; rest + j <= M; j++) { if (rest + j - weight >= 0 && dp[dst][rest + j - weight] > dp[src][rest] + weight + j) { dp[dst][rest + j - weight] = dp[src][rest] + weight + j; q.push(State(dst, dp[src][rest] + weight + j, rest - weight + j)); } } } } } return inf; } int main() { while (cin >> V >> M >> L >> E >> A >> H && V) { memset(isL, 0, sizeof(isL)); g.assign(V, {}); isL[A] = isL[H] = true; rep(i, L) { int v; cin >> v; isL[v] = true; } rep(i, E) { int u, v, t; cin >> u >> v >> t; g[u].push_back(Edge(v, t)); g[v].push_back(Edge(u, t)); } int ans = solve(); if (ans >= inf) cout << "Help!"; else cout << ans; cout << endl; } }
replace
34
35
34
35
0
p01146
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef int Weight; typedef pair<Weight, int> Data; // enable reduce struct Heap { shared_ptr<Heap> l, r, p; Data val; Heap(Data v) : val(v) {} Data top() { return val; } }; int cnt1, cnt2; shared_ptr<Heap> meld(shared_ptr<Heap> a, shared_ptr<Heap> b, shared_ptr<Heap> p = nullptr) { ++cnt1; if (p == nullptr) ++cnt2; if (!a) { if (b) b->p = p; return b; } if (!b) { if (a) a->p = p; return a; } if (a->val > b->val) swap(a, b); a->p = p; a->r = meld(a->r, b, a); swap(a->l, a->r); return a; } pair<shared_ptr<Heap>, shared_ptr<Heap>> push(shared_ptr<Heap> h, Data v) { auto n = make_shared<Heap>(v); return make_pair(meld(h, n), n); } shared_ptr<Heap> pop(shared_ptr<Heap> h) { if (h->l) h->l->p.reset(); if (h->r) h->r->p.reset(); return meld(h->l, h->r); } shared_ptr<Heap> reduce(shared_ptr<Heap> h, shared_ptr<Heap> root, Data v) { if (v > h->val) return root; h->val = v; if (!h->p) return root; if (h->val < h->p->val) { if (h->p->l && h->p->l == h) { h->p->l.reset(); return meld(h, root); } else { h->p->r.reset(); return meld(h, root); } } else return root; } Weight INF = 1000000000; struct Edge { int src, dest; Weight weight; bool operator<(const Edge &rhs) const { return weight > rhs.weight; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; typedef vector<Weight> Array; typedef vector<Array> Matrix; void add_edge(Graph &g, int src, int dest, Weight weight) { g[src].push_back((Edge){src, dest, weight}); g[dest].push_back((Edge){dest, src, weight}); } template <typename G> void dijkstra(G &g, Array &d, int s) { int n = g.size(); d.assign(n, INF); d[s] = 0; shared_ptr<Heap> que; vector<shared_ptr<Heap>> nodes(n); auto p = push(que, Data(0, s)); que = p.first; nodes[s] = p.second; assert(que != nullptr); while (que) { Weight dist = que->top().first; int v = que->top().second; que = pop(que); nodes[v].reset(); if (d[v] < dist) continue; REP(i, g(v).size()) { Edge e = g(v)[i]; if (d[e.dest] > d[v] + e.weight) { d[e.dest] = d[v] + e.weight; if (!nodes[e.dest]) { auto p = push(que, Data(d[e.dest], e.dest)); que = p.first; nodes[e.dest] = p.second; } else { que = reduce(nodes[e.dest], que, Data(d[e.dest], e.dest)); } } } } } struct G { Graph g; int m; vector<bool> f; G(Graph &g, int m, vector<bool> &f) : g(g), m(m), f(f) {} Edges operator()(int i) { int j = i / (m + 1); int k = i % (m + 1); Edges es; REP(l, g[j].size()) { if (k + g[j][l].weight > m) continue; es.push_back((Edge){i, g[j][l].dest * (m + 1) + k + g[j][l].weight, g[j][l].weight}); } if (f[j] && k) es.push_back((Edge){i, i - 1, 1}); return es; } size_t size() const { return g.size() * (m + 1); } }; int main() { while (1) { int n, m, l, k, a, h; cin >> n >> m >> l >> k >> a >> h; if (!n) break; vector<int> f(l); REP(i, l) cin >> f[i]; Graph g(n); REP(i, k) { int s, t, c; cin >> s >> t >> c; add_edge(g, s, t, c); } vector<bool> fb(n, false); REP(i, l) fb[f[i]] = true; G gg(g, m, fb); Array d(gg.size()); cnt1 = cnt2 = 0; dijkstra<G>(gg, d, a * (m + 1)); cerr << cnt1 << ' ' << cnt2 << endl; int mc = INF; REP(i, m + 1) mc = min(mc, d[h * (m + 1) + i]); if (mc < INF) cout << mc << endl; else cout << "Help!" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef int Weight; typedef pair<Weight, int> Data; // enable reduce struct Heap { shared_ptr<Heap> l, r, p; Data val; Heap(Data v) : val(v) {} Data top() { return val; } }; int cnt1, cnt2; shared_ptr<Heap> meld(shared_ptr<Heap> a, shared_ptr<Heap> b, shared_ptr<Heap> p = nullptr) { ++cnt1; if (p == nullptr) ++cnt2; if (!a) { if (b) b->p = p; return b; } if (!b) { if (a) a->p = p; return a; } if (a->val > b->val) swap(a, b); a->p = p; a->r = meld(a->r, b, a); swap(a->l, a->r); return a; } pair<shared_ptr<Heap>, shared_ptr<Heap>> push(shared_ptr<Heap> h, Data v) { auto n = make_shared<Heap>(v); return make_pair(meld(h, n), n); } shared_ptr<Heap> pop(shared_ptr<Heap> h) { if (h->l) h->l->p.reset(); if (h->r) h->r->p.reset(); return meld(h->l, h->r); } shared_ptr<Heap> reduce(shared_ptr<Heap> h, shared_ptr<Heap> root, Data v) { if (v > h->val) return root; h->val = v; if (!h->p) return root; if (h->val < h->p->val) { if (h->p->l && h->p->l == h) { h->p->l.reset(); return meld(h, root); } else { h->p->r.reset(); return meld(h, root); } } else return root; } Weight INF = 1000000000; struct Edge { int src, dest; Weight weight; bool operator<(const Edge &rhs) const { return weight > rhs.weight; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; typedef vector<Weight> Array; typedef vector<Array> Matrix; void add_edge(Graph &g, int src, int dest, Weight weight) { g[src].push_back((Edge){src, dest, weight}); g[dest].push_back((Edge){dest, src, weight}); } template <typename G> void dijkstra(G &g, Array &d, int s) { int n = g.size(); d.assign(n, INF); d[s] = 0; shared_ptr<Heap> que; vector<shared_ptr<Heap>> nodes(n); auto p = push(que, Data(0, s)); que = p.first; nodes[s] = p.second; assert(que != nullptr); while (que) { Weight dist = que->top().first; int v = que->top().second; que = pop(que); nodes[v].reset(); if (d[v] < dist) continue; REP(i, g(v).size()) { Edge e = g(v)[i]; if (d[e.dest] > d[v] + e.weight) { d[e.dest] = d[v] + e.weight; if (!nodes[e.dest]) { auto p = push(que, Data(d[e.dest], e.dest)); que = p.first; nodes[e.dest] = p.second; } else { que = reduce(nodes[e.dest], que, Data(d[e.dest], e.dest)); } } } } } struct G { Graph g; int m; vector<bool> f; G(Graph &g, int m, vector<bool> &f) : g(g), m(m), f(f) {} Edges operator()(int i) { int j = i / (m + 1); int k = i % (m + 1); Edges es; REP(l, g[j].size()) { if (k + g[j][l].weight > m) continue; es.push_back((Edge){i, g[j][l].dest * (m + 1) + k + g[j][l].weight, g[j][l].weight}); } if (f[j] && k) es.push_back((Edge){i, i - 1, 1}); return es; } size_t size() const { return g.size() * (m + 1); } }; int main() { while (1) { int n, m, l, k, a, h; cin >> n >> m >> l >> k >> a >> h; if (!n) break; vector<int> f(l); REP(i, l) cin >> f[i]; Graph g(n); REP(i, k) { int s, t, c; cin >> s >> t >> c; add_edge(g, s, t, c); } vector<bool> fb(n, false); REP(i, l) fb[f[i]] = true; G gg(g, m, fb); Array d(gg.size()); cnt1 = cnt2 = 0; dijkstra<G>(gg, d, a * (m + 1)); int mc = INF; REP(i, m + 1) mc = min(mc, d[h * (m + 1) + i]); if (mc < INF) cout << mc << endl; else cout << "Help!" << endl; } return 0; }
delete
158
159
158
158
0
2 2 11 10 21 16 37 26 70 34 62 36
p01146
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; struct Edge { int to, cost; Edge() {} Edge(int to, int cost) : to(to), cost(cost) {} }; struct State { Edge e; int ltime; State(Edge e, int ltime) : e(e), ltime(ltime) {} bool operator>(const State &rhs) const { return (e.cost > rhs.e.cost); } }; int main() { int N, M, L, K, A, H; while (scanf("%d %d %d %d %d %d", &N, &M, &L, &K, &A, &H) && N) { vector<Edge> G[128]; bool able[128] = {0}; int dp[128][128]; for (int i = 0; i < N; i++) { fill(dp[i], dp[i] + 128, INF); } for (int i = 0; i < L; i++) { int x; scanf("%d", &x); able[x] = true; } able[A] = able[H] = 0; for (int i = 0; i < K; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); G[a].push_back(Edge(b, c)); G[b].push_back(Edge(a, c)); } priority_queue<State, vector<State>, greater<State>> pq; pq.push(State(Edge(A, 0), M)); while (!pq.empty()) { State tmp = pq.top(); pq.pop(); if (dp[tmp.e.to][tmp.ltime] <= tmp.e.cost) continue; dp[tmp.e.to][tmp.ltime] = tmp.e.cost; for (int i = 0; i < G[tmp.e.to].size(); i++) { Edge nxt = G[tmp.e.to][i]; if (nxt.cost > tmp.ltime) continue; for (int j = 0; j + tmp.ltime - nxt.cost <= M; j++) { if (j != 0 && !able[nxt.to]) break; else if (dp[nxt.to][j + tmp.ltime - nxt.cost] >= tmp.e.cost + j + nxt.cost) { pq.push(State(Edge(nxt.to, tmp.e.cost + j + nxt.cost), j + tmp.ltime - nxt.cost)); } } } } int ans = *min_element(dp[H], dp[H] + M + 1); if (ans != INF) printf("%d\n", ans); else printf("Help!\n"); } return (0); }
#include <bits/stdc++.h> using namespace std; const int INF = 1001001001; struct Edge { int to, cost; Edge() {} Edge(int to, int cost) : to(to), cost(cost) {} }; struct State { Edge e; int ltime; State(Edge e, int ltime) : e(e), ltime(ltime) {} bool operator>(const State &rhs) const { return (e.cost > rhs.e.cost); } }; int main() { int N, M, L, K, A, H; while (scanf("%d %d %d %d %d %d", &N, &M, &L, &K, &A, &H) && N) { vector<Edge> G[128]; bool able[128] = {0}; int dp[128][128]; for (int i = 0; i < N; i++) { fill(dp[i], dp[i] + 128, INF); } for (int i = 0; i < L; i++) { int x; scanf("%d", &x); able[x] = true; } able[A] = able[H] = 0; for (int i = 0; i < K; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); G[a].push_back(Edge(b, c)); G[b].push_back(Edge(a, c)); } priority_queue<State, vector<State>, greater<State>> pq; pq.push(State(Edge(A, 0), M)); while (!pq.empty()) { State tmp = pq.top(); pq.pop(); if (dp[tmp.e.to][tmp.ltime] <= tmp.e.cost) continue; dp[tmp.e.to][tmp.ltime] = tmp.e.cost; if (tmp.e.to == H) break; for (int i = 0; i < G[tmp.e.to].size(); i++) { Edge nxt = G[tmp.e.to][i]; if (nxt.cost > tmp.ltime) continue; for (int j = 0; j + tmp.ltime - nxt.cost <= M; j++) { if (j != 0 && !able[nxt.to]) break; else if (dp[nxt.to][j + tmp.ltime - nxt.cost] >= tmp.e.cost + j + nxt.cost) { pq.push(State(Edge(nxt.to, tmp.e.cost + j + nxt.cost), j + tmp.ltime - nxt.cost)); } } } } int ans = *min_element(dp[H], dp[H] + M + 1); if (ans != INF) printf("%d\n", ans); else printf("Help!\n"); } return (0); }
insert
55
55
55
58
TLE
p01146
C++
Memory Limit Exceeded
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stdio.h> #include <string> #include <vector> #define INF 100000000 using namespace std; typedef pair<int, int> P; typedef pair<int, P> PP; int main() { int n, m, k, l, a, h; while (cin >> n >> m >> l >> k >> a >> h, n || m || l || k || h || a) { vector<vector<int>> cost(n, vector<int>(n, INF)); map<int, bool> hos; for (int i = 0; i < l; i++) { int x; cin >> x; hos[x] = true; } for (int i = 0; i < k; i++) { int x, y, t; cin >> x >> y >> t; cost[x][y] = t; cost[y][x] = t; } priority_queue<PP, vector<PP>, greater<PP>> que; vector<vector<int>> d(101, vector<int>(101, INF)); que.push(PP(0, P(a, m))); // 時間、位置、残り d[a][m] = 0; // 場所,残り int ans = -1; while (!que.empty()) { // cout<<"--"<<endl; PP p = que.top(); que.pop(); int now = p.second.first, time = p.first, left = p.second.second; if (now == h) { ans = time; break; } if (hos[now]) for (int i = 1; i + left <= m; i++) { if (d[now][left + i] > time + i) { que.push(PP(time + i, P(now, left + i))); } } for (int i = 0; i < n; i++) { if (cost[now][i] == INF) { continue; } // cout<<"aaaaaaaaa"<<endl; if (left - cost[now][i] >= 0 && d[i][left - cost[now][i]] > time + cost[now][i]) { que.push(PP(time + cost[now][i], P(i, left - cost[now][i]))); d[i][left - cost[now][i]] = time + cost[now][i]; } } } if (ans == -1) cout << "Help!" << endl; else cout << ans << endl; } return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <stdio.h> #include <string> #include <vector> #define INF 100000000 using namespace std; typedef pair<int, int> P; typedef pair<int, P> PP; int main() { int n, m, k, l, a, h; while (cin >> n >> m >> l >> k >> a >> h, n || m || l || k || h || a) { vector<vector<int>> cost(n, vector<int>(n, INF)); map<int, bool> hos; for (int i = 0; i < l; i++) { int x; cin >> x; hos[x] = true; } for (int i = 0; i < k; i++) { int x, y, t; cin >> x >> y >> t; cost[x][y] = t; cost[y][x] = t; } priority_queue<PP, vector<PP>, greater<PP>> que; vector<vector<int>> d(101, vector<int>(101, INF)); que.push(PP(0, P(a, m))); // 時間、位置、残り d[a][m] = 0; // 場所,残り int ans = -1; while (!que.empty()) { // cout<<"--"<<endl; PP p = que.top(); que.pop(); int now = p.second.first, time = p.first, left = p.second.second; if (now == h) { ans = time; break; } if (hos[now]) for (int i = 1; i + left <= m; i++) { if (d[now][left + i] > time + i) { que.push(PP(time + i, P(now, left + i))); d[now][left + i] = time + i; } } for (int i = 0; i < n; i++) { if (cost[now][i] == INF) { continue; } // cout<<"aaaaaaaaa"<<endl; if (left - cost[now][i] >= 0 && d[i][left - cost[now][i]] > time + cost[now][i]) { que.push(PP(time + cost[now][i], P(i, left - cost[now][i]))); d[i][left - cost[now][i]] = time + cost[now][i]; } } } if (ans == -1) cout << "Help!" << endl; else cout << ans << endl; } return 0; }
insert
52
52
52
53
MLE
p01146
C++
Runtime Error
#ifndef _WIN32 #include <iostream> #endif // !_WIN32 #include <algorithm> #include <queue> #include <tuple> #include <vector> using namespace std; typedef long long LL; const LL INF = 1e17; #define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++) #define REP(i, n) FOR(i, 0, n) typedef tuple<LL, int, int> edge; typedef priority_queue<edge> QUE; typedef vector<LL> V; typedef vector<V> VV; int N, M, L, E, s, t; int a[1123]; int b[1123]; LL c[1123]; int l[1123]; VV dist(int s, VV g) { VV res(N, V(M + 1, INF)); QUE que; que.push(edge{0, s, M}); res[s][M] = 0; while (que.size()) { LL cost; int v, m; tie(cost, v, m) = que.top(); que.pop(); cost = -cost; if (res[v][m] < cost) continue; if (l[v] == 1 && m < M) { if (res[v][m + 1] > cost + 1) { res[v][m + 1] = cost + 1; que.push(edge{-cost - 1, v, m + 1}); } } for (auto &e : g[v]) { int u = v ^ a[e] ^ b[e]; int nxt_m = m - c[e]; if (nxt_m < 0) continue; LL nxt_cost = cost + c[e]; if (res[u][nxt_m] > nxt_cost) { res[u][nxt_m] = nxt_cost; que.push(edge{-nxt_cost, u, nxt_m}); } } } return res; } int main() { while (cin >> N >> M >> L >> E >> s >> t, N + M + L + E + s + t) { REP(i, N) l[i] = 0; REP(i, L) { int p; cin >> p; l[p] = 1; } VV g(N); REP(i, E) { cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(i); g[b[i]].push_back(i); } auto d = dist(s, g); LL res = INF; REP(i, M + 1) res = min(res, d[t][i]); if (res == INF) cout << "Help!" << endl; else cout << res << endl; } }
#ifndef _WIN32 #include <iostream> #endif // !_WIN32 #include <algorithm> #include <queue> #include <tuple> #include <vector> using namespace std; typedef long long LL; const LL INF = 1e17; #define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++) #define REP(i, n) FOR(i, 0, n) typedef tuple<LL, int, int> edge; typedef priority_queue<edge> QUE; typedef vector<LL> V; typedef vector<V> VV; int N, M, L, E, s, t; int a[112345]; int b[112345]; LL c[112345]; int l[1123]; VV dist(int s, VV g) { VV res(N, V(M + 1, INF)); QUE que; que.push(edge{0, s, M}); res[s][M] = 0; while (que.size()) { LL cost; int v, m; tie(cost, v, m) = que.top(); que.pop(); cost = -cost; if (res[v][m] < cost) continue; if (l[v] == 1 && m < M) { if (res[v][m + 1] > cost + 1) { res[v][m + 1] = cost + 1; que.push(edge{-cost - 1, v, m + 1}); } } for (auto &e : g[v]) { int u = v ^ a[e] ^ b[e]; int nxt_m = m - c[e]; if (nxt_m < 0) continue; LL nxt_cost = cost + c[e]; if (res[u][nxt_m] > nxt_cost) { res[u][nxt_m] = nxt_cost; que.push(edge{-nxt_cost, u, nxt_m}); } } } return res; } int main() { while (cin >> N >> M >> L >> E >> s >> t, N + M + L + E + s + t) { REP(i, N) l[i] = 0; REP(i, L) { int p; cin >> p; l[p] = 1; } VV g(N); REP(i, E) { cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(i); g[b[i]].push_back(i); } auto d = dist(s, g); LL res = INF; REP(i, M + 1) res = min(res, d[t][i]); if (res == INF) cout << "Help!" << endl; else cout << res << endl; } }
replace
22
25
22
25
0
p01146
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <vector> #define INF (1 << 29) using namespace std; int V, E, L, M, A, H, P, Q, R, C; int main() { while (true) { scanf("%d", &V); scanf("%d", &M); scanf("%d", &L); scanf("%d", &E); scanf("%d", &A); scanf("%d", &H); if (V == 0) { break; } vector<vector<pair<int, int>>> G(V); vector<bool> ok(V, false); for (int i = 0; i < L; i++) { scanf("%d", &C); ok[C] = true; } for (int i = 0; i < E; i++) { scanf("%d", &P); scanf("%d", &Q); scanf("%d", &R); G[P].push_back(make_pair(Q, R)); G[Q].push_back(make_pair(P, R)); } vector<vector<int>> dp(V, vector<int>(M + 1, INF)); dp[A][M] = 0; for (int rep = 0; rep < V - 1; rep++) { for (int i = 0; i < V; i++) { if (i != A) { for (int j = 0; j <= M; j++) { for (int k = 0; k < G[i].size(); k++) { if (G[i][k].second + j <= M) { dp[i][j] = min(dp[i][j], dp[G[i][k].first][j + G[i][k].second] + G[i][k].second); } } } } if (ok[i]) { for (int j = 0; j < M; j++) { for (int k = j + 1; k <= M; k++) { dp[i][k] = min(dp[i][k], dp[i][j] + k - j); } } } } } int ret = INF; for (int i = 0; i <= M; i++) { ret = min(ret, dp[H][i]); } if (ret != INF) { printf("%d\n", ret); } else { printf("Help!\n"); } } return 0; }
#include <algorithm> #include <cstdio> #include <vector> #define INF (1 << 29) using namespace std; int V, E, L, M, A, H, P, Q, R, C; int main() { while (true) { scanf("%d", &V); scanf("%d", &M); scanf("%d", &L); scanf("%d", &E); scanf("%d", &A); scanf("%d", &H); if (V == 0) { break; } vector<vector<pair<int, int>>> G(V); vector<bool> ok(V, false); for (int i = 0; i < L; i++) { scanf("%d", &C); ok[C] = true; } for (int i = 0; i < E; i++) { scanf("%d", &P); scanf("%d", &Q); scanf("%d", &R); G[P].push_back(make_pair(Q, R)); G[Q].push_back(make_pair(P, R)); } vector<vector<int>> dp(V, vector<int>(M + 1, INF)); dp[A][M] = 0; for (int rep = 0; rep < V - 1; rep++) { for (int i = 0; i < V; i++) { if (i != A) { for (int j = 0; j <= M; j++) { for (int k = 0; k < G[i].size(); k++) { if (G[i][k].second + j <= M) { dp[i][j] = min(dp[i][j], dp[G[i][k].first][j + G[i][k].second] + G[i][k].second); } } } } if (ok[i]) { int t = INF; for (int j = 0; j <= M; j++) { t = min(dp[i][j], ++t); dp[i][j] = t; } } } } int ret = INF; for (int i = 0; i <= M; i++) { ret = min(ret, dp[H][i]); } if (ret != INF) { printf("%d\n", ret); } else { printf("Help!\n"); } } return 0; }
replace
60
64
60
66
TLE
p01146
C++
Runtime Error
#include <algorithm> #include <climits> #include <functional> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) struct Edge { int to; int cost; }; struct Node { int city_index; int total_cost; int current_life; int remain_can_regain; bool operator>(const Node &a) const { return total_cost > a.total_cost; } }; int main() { int city_count, initial_life, cooler_count, road_count, start_index, goal_index; while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index, city_count) { // input vector<int> is_cooler(city_count, false); REP(i, cooler_count) { int cooler_index; cin >> cooler_index; is_cooler[cooler_index] = true; } vector<vector<Edge>> roads(city_count); REP(i, road_count) { int from, to, cost; cin >> from >> to >> cost; roads[from].push_back({to, cost}); roads[to].push_back({from, cost}); } // dijkstra vector<vector<int>> d( city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost d[start_index][initial_life] = 0; priority_queue<Node, vector<Node>, greater<Node>> pq; pq.push({start_index, 0, initial_life, 0}); while (true) { if (pq.empty()) { cout << "Help!" << endl; break; } auto current_node = pq.top(); pq.pop(); if (current_node.city_index == goal_index) { cout << current_node.total_cost << endl; break; } for (auto &road : roads[current_node.city_index]) { int total_cost = current_node.total_cost + road.cost; int life = current_node.current_life - road.cost; int remain_can_regain = is_cooler[current_node.city_index] ? initial_life - current_node.current_life : current_node.remain_can_regain; if (life < 0) { int shortage = -life; remain_can_regain -= shortage; if (remain_can_regain < 0) { continue; } total_cost += shortage; life = 0; } REP(i, remain_can_regain + 1) { auto &di = d[road.to][life + i]; if (total_cost < di) { di = total_cost + i; pq.push({road.to, total_cost + i, life + i, remain_can_regain - i}); break; } } } } } return 0; }
#include <algorithm> #include <climits> #include <functional> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) struct Edge { int to; int cost; }; struct Node { int city_index; int total_cost; int current_life; int remain_can_regain; bool operator>(const Node &a) const { return total_cost > a.total_cost; } }; int main() { int city_count, initial_life, cooler_count, road_count, start_index, goal_index; while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index, city_count) { // input vector<int> is_cooler(city_count, false); REP(i, cooler_count) { int cooler_index; cin >> cooler_index; is_cooler[cooler_index] = true; } vector<vector<Edge>> roads(city_count); REP(i, road_count) { int from, to, cost; cin >> from >> to >> cost; roads[from].push_back({to, cost}); roads[to].push_back({from, cost}); } // dijkstra vector<vector<int>> d( city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost d[start_index][initial_life] = 0; priority_queue<Node, vector<Node>, greater<Node>> pq; pq.push({start_index, 0, initial_life, 0}); while (true) { if (pq.empty()) { cout << "Help!" << endl; break; } auto current_node = pq.top(); pq.pop(); if (current_node.city_index == goal_index) { cout << current_node.total_cost << endl; break; } for (auto &road : roads[current_node.city_index]) { int total_cost = current_node.total_cost + road.cost; int life = current_node.current_life - road.cost; int remain_can_regain = is_cooler[current_node.city_index] ? initial_life - current_node.current_life : current_node.remain_can_regain; if (life < 0) { int shortage = -life; remain_can_regain -= shortage; if (remain_can_regain < 0) { continue; } total_cost += shortage; life = 0; } REP(i, remain_can_regain + 1) { auto &di = d[road.to][life + i]; if (total_cost + i < di) { di = total_cost + i; pq.push({road.to, total_cost + i, life + i, remain_can_regain - i}); break; } } } } } return 0; }
replace
84
85
84
85
0
p01146
C++
Runtime Error
#include <algorithm> #include <climits> #include <functional> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) struct Edge { int to; int cost; }; struct Node { int city_index; int total_cost; int current_life; int remain_can_regain; bool operator>(const Node &a) const { return total_cost > a.total_cost; } }; int main() { int city_count, initial_life, cooler_count, road_count, start_index, goal_index; while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index, city_count) { // input vector<int> is_cooler(city_count, false); REP(i, cooler_count) { int cooler_index; cin >> cooler_index; is_cooler[cooler_index] = true; } vector<vector<Edge>> roads(city_count); REP(i, road_count) { int from, to, cost; cin >> from >> to >> cost; roads[from].push_back({to, cost}); roads[to].push_back({from, cost}); } // dijkstra vector<vector<int>> d( city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost d[start_index][initial_life] = 0; priority_queue<Node, vector<Node>, greater<Node>> pq; pq.push({start_index, 0, initial_life, 0}); while (true) { if (pq.empty()) { cout << "Help!" << endl; break; } auto current_node = pq.top(); pq.pop(); if (current_node.city_index == goal_index) { cout << current_node.total_cost << endl; break; } for (auto &road : roads[current_node.city_index]) { int total_cost = current_node.total_cost + road.cost; int life = current_node.current_life - road.cost; int remain_can_regain = is_cooler[current_node.city_index] ? initial_life - current_node.current_life : current_node.remain_can_regain; if (life < 0) { int shortage = -life; remain_can_regain -= shortage; if (remain_can_regain < 0) { continue; } total_cost += shortage; life = 0; } /*auto &di = d[road.to][life]; if (total_cost < di) { di = total_cost;*/ pq.push({road.to, total_cost, life, remain_can_regain}); //} } } } return 0; }
#include <algorithm> #include <climits> #include <functional> #include <iostream> #include <queue> #include <set> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) struct Edge { int to; int cost; }; struct Node { int city_index; int total_cost; int current_life; int remain_can_regain; bool operator>(const Node &a) const { return total_cost > a.total_cost; } }; int main() { int city_count, initial_life, cooler_count, road_count, start_index, goal_index; while (cin >> city_count >> initial_life >> cooler_count >> road_count >> start_index >> goal_index, city_count) { // input vector<int> is_cooler(city_count, false); REP(i, cooler_count) { int cooler_index; cin >> cooler_index; is_cooler[cooler_index] = true; } vector<vector<Edge>> roads(city_count); REP(i, road_count) { int from, to, cost; cin >> from >> to >> cost; roads[from].push_back({to, cost}); roads[to].push_back({from, cost}); } // dijkstra vector<vector<int>> d( city_count, vector<int>(initial_life + 1, INT_MAX)); // [city_index][current_life] => total_cost d[start_index][initial_life] = 0; priority_queue<Node, vector<Node>, greater<Node>> pq; pq.push({start_index, 0, initial_life, 0}); while (true) { if (pq.empty()) { cout << "Help!" << endl; break; } auto current_node = pq.top(); pq.pop(); if (current_node.city_index == goal_index) { cout << current_node.total_cost << endl; break; } for (auto &road : roads[current_node.city_index]) { int total_cost = current_node.total_cost + road.cost; int life = current_node.current_life - road.cost; int remain_can_regain = is_cooler[current_node.city_index] ? initial_life - current_node.current_life : current_node.remain_can_regain; if (life < 0) { int shortage = -life; remain_can_regain -= shortage; if (remain_can_regain < 0) { continue; } total_cost += shortage; life = 0; } auto &di = d[road.to][remain_can_regain]; if (total_cost < di) { di = total_cost; pq.push({road.to, total_cost, life, remain_can_regain}); } } } } return 0; }
replace
82
88
82
87
0
p01147
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long LL; #define SORT(c) sort((c).begin(), (c).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; vector<string> uvs; pair<int, string> solve(void) { string answer = ""; for (string &s : uvs) { int ol = min(answer.size(), s.size()); for (; ol > 0; --ol) { bool flag = true; REP(i, ol) if (answer[answer.size() - ol + i] != s[i]) { flag = false; break; } if (flag) break; } answer += string(s.begin() + ol, s.end()); } return make_pair(answer.size(), answer); } int main(void) { for (;;) { int n; cin >> n; if (!n) return 0; vector<pair<int, string>> vs(n); uvs.clear(); REP(i, n) { string s; cin >> s; vs[i] = make_pair(-(int)s.size(), s); } SORT(vs); REP(i, n) { bool flag = true; REP(j, i) REP(k, vs[i].first - vs[j].first) { string tmp = vs[j].second; string r(tmp.begin() + k, tmp.begin() + k - vs[i].first); if (vs[i].second == r) flag = false; } if (flag) uvs.push_back(vs[i].second); } SORT(uvs); pair<int, string> answer(1000, ""); do { answer = min(answer, solve()); } while (next_permutation(uvs.begin(), uvs.end())); cout << answer.second << endl; } }
#include <bits/stdc++.h> typedef long long LL; #define SORT(c) sort((c).begin(), (c).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) using namespace std; vector<string> uvs; pair<int, string> solve(void) { string answer = ""; for (string &s : uvs) { int ol = min(answer.size(), s.size()); for (; ol > 0; --ol) { bool flag = true; REP(i, ol) if (answer[answer.size() - ol + i] != s[i]) { flag = false; break; } if (flag) break; } for (auto i = s.begin() + ol; i != s.end(); ++i) answer.push_back(*i); } return make_pair(answer.size(), answer); } int main(void) { for (;;) { int n; cin >> n; if (!n) return 0; vector<pair<int, string>> vs(n); uvs.clear(); REP(i, n) { string s; cin >> s; vs[i] = make_pair(-(int)s.size(), s); } SORT(vs); REP(i, n) { bool flag = true; REP(j, i) REP(k, vs[i].first - vs[j].first) { string tmp = vs[j].second; string r(tmp.begin() + k, tmp.begin() + k - vs[i].first); if (vs[i].second == r) flag = false; } if (flag) uvs.push_back(vs[i].second); } SORT(uvs); pair<int, string> answer(1000, ""); do { answer = min(answer, solve()); } while (next_permutation(uvs.begin(), uvs.end())); cout << answer.second << endl; } }
replace
22
23
22
24
TLE
p01150
C++
Time Limit Exceeded
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; int sum = 0; vector<int> solve(bitset<13> &used, vector<int> &nums) { if (used.count() == 13) { return vector<int>{-1}; } else { for (int i = 0; i < 13; ++i) { if (!used[i]) { if (sum % (i + 1) == 0) { sum += (i + 1) * nums[i]; used[i] = true; auto v(solve(used, nums)); if (!v.empty()) { if (v == vector<int>{-1}) { v.clear(); } for (int j = 0; j < nums[i]; ++j) { v.push_back(i); } return v; } used[i] = false; sum -= (i + 1) * nums[i]; } } } return vector<int>(); } } int main() { while (true) { sum = 0; int N; cin >> N; if (N % 2) { long long int dp[100][2][2][9]; for (int i = 0; i < 100; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { for (int n = 0; n < 9; ++n) { dp[i][j][k][n] = 0; } } } } for (int luse = 0; luse < 2; ++luse) { dp[0][luse][luse][luse] = 1; } for (int h = 0; h < N - 1; ++h) { for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { for (int cnt = 0; cnt <= 8; ++cnt) { const long long int num = dp[h][fst_luse][pre_luse][cnt]; for (int next_luse = 0; next_luse < 2; ++next_luse) { const int next_cnt = cnt + next_luse; if (next_cnt > 8) continue; const int next_h = h + 1; if (pre_luse && next_luse) continue; if (next_h == N - 1) { if (fst_luse && next_luse) continue; } dp[next_h][fst_luse][next_luse][next_cnt] += num; } } } } } long long int ans = 0; { int h = N - 1; for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { { int cnt = 8; const long long int num = dp[h][fst_luse][pre_luse][cnt]; ans += num; } } } } ans *= 40320; cout << ans << endl; } else { long long int dp[100][2][2][2][2][9]; for (int i = 0; i < 100; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { for (int l = 0; l < 2; ++l) { for (int m = 0; m < 2; ++m) { for (int n = 0; n < 9; ++n) { dp[i][j][k][l][m][n] = 0; } } } } } } for (int luse = 0; luse < 2; ++luse) { for (int ruse = 0; ruse < 2; ++ruse) { if (luse && ruse) continue; dp[0][luse][ruse][luse][ruse][luse + ruse] = 1; } } for (int h = 0; h < N / 2 - 1; ++h) { for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int fst_ruse = 0; fst_ruse < 2; ++fst_ruse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { for (int pre_ruse = 0; pre_ruse < 2; ++pre_ruse) { for (int cnt = 0; cnt <= 8; ++cnt) { const long long int num = dp[h][fst_luse][fst_ruse][pre_luse][pre_ruse][cnt]; for (int next_luse = 0; next_luse < 2; ++next_luse) { for (int next_ruse = 0; next_ruse < 2; ++next_ruse) { const int next_cnt = cnt + next_luse + next_ruse; if (next_cnt > 8) continue; const int next_h = h + 1; if (pre_luse && next_ruse) continue; if (pre_ruse && next_luse) continue; if (next_luse && next_ruse) continue; if (next_h == N / 2 - 1) { if (fst_luse && next_luse) continue; if (fst_ruse && next_ruse) continue; } dp[next_h][fst_luse][fst_ruse][next_luse][next_ruse] [next_cnt] += num; } } } } } } } } long long int ans = 0; { int h = N / 2 - 1; for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int fst_ruse = 0; fst_ruse < 2; ++fst_ruse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { for (int pre_ruse = 0; pre_ruse < 2; ++pre_ruse) { { int cnt = 8; const long long int num = dp[h][fst_luse][fst_ruse][pre_luse][pre_ruse][cnt]; ans += num; } } } } } } ans *= 40320; cout << ans << endl; } } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; int sum = 0; vector<int> solve(bitset<13> &used, vector<int> &nums) { if (used.count() == 13) { return vector<int>{-1}; } else { for (int i = 0; i < 13; ++i) { if (!used[i]) { if (sum % (i + 1) == 0) { sum += (i + 1) * nums[i]; used[i] = true; auto v(solve(used, nums)); if (!v.empty()) { if (v == vector<int>{-1}) { v.clear(); } for (int j = 0; j < nums[i]; ++j) { v.push_back(i); } return v; } used[i] = false; sum -= (i + 1) * nums[i]; } } } return vector<int>(); } } int main() { while (true) { sum = 0; int N; cin >> N; if (!N) break; if (N % 2) { long long int dp[100][2][2][9]; for (int i = 0; i < 100; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { for (int n = 0; n < 9; ++n) { dp[i][j][k][n] = 0; } } } } for (int luse = 0; luse < 2; ++luse) { dp[0][luse][luse][luse] = 1; } for (int h = 0; h < N - 1; ++h) { for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { for (int cnt = 0; cnt <= 8; ++cnt) { const long long int num = dp[h][fst_luse][pre_luse][cnt]; for (int next_luse = 0; next_luse < 2; ++next_luse) { const int next_cnt = cnt + next_luse; if (next_cnt > 8) continue; const int next_h = h + 1; if (pre_luse && next_luse) continue; if (next_h == N - 1) { if (fst_luse && next_luse) continue; } dp[next_h][fst_luse][next_luse][next_cnt] += num; } } } } } long long int ans = 0; { int h = N - 1; for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { { int cnt = 8; const long long int num = dp[h][fst_luse][pre_luse][cnt]; ans += num; } } } } ans *= 40320; cout << ans << endl; } else { long long int dp[100][2][2][2][2][9]; for (int i = 0; i < 100; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { for (int l = 0; l < 2; ++l) { for (int m = 0; m < 2; ++m) { for (int n = 0; n < 9; ++n) { dp[i][j][k][l][m][n] = 0; } } } } } } for (int luse = 0; luse < 2; ++luse) { for (int ruse = 0; ruse < 2; ++ruse) { if (luse && ruse) continue; dp[0][luse][ruse][luse][ruse][luse + ruse] = 1; } } for (int h = 0; h < N / 2 - 1; ++h) { for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int fst_ruse = 0; fst_ruse < 2; ++fst_ruse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { for (int pre_ruse = 0; pre_ruse < 2; ++pre_ruse) { for (int cnt = 0; cnt <= 8; ++cnt) { const long long int num = dp[h][fst_luse][fst_ruse][pre_luse][pre_ruse][cnt]; for (int next_luse = 0; next_luse < 2; ++next_luse) { for (int next_ruse = 0; next_ruse < 2; ++next_ruse) { const int next_cnt = cnt + next_luse + next_ruse; if (next_cnt > 8) continue; const int next_h = h + 1; if (pre_luse && next_ruse) continue; if (pre_ruse && next_luse) continue; if (next_luse && next_ruse) continue; if (next_h == N / 2 - 1) { if (fst_luse && next_luse) continue; if (fst_ruse && next_ruse) continue; } dp[next_h][fst_luse][fst_ruse][next_luse][next_ruse] [next_cnt] += num; } } } } } } } } long long int ans = 0; { int h = N / 2 - 1; for (int fst_luse = 0; fst_luse < 2; ++fst_luse) { for (int fst_ruse = 0; fst_ruse < 2; ++fst_ruse) { for (int pre_luse = 0; pre_luse < 2; ++pre_luse) { for (int pre_ruse = 0; pre_ruse < 2; ++pre_ruse) { { int cnt = 8; const long long int num = dp[h][fst_luse][fst_ruse][pre_luse][pre_ruse][cnt]; ans += num; } } } } } } ans *= 40320; cout << ans << endl; } } return 0; }
insert
43
43
43
45
TLE
p01153
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int n, a[107], dp[107][107], K[107][107]; int main() { int t; cin >> t; for (int p = 0; p < t; p++) { for (int i = 0; i < 11449; i++) dp[i / 107][i % 107] = 0; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) cin >> a[i]; int maxn = 0; for (int u = 0; u < n; u++) { int G = a[0]; for (int v = 1; v < n; v++) a[v - 1] = a[v]; a[n - 1] = G; for (int v = 0; v < 11449; v++) dp[v / 107][v % 107] = 0; for (int v = 0; v < n; v++) { for (int w = 0; w < n; w++) K[v][w] = abs(a[v] - a[w]); } for (int v = 0; v < 8; v++) { for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = i; k < j; k++) { dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j] + K[i][k + 1]); } } } } maxn = max(maxn, dp[0][n - 1]); } cout << maxn << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int n, a[107], dp[107][107], K[107][107]; int main() { int t; cin >> t; for (int p = 0; p < t; p++) { for (int i = 0; i < 11449; i++) dp[i / 107][i % 107] = 0; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) cin >> a[i]; int maxn = 0; for (int u = 0; u < n; u++) { int G = a[0]; for (int v = 1; v < n; v++) a[v - 1] = a[v]; a[n - 1] = G; for (int v = 0; v < 11449; v++) dp[v / 107][v % 107] = 0; for (int v = 0; v < n; v++) { for (int w = 0; w < n; w++) K[v][w] = abs(a[v] - a[w]); } for (int v = 1; v <= n; v++) { for (int w = 0; w < n; w++) { int I = w, J = v + w; if (I >= J || J >= n) continue; for (int k = I; k < J; k++) { dp[I][J] = max(dp[I][J], dp[I][k] + dp[k + 1][J] + K[I][k + 1]); } } } maxn = max(maxn, dp[0][n - 1]); } cout << maxn << endl; } return 0; }
replace
28
34
28
35
TLE
p01156
C++
Runtime Error
#include <iostream> #include <string> using namespace std; string S[15] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"}; int N, a[10000], c[15]; string T; bool solve(int a, int b) { if (a > b) b += 15; if (b - a <= 7) return true; return false; } int main() { while (true) { cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) { cin >> T; for (int j = 0; j < 15; j++) { if (T == S[j]) a[i] = j; } } for (int i = 0; i < 15; i++) c[i] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (!solve(a[i], a[j])) goto E; } c[a[i]] = 1; E:; } int G = 0; for (int i = 0; i < N - 1; i++) { if (S[i] != S[i + 1]) G = 1; } int P = 0; if (G == 0) goto F; for (int i = 0; i < 15; i++) { if (c[i] == 1) { P = 1; cout << S[i] << endl; } } F:; if (P == 0) cout << "Draw" << endl; } return 0; }
#include <iostream> #include <string> using namespace std; string S[15] = {"Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun"}; int N, a[10000], c[15]; string T; bool solve(int a, int b) { if (a > b) b += 15; if (b - a <= 7) return true; return false; } int main() { while (true) { cin >> N; if (N == 0) break; for (int i = 0; i < N; i++) { cin >> T; for (int j = 0; j < 15; j++) { if (T == S[j]) a[i] = j; } } for (int i = 0; i < 15; i++) c[i] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (!solve(a[i], a[j])) goto E; } c[a[i]] = 1; E:; } int G = 0; for (int i = 0; i < N - 1; i++) { if (a[i] != a[i + 1]) G = 1; } int P = 0; if (G == 0) goto F; for (int i = 0; i < 15; i++) { if (c[i] == 1) { P = 1; cout << S[i] << endl; } } F:; if (P == 0) cout << "Draw" << endl; } return 0; }
replace
39
40
39
40
0
p01160
C++
Memory Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int X[3001][3001]; int Y[3001][3001]; string lcs(string a, string b) { int n = a.size(); int m = b.size(); for (int i = 0; i < n + 1; i++) { for (int j = 0; j < m + 1; j++) { X[i][j] = 0; Y[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] == b[j]) { X[i + 1][j + 1] = X[i][j] + 1; Y[i + 1][j + 1] = 0; } else if (X[i + 1][j] < X[i][j + 1]) { X[i + 1][j + 1] = X[i][j + 1]; Y[i + 1][j + 1] = +1; } else { X[i + 1][j + 1] = X[i + 1][j]; Y[i + 1][j + 1] = -1; } } } string answer; for (int i = n, j = m; i > 0 && j > 0;) { if (Y[i][j] > 0) { i--; } else if (Y[i][j] < 0) { j--; } else { answer += a[i - 1]; i--; j--; } } reverse(answer.begin(), answer.end()); return answer; } int main() { string input; while (cin >> input) { string a = input; string b = input; reverse(b.begin(), b.end()); string answer = lcs(a, b); cout << answer << endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; short X[3001][3001]; short Y[3001][3001]; string lcs(string a, string b) { int n = a.size(); int m = b.size(); for (int i = 0; i < n + 1; i++) { for (int j = 0; j < m + 1; j++) { X[i][j] = 0; Y[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i] == b[j]) { X[i + 1][j + 1] = X[i][j] + 1; Y[i + 1][j + 1] = 0; } else if (X[i + 1][j] < X[i][j + 1]) { X[i + 1][j + 1] = X[i][j + 1]; Y[i + 1][j + 1] = +1; } else { X[i + 1][j + 1] = X[i + 1][j]; Y[i + 1][j + 1] = -1; } } } string answer; for (int i = n, j = m; i > 0 && j > 0;) { if (Y[i][j] > 0) { i--; } else if (Y[i][j] < 0) { j--; } else { answer += a[i - 1]; i--; j--; } } reverse(answer.begin(), answer.end()); return answer; } int main() { string input; while (cin >> input) { string a = input; string b = input; reverse(b.begin(), b.end()); string answer = lcs(a, b); cout << answer << endl; } return 0; }
replace
6
8
6
8
MLE
p01160
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; string s, t; int dp[1011][1011]; int used[1011][1011]; string solve() { string ans = ""; int i = s.size() - 1; int j = t.size() - 1; while (i > 0 && j > 0) { if (used[i][j] == 1) ans += t[j], i--, j--; else if (used[i][j] == 2) i--; else j--; } return ans; } int main() { while (cin >> s) { memset(dp, 0, sizeof(dp)); memset(used, 0, sizeof(used)); t = s; reverse(s.begin(), s.end()); t = "@" + t; s = "@" + s; for (int i = 1; i < s.size(); i++) for (int j = 1; j < t.size(); j++) if (s[i] == t[j]) { if (dp[i - 1][j] >= dp[i - 1][j - 1] + 1) dp[i][j] = max(dp[i][j], dp[i - 1][j]), used[i][j] = 2; else dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1), used[i][j] = 1; } else { if (dp[i - 1][j] >= dp[i][j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j]), used[i][j] = 2; else dp[i][j] = max(dp[i][j], dp[i][j - 1]), used[i][j] = 3; } cout << solve() << endl; } }
#include <bits/stdc++.h> using namespace std; string s, t; int dp[2011][2011]; int used[2011][2011]; string solve() { string ans = ""; int i = s.size() - 1; int j = t.size() - 1; while (i > 0 && j > 0) { if (used[i][j] == 1) ans += t[j], i--, j--; else if (used[i][j] == 2) i--; else j--; } return ans; } int main() { while (cin >> s) { memset(dp, 0, sizeof(dp)); memset(used, 0, sizeof(used)); t = s; reverse(s.begin(), s.end()); t = "@" + t; s = "@" + s; for (int i = 1; i < s.size(); i++) for (int j = 1; j < t.size(); j++) if (s[i] == t[j]) { if (dp[i - 1][j] >= dp[i - 1][j - 1] + 1) dp[i][j] = max(dp[i][j], dp[i - 1][j]), used[i][j] = 2; else dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1), used[i][j] = 1; } else { if (dp[i - 1][j] >= dp[i][j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j]), used[i][j] = 2; else dp[i][j] = max(dp[i][j], dp[i][j - 1]), used[i][j] = 3; } cout << solve() << endl; } }
replace
3
5
3
5
0
p01160
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 2050 string ss[2][N + 1]; int c[N + 1][N + 1]; string lcs(string X, string Y) { int m = X.size(); int n = Y.size(); int maxl = 0; X = ' ' + X; Y = ' ' + Y; ss[0][0] = ""; memset(c, 0, sizeof(c)); for (int i = 0; i <= m; i++) c[i][0] = 0; for (int j = 1; j <= n; j++) c[0][j] = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (X[i] == Y[j]) c[i][j] = c[i - 1][j - 1] + 1, ss[i % 2][j] = ss[(i - 1) % 2][j - 1] + X[i]; else { if (c[i - 1][j] >= c[i][j - 1]) c[i][j] = c[i - 1][j], ss[i % 2][j] = ss[(i - 1) % 2][j]; else c[i][j] = c[i][j - 1], ss[i % 2][j] = ss[i % 2][j - 1]; } maxl = max(maxl, c[i][j]); } } string ret = ss[m % 2][n], ret2 = ret; reverse(ret2.begin(), ret2.end()); // assert(ret==ret2); assert((int)ret.size() == maxl); return ss[m % 2][n]; } int main() { string s; while (cin >> s) { string t = s; reverse(t.begin(), t.end()); cout << lcs(s, t) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define N 2050 string ss[2][N + 1]; int c[N + 1][N + 1]; string lcs(string X, string Y) { int m = X.size(); int n = Y.size(); int maxl = 0; X = ' ' + X; Y = ' ' + Y; ss[0][0] = ""; memset(c, 0, sizeof(c)); for (int i = 0; i < N + 1; i++) ss[0][i] = ss[1][i] = ""; for (int i = 0; i <= m; i++) c[i][0] = 0; for (int j = 1; j <= n; j++) c[0][j] = 0; for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (X[i] == Y[j]) c[i][j] = c[i - 1][j - 1] + 1, ss[i % 2][j] = ss[(i - 1) % 2][j - 1] + X[i]; else { if (c[i - 1][j] >= c[i][j - 1]) c[i][j] = c[i - 1][j], ss[i % 2][j] = ss[(i - 1) % 2][j]; else c[i][j] = c[i][j - 1], ss[i % 2][j] = ss[i % 2][j - 1]; } maxl = max(maxl, c[i][j]); } } string ret = ss[m % 2][n], ret2 = ret; reverse(ret2.begin(), ret2.end()); // assert(ret==ret2); assert((int)ret.size() == maxl); return ss[m % 2][n]; } int main() { string s; while (cin >> s) { string t = s; reverse(t.begin(), t.end()); cout << lcs(s, t) << endl; } return 0; }
insert
13
13
13
15
0
p01163
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr, __VA_ARGS__) // #define LOG(...) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SQ(n) (n) * (n) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int primes[3000]; int siz = 0; int num[40000] = {0}; bool isprime[200000] = {false}; int main() { for (int i = 2; i < 20000; i++) { if (isprime[i]) continue; primes[siz++] = i; for (int j = i * 2; j < 20000; j += i) { isprime[j] = true; } } for (int a = 0; primes[a] <= 15000; a++) { for (int b = a; primes[b] <= 15000; b++) { for (int c = b; primes[c] <= 15000; c++) { if (primes[a] + primes[b] <= primes[c]) continue; num[primes[a] + primes[b] + primes[c]]++; // LOG("%d %d %d\n",primes[a],primes[b],primes[c]); } } } // cout << "end works" << endl; int T; while (cin >> T, T) { cout << num[T] << endl; } }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr, __VA_ARGS__) // #define LOG(...) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SQ(n) (n) * (n) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int primes[3000]; int siz = 0; int num[40000] = {0}; bool isprime[200000] = {false}; int main() { for (int i = 2; i < 20000; i++) { if (isprime[i]) continue; primes[siz++] = i; for (int j = i * 2; j < 20000; j += i) { isprime[j] = true; } } for (int a = 0; primes[a] <= 15000; a++) { for (int b = a; primes[b] <= 15000; b++) { for (int c = b; primes[c] <= 15000; c++) { if (primes[a] + primes[b] <= primes[c]) continue; if (primes[a] + primes[b] + primes[c] > 30000) continue; num[primes[a] + primes[b] + primes[c]]++; // LOG("%d %d %d\n",primes[a],primes[b],primes[c]); } } } // cout << "end works" << endl; int T; while (cin >> T, T) { cout << num[T] << endl; } }
insert
62
62
62
64
TLE
p01163
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; const int MAX = 30000; int main() { vector<int> pr; bool p[MAX + 1] = {false}; for (int i = 2; i <= MAX; i++) p[i] = 1; for (int i = 2; i * i <= MAX; i++) if (p[i]) for (int k = i + i; k <= MAX; k += i) p[k] = 0; for (int i = 2; i <= MAX; i++) if (p[i]) pr.push_back(i); int N; while (cin >> N, N) { int cnt = 0; for (int i = 0; i < pr.size(); i++) for (int j = i; j < pr.size() && pr[i] + pr[j] <= N; j++) for (int k = j; k < pr.size() && pr[i] + pr[j] + pr[k] <= N; k++) if (pr[i] + pr[j] + pr[k] == N && pr[i] + pr[j] > pr[k]) cnt++; cout << cnt << endl; } }
#include <iostream> #include <vector> using namespace std; const int MAX = 30000; int main() { vector<int> pr; bool p[MAX + 1] = {false}; for (int i = 2; i <= MAX; i++) p[i] = 1; for (int i = 2; i * i <= MAX; i++) if (p[i]) for (int k = i + i; k <= MAX; k += i) p[k] = 0; for (int i = 2; i <= MAX; i++) if (p[i]) pr.push_back(i); int N; while (cin >> N, N) { int cnt = 0; for (int i = 0; i < pr.size(); i++) for (int j = i; j < pr.size() && pr[i] + pr[j] <= N; j++) { int k = N - pr[i] - pr[j]; if (!p[k]) continue; if (pr[j] > k) continue; if (pr[i] + pr[j] > k) cnt++; } cout << cnt << endl; } }
replace
24
28
24
33
TLE
p01163
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; int tx[] = {0, 1, 0, -1}; int ty[] = {-1, 0, 1, 0}; static const double EPS = 1e-8; bool is_prime[30001]; int main() { int side_sum; memset(is_prime, true, sizeof(is_prime)); is_prime[0] = false; is_prime[1] = false; vector<int> prime; for (int i = 0; i <= 30000; i++) { if (!is_prime[i]) continue; prime.push_back(i); for (int j = i + i; j <= 30000; j += i) { is_prime[j] = false; } } while (~scanf("%d", &side_sum)) { if (side_sum == 0) break; int res = 0; map<vector<int>, bool> visited; for (int prime_i = 0; prime_i < prime.size(); prime_i++) { int center_side = prime[prime_i]; if (2 * center_side >= side_sum) break; int remainings = side_sum - center_side; if (remainings <= 0) break; for (int prime_j = 0; prime_j < prime.size(); prime_j++) { int left_side = prime[prime_j]; int right_side = remainings - left_side; if (right_side <= 0) continue; if (!is_prime[right_side]) continue; vector<int> used; used.push_back(center_side); used.push_back(left_side); used.push_back(right_side); sort(used.begin(), used.end()); if (used[0] + used[1] <= used[2]) continue; if (visited.find(used) != visited.end()) continue; visited[used] = true; res++; } } printf("%d\n", res); } }
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; int tx[] = {0, 1, 0, -1}; int ty[] = {-1, 0, 1, 0}; static const double EPS = 1e-8; bool is_prime[30001]; int main() { int side_sum; memset(is_prime, true, sizeof(is_prime)); is_prime[0] = false; is_prime[1] = false; vector<int> prime; for (int i = 0; i <= 30000; i++) { if (!is_prime[i]) continue; prime.push_back(i); for (int j = i + i; j <= 30000; j += i) { is_prime[j] = false; } } while (~scanf("%d", &side_sum)) { if (side_sum == 0) break; int res = 0; map<vector<int>, bool> visited; for (int prime_i = 0; prime_i < prime.size(); prime_i++) { int center_side = prime[prime_i]; if (2 * center_side >= side_sum) break; int remainings = side_sum - center_side; if (remainings <= 0) break; for (int prime_j = 0; prime_j < prime.size(); prime_j++) { int left_side = prime[prime_j]; int right_side = remainings - left_side; if (right_side <= 0) continue; if (!is_prime[right_side]) continue; if (left_side > right_side) break; vector<int> used; used.push_back(center_side); used.push_back(left_side); used.push_back(right_side); sort(used.begin(), used.end()); if (used[0] + used[1] <= used[2]) continue; if (visited.find(used) != visited.end()) continue; visited[used] = true; res++; } } printf("%d\n", res); } }
insert
74
74
74
77
TLE
p01168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int m(int a, int k) { string s; while (a) { int tmp = a % k; if (tmp > 9) return -1; s += '0' + tmp; a /= k; } reverse(s.begin(), s.end()); return stoll(s); } signed main() { int a, b, c; while (cin >> a >> b >> c, ~a) { bool f = 1; for (int i = 2; i <= 16; i++) f &= m(a, i) != b; int res = b; for (int j = a; j <= c; j++) { int tmp = -1; for (int i = 2; i <= 16; i++) if (m(j, i) >= res) if (tmp < 0 || m(j, i) < tmp) tmp = m(j, i); if (tmp < 0) { f = 1; break; } res = tmp; } cout << (f ? -1 : res) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int m(int a, int k) { if (!a) return 0; string s; while (a) { int tmp = a % k; if (tmp > 9) return -1; s += '0' + tmp; a /= k; } reverse(s.begin(), s.end()); return stoll(s); } signed main() { int a, b, c; while (cin >> a >> b >> c, ~a) { bool f = 1; for (int i = 2; i <= 16; i++) f &= m(a, i) != b; int res = b; for (int j = a; j <= c; j++) { int tmp = -1; for (int i = 2; i <= 16; i++) if (m(j, i) >= res) if (tmp < 0 || m(j, i) < tmp) tmp = m(j, i); if (tmp < 0) { f = 1; break; } res = tmp; } cout << (f ? -1 : res) << endl; } return 0; }
insert
4
4
4
6
0
p01170
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; typedef complex<double> Point; namespace std { bool operator<(const Point &p1, const Point &p2) { if (p1.real() != p2.real()) return p1.real() < p2.real(); return p1.imag() < p2.imag(); } }; // namespace std struct Event { double y; Point p; int p_type; int e_type; Event(double y, Point p, int p_type, int e_type) : y(y), p(p), p_type(p_type), e_type(e_type) {} bool operator<(const Event &e) const { if (y != e.y) return y < e.y; if (e_type != e.e_type) return e_type > e.e_type; // delete is first ??? return p < e.p; } }; double get_time(Point p, Point q, double R, double v) { double dx = abs(p.real() - q.real()); double dy = abs(p.imag() - q.imag()); assert(2 * R >= dy); double b = sqrt(4 * R * R - dy * dy); assert(dx - b >= 0); return (dx - b) / v; } void update(double &ans, vector<Point> &pset, Point p, double R, double v, int t) { int k = lower_bound(pset.begin(), pset.end(), p) - pset.begin(); for (int dk = -1; dk <= 1; dk++) if (k + dk >= 0 && k + dk < pset.size()) { if (t == 0 && p.real() < pset[k + dk].real()) { ans = min(ans, get_time(p, pset[k + dk], R, v)); } else if (t == 1 && p.real() > pset[k + dk].real()) { ans = min(ans, get_time(p, pset[k + dk], R, v)); } } } int main() { int N; while (cin >> N && N) { double vx, vy; cin >> vx >> vy; vx *= 2; vy *= 2; double th = arg(Point(vx, vy)); double v = sqrt(vx * vx + vy * vy); double R; cin >> R; vector<Event> events; REP(i, N) { double x, y; int u; cin >> x >> y >> u; Point p(x, y); p = p * polar(1.0, -th); if (u == 1) { events.push_back(Event(p.imag() - R, p, 0, 0)); events.push_back(Event(p.imag() + R, p, 0, 1)); } else { events.push_back(Event(p.imag() - R, p, 1, 0)); events.push_back(Event(p.imag() + R, p, 1, 1)); } } sort(events.begin(), events.end()); vector<Point> point_set[2]; double ans = 1e16; for (int i = 0; i < events.size(); i++) { Event e = events[i]; // cout << e.p << " " << e.e_type << " " << e.p_type << endl; vector<Point> &my_set = point_set[e.p_type]; vector<Point> &you_set = point_set[e.p_type ^ 1]; if (e.e_type == 0) { my_set.insert(lower_bound(my_set.begin(), my_set.end(), e.p), e.p); update(ans, you_set, e.p, R, v, e.p_type); } else if (e.e_type == 1) { my_set.erase(lower_bound(my_set.begin(), my_set.end(), e.p)); int k = lower_bound(you_set.begin(), you_set.end(), e.p) - you_set.begin(); for (int dk = -1; dk <= 1; dk++) if (k + dk >= 0 && k + dk < you_set.size()) { update(ans, my_set, you_set[k], R, v, e.p_type ^ 1); } } } if (ans >= 1e16) { puts("SAFE"); } else { printf("%.6f\n", ans); } } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (int)(n); ++i) using namespace std; typedef complex<double> Point; namespace std { bool operator<(const Point &p1, const Point &p2) { if (p1.real() != p2.real()) return p1.real() < p2.real(); return p1.imag() < p2.imag(); } }; // namespace std struct Event { double y; Point p; int p_type; int e_type; Event(double y, Point p, int p_type, int e_type) : y(y), p(p), p_type(p_type), e_type(e_type) {} bool operator<(const Event &e) const { if (y != e.y) return y < e.y; if (e_type != e.e_type) return e_type > e.e_type; // delete is first ??? return p < e.p; } }; double get_time(Point p, Point q, double R, double v) { double dx = abs(p.real() - q.real()); double dy = abs(p.imag() - q.imag()); if (!(2 * R >= dy)) return 1e16; assert(2 * R >= dy); double b = sqrt(4 * R * R - dy * dy); assert(dx - b >= 0); return (dx - b) / v; } void update(double &ans, vector<Point> &pset, Point p, double R, double v, int t) { int k = lower_bound(pset.begin(), pset.end(), p) - pset.begin(); for (int dk = -1; dk <= 1; dk++) if (k + dk >= 0 && k + dk < pset.size()) { if (t == 0 && p.real() < pset[k + dk].real()) { ans = min(ans, get_time(p, pset[k + dk], R, v)); } else if (t == 1 && p.real() > pset[k + dk].real()) { ans = min(ans, get_time(p, pset[k + dk], R, v)); } } } int main() { int N; while (cin >> N && N) { double vx, vy; cin >> vx >> vy; vx *= 2; vy *= 2; double th = arg(Point(vx, vy)); double v = sqrt(vx * vx + vy * vy); double R; cin >> R; vector<Event> events; REP(i, N) { double x, y; int u; cin >> x >> y >> u; Point p(x, y); p = p * polar(1.0, -th); if (u == 1) { events.push_back(Event(p.imag() - R, p, 0, 0)); events.push_back(Event(p.imag() + R, p, 0, 1)); } else { events.push_back(Event(p.imag() - R, p, 1, 0)); events.push_back(Event(p.imag() + R, p, 1, 1)); } } sort(events.begin(), events.end()); vector<Point> point_set[2]; double ans = 1e16; for (int i = 0; i < events.size(); i++) { Event e = events[i]; // cout << e.p << " " << e.e_type << " " << e.p_type << endl; vector<Point> &my_set = point_set[e.p_type]; vector<Point> &you_set = point_set[e.p_type ^ 1]; if (e.e_type == 0) { my_set.insert(lower_bound(my_set.begin(), my_set.end(), e.p), e.p); update(ans, you_set, e.p, R, v, e.p_type); } else if (e.e_type == 1) { my_set.erase(lower_bound(my_set.begin(), my_set.end(), e.p)); int k = lower_bound(you_set.begin(), you_set.end(), e.p) - you_set.begin(); for (int dk = -1; dk <= 1; dk++) if (k + dk >= 0 && k + dk < you_set.size()) { update(ans, my_set, you_set[k], R, v, e.p_type ^ 1); } } } if (ans >= 1e16) { puts("SAFE"); } else { printf("%.6f\n", ans); } } return 0; }
insert
32
32
32
34
0