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
p00424
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m, co[100] = {0}, i, j; char a[100] = {0}, b[100] = {0}, c[100] = {0}; while (1) { cin >> n; if (n == 0) { break; } for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; co[i] = 1; } cin >> m; for (j = 0; j < m; j++) { cin >> c[j]; for (i = 0; i < n; i++) { if (c[j] == a[i]) { c[j] = b[i]; co[i] = 0; break; } } } for (j = 0; j < m; j++) { cout << c[j]; } cout << endl; } return 0; }
#include <iostream> using namespace std; int main(void) { int n, m, co[1000] = {0}, i, j; char a[1000] = {0}, b[1000] = {0}, c[100011] = {0}; while (1) { cin >> n; if (n == 0) { break; } for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; co[i] = 1; } cin >> m; for (j = 0; j < m; j++) { cin >> c[j]; for (i = 0; i < n; i++) { if (c[j] == a[i]) { c[j] = b[i]; co[i] = 0; break; } } } for (j = 0; j < m; j++) { cout << c[j]; } cout << endl; } return 0; }
replace
2
5
2
5
0
p00424
C++
Runtime Error
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; ////////////////*My library*//////////////////////// #define rep_to(a, i, n) for (int i = a; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define rep_r(i, n) for (int i = n - 1; i >= 0; i--) #define debug(x) cout << x << endl #define s_1(x) cin >> x #define s_2(x, y) cin >> x >> y //////////////////////////////////////////////////// //////////////////////// /*prime()*/ /*primecount()*/ /*sort()*/ /*imos???*/ /*????????¢?´¢*/ /*??±???????????¢?´¢*/ /*???????¨???????*/ /////////////////////// int main() { int N, len; char str[10000][10] = {}; char s[10000] = {}; while (1) { s_1(N); if (N == 0) break; rep(i, N) cin >> str[i][0] >> str[i][1]; s_1(len); rep(i, len) { s_1(s[i]); rep(j, N) { if (str[j][0] == s[i]) { s[i] = str[j][1]; break; } } } rep(i, len) cout << s[i]; cout << endl; } return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <stack> #include <string> #include <vector> using namespace std; ////////////////*My library*//////////////////////// #define rep_to(a, i, n) for (int i = a; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define rep_r(i, n) for (int i = n - 1; i >= 0; i--) #define debug(x) cout << x << endl #define s_1(x) cin >> x #define s_2(x, y) cin >> x >> y //////////////////////////////////////////////////// //////////////////////// /*prime()*/ /*primecount()*/ /*sort()*/ /*imos???*/ /*????????¢?´¢*/ /*??±???????????¢?´¢*/ /*???????¨???????*/ /////////////////////// int main() { int N, len; char str[10000][10] = {}; char s[100000] = {}; while (1) { s_1(N); if (N == 0) break; rep(i, N) cin >> str[i][0] >> str[i][1]; s_1(len); rep(i, len) { s_1(s[i]); rep(j, N) { if (str[j][0] == s[i]) { s[i] = str[j][1]; break; } } } rep(i, len) cout << s[i]; cout << endl; } return 0; }
replace
33
34
33
34
0
p00424
C++
Runtime Error
#include <iostream> using namespace std; int main() { int i, j, n, x, l; char a[10000], b[10000], c[10000], m; while (true) { cin >> n; if (n == 0) { break; } for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } cin >> x; for (j = 0; j < x; j++) { cin >> c[j]; } for (l = 0; l < x; l++) { for (int k = 0; k < n; ++k) { if (c[l] == a[k]) { c[l] = b[k]; break; } } } for (int k = 0; k < x; ++k) { cout << c[k]; } cout << endl; } return 0; }
#include <iostream> using namespace std; int main() { int i, j, n, x, l; char a[100001], b[100001], c[100001], m; while (true) { cin >> n; if (n == 0) { break; } for (i = 0; i < n; i++) { cin >> a[i] >> b[i]; } cin >> x; for (j = 0; j < x; j++) { cin >> c[j]; } for (l = 0; l < x; l++) { for (int k = 0; k < n; ++k) { if (c[l] == a[k]) { c[l] = b[k]; break; } } } for (int k = 0; k < x; ++k) { cout << c[k]; } cout << endl; } return 0; }
replace
4
5
4
5
0
p00424
C++
Runtime Error
#include <iostream> using namespace std; int main() { for (;;) { char henkan[1000][2]; char str[1000]; int n, m; char temp; bool flg = 0; cin >> n; if (n == 0) { break; } for (int i = 0; i < n; i++) { cin >> henkan[i][0] >> henkan[i][1]; } /* for(int i = 0; i < n; i++){ cout << henkan[i][1] << endl; } */ cin >> m; for (int i = 0; i < m; i++) { cin >> str[i]; } for (int i = 0; i < m; i++) { flg = 0; for (int j = 0; j < n; j++) { if (str[i] == henkan[j][0]) { temp = henkan[j][1]; flg = 1; } } if (flg == 1) { printf("%c", temp); } else { printf("%c", str[i]); } } cout << endl; } }
#include <iostream> using namespace std; int main() { for (;;) { char henkan[100000][2]; char str[100000]; int n, m; char temp; bool flg = 0; cin >> n; if (n == 0) { break; } for (int i = 0; i < n; i++) { cin >> henkan[i][0] >> henkan[i][1]; } /* for(int i = 0; i < n; i++){ cout << henkan[i][1] << endl; } */ cin >> m; for (int i = 0; i < m; i++) { cin >> str[i]; } for (int i = 0; i < m; i++) { flg = 0; for (int j = 0; j < n; j++) { if (str[i] == henkan[j][0]) { temp = henkan[j][1]; flg = 1; } } if (flg == 1) { printf("%c", temp); } else { printf("%c", str[i]); } } cout << endl; } }
replace
6
8
6
8
0
p00424
C++
Runtime Error
#include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int n; while (cin >> n) { vector<vector<char>> c(n, vector<char>(2)); const int first = 0; const int second = 1; while (n--) { cin >> c[n][first] >> c[n][second]; } cin >> n; char in; string ans; while (n--) { cin >> in; for (int i = 0; i < c.size(); i++) { if (in == c[i][first]) { in = c[i][second]; break; } } ans += in; } cout << ans << endl; } }
#include <iostream> #include <string> #include <vector> using namespace std; int main(void) { int n; while (cin >> n, n) { vector<vector<char>> c(n, vector<char>(2)); const int first = 0; const int second = 1; while (n--) { cin >> c[n][first] >> c[n][second]; } cin >> n; char in; string ans; while (n--) { cin >> in; for (int i = 0; i < c.size(); i++) { if (in == c[i][first]) { in = c[i][second]; break; } } ans += in; } cout << ans << endl; } }
replace
7
8
7
8
TLE
p00424
C++
Time Limit Exceeded
#include <iostream> #include <map> using namespace std; int main() { int n; char a, b; map<char, char> list; map<char, char>::iterator it; while (1) { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; list.insert(pair<char, char>(a, b)); } cin >> n; for (int i = 0; i < n; i++) { cin >> a; it = list.find(a); if (it == list.end()) { cout << a; } else { cout << (*it).second; } } cout << endl; list.clear(); } return 0; }
#include <iostream> #include <map> using namespace std; int main() { int n; char a, b; map<char, char> list; map<char, char>::iterator it; while (1) { cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> a >> b; list.insert(pair<char, char>(a, b)); } cin >> n; for (int i = 0; i < n; i++) { cin >> a; it = list.find(a); if (it == list.end()) { cout << a; } else { cout << (*it).second; } } cout << endl; list.clear(); } return 0; }
insert
11
11
11
13
TLE
p00424
C++
Runtime Error
#include <stdio.h> char hantei(char); int n; char chana[1000000000], chanb[1000000000]; int main() { int i, j, m; char w; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { scanf(" %c %c", &chana[i], &chanb[i]); } scanf("%d", &m); for (j = 0; j < m; j++) { scanf(" %c", &w); printf("%c", hantei(w)); } printf("\n"); } return 0; } char hantei(char w) { int i; for (i = 0; i < n; i++) { if (w == chana[i]) return chanb[i]; } return w; }
#include <stdio.h> char hantei(char); int n; char chana[1000], chanb[1000]; int main() { int i, j, m; char w; while (1) { scanf("%d", &n); if (n == 0) break; for (i = 0; i < n; i++) { scanf(" %c %c", &chana[i], &chanb[i]); } scanf("%d", &m); for (j = 0; j < m; j++) { scanf(" %c", &w); printf("%c", hantei(w)); } printf("\n"); } return 0; } char hantei(char w) { int i; for (i = 0; i < n; i++) { if (w == chana[i]) return chanb[i]; } return w; }
replace
4
5
4
5
-11
p00424
C++
Runtime Error
#include <stdio.h> int main() { int n, i, j, m, f; char a[256], b[256], x; while (1) { scanf("%d ", &n); if (n == 0) { break; } for (i = 0; i < n; i++) { scanf("%c %c ", &a[i], &b[i]); } scanf("%d ", &m); for (i = 0; i < m; i++) { scanf("%s", &x); f = 0; for (j = 0; j < n; j++) { if (x == a[j]) { printf("%c", b[j]); f = 1; break; } } if (f == 0) { printf("%s", x); } } printf("\n"); } return 0; }
#include <stdio.h> int main() { int n, i, j, m, f; char a[256], b[256], x; while (1) { scanf("%d ", &n); if (n == 0) { break; } for (i = 0; i < n; i++) { scanf("%c %c ", &a[i], &b[i]); } scanf("%d ", &m); for (i = 0; i < m; i++) { scanf("%s", &x); f = 0; for (j = 0; j < n; j++) { if (x == a[j]) { printf("%c", b[j]); f = 1; break; } } if (f == 0) { printf("%c", x); } } printf("\n"); } return 0; }
replace
26
27
26
27
-11
p00424
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { while (1) { int m, n; char cha[10000], con[10000], a[10000]; cin >> m; if (m == 0) break; for (int i = 0; i < m; i++) { cin >> cha[i] >> con[i]; } cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = 0; j < m; j++) { if (a[i] == cha[j]) { a[i] = con[j]; break; } } } for (int i = 0; i < n; i++) { cout << a[i]; } cout << "\n"; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { while (1) { int m, n; char cha[100000], con[100000], a[100000]; cin >> m; if (m == 0) break; for (int i = 0; i < m; i++) { cin >> cha[i] >> con[i]; } cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; for (int j = 0; j < m; j++) { if (a[i] == cha[j]) { a[i] = con[j]; break; } } } for (int i = 0; i < n; i++) { cout << a[i]; } cout << "\n"; } return 0; }
replace
6
7
6
7
0
p00424
C++
Memory Limit Exceeded
#include <cstring> #include <iostream> #include <string> using namespace std; struct T { unsigned char a, b; }; T array[100000000]; int main() { int n, m, i, j; unsigned char a, b; string ca, cb; bool flag; while (cin >> n && n) { flag = true; string out; memset(array, 0, sizeof(array)); for (i = 0; i < n; i++) { cin >> a >> b; array[i].a = a; array[i].b = b; } cin >> m; for (i = 0; i < m; i++) { cin >> a; ca = a; for (j = 0; j < n; j++) { cb = array[j].a; if (ca == cb) { flag = false; break; } } if (flag) { out += a; } else { out += array[j].b; } flag = true; } cout << out << endl; } return 0; }
#include <cstring> #include <iostream> #include <string> using namespace std; struct T { unsigned char a, b; }; T array[1000000]; int main() { int n, m, i, j; unsigned char a, b; string ca, cb; bool flag; while (cin >> n && n) { flag = true; string out; memset(array, 0, sizeof(array)); for (i = 0; i < n; i++) { cin >> a >> b; array[i].a = a; array[i].b = b; } cin >> m; for (i = 0; i < m; i++) { cin >> a; ca = a; for (j = 0; j < n; j++) { cb = array[j].a; if (ca == cb) { flag = false; break; } } if (flag) { out += a; } else { out += array[j].b; } flag = true; } cout << out << endl; } return 0; }
replace
7
8
7
8
MLE
p00424
C++
Runtime Error
#include <stdio.h> int main() { int n, m; int i, j; char c[10000000][2]; char t[10000000]; int f; while (scanf("%d", &n), n) { for (i = 0; i < n; i++) { scanf("%s", &c[i][0]); scanf("%s", &c[i][1]); } scanf("%d", &m); for (i = 0; i < m; i++) { scanf(" %s", &t[i]); } for (i = 0; i < m; i++) { f = -1; for (j = 0; j < n; j++) { if (t[i] == c[j][0]) { f = j; } } if (f != -1) { printf("%c", c[f][1]); } else if (f == -1) { printf("%c", t[i]); } } printf("\n"); } return 0; }
#include <stdio.h> int main() { int n, m; int i, j; char c[1000000][2]; char t[1000000]; int f; while (scanf("%d", &n), n) { for (i = 0; i < n; i++) { scanf("%s", &c[i][0]); scanf("%s", &c[i][1]); } scanf("%d", &m); for (i = 0; i < m; i++) { scanf(" %s", &t[i]); } for (i = 0; i < m; i++) { f = -1; for (j = 0; j < n; j++) { if (t[i] == c[j][0]) { f = j; } } if (f != -1) { printf("%c", c[f][1]); } else if (f == -1) { printf("%c", t[i]); } } printf("\n"); } return 0; }
replace
5
7
5
7
-11
p00424
C++
Time Limit Exceeded
#include <iostream> using namespace std; char v[256]; int n, m; int main() { while (true) { cin >> n; for (int i = 32; i < 127; i++) { v[i] = i; } for (int i = 0; i < n; i++) { char p, q; cin >> p >> q; v[p] = q; } cin >> m; for (int i = 0; i < m; i++) { char f; cin >> f; cout << v[f]; } cout << endl; } return 0; }
#include <iostream> using namespace std; char v[256]; int n, m; int main() { while (true) { cin >> n; for (int i = 32; i < 127; i++) { v[i] = i; } if (n == 0) break; for (int i = 0; i < n; i++) { char p, q; cin >> p >> q; v[p] = q; } cin >> m; for (int i = 0; i < m; i++) { char f; cin >> f; cout << v[f]; } cout << endl; } return 0; }
insert
10
10
10
12
TLE
p00424
C++
Time Limit Exceeded
#include <iostream> #include <map> #include <string> using namespace std; int main() { map<char, char> mp; char a, b, c; string x; int n; cin >> n; do { mp.clear(); n = 0; x.clear(); do { cin >> a >> b; mp[a] = b; } while (--n); cin >> n; do { cin >> c; if (mp[c] != NULL) { x += mp[c]; } else { x += c; } } while (--n); cout << x << endl; } while (cin >> n, n != 0); return 0; }
#include <iostream> #include <map> #include <string> using namespace std; int main() { map<char, char> mp; char a, b, c; string x; int n; cin >> n; do { mp.clear(); x.clear(); do { cin >> a >> b; mp[a] = b; } while (--n); cin >> n; do { cin >> c; if (mp[c] != NULL) { x += mp[c]; } else { x += c; } } while (--n); cout << x << endl; } while (cin >> n, n != 0); return 0; }
delete
13
14
13
13
TLE
p00424
C++
Runtime Error
#include <iostream> #include <map> using namespace std; int main() { int n, m; string dic[100]; string words[100]; map<string, string> mp; while (true) { cin >> n; if (n == 0) { return 0; } string result = ""; for (int i = 0; i < n; i++) { cin >> dic[i]; cin >> mp[dic[i]]; } cin >> m; for (int k = 0; k < m; k++) { cin >> words[k]; for (int j = 0; j < n; j++) { if (words[k] == dic[j]) { words[k] = mp[dic[j]]; break; } } result = result + words[k]; } cout << result << "\n"; } return 0; }
#include <iostream> #include <map> using namespace std; int main() { int n, m; string dic[100000]; string words[100000]; map<string, string> mp; while (true) { cin >> n; if (n == 0) { return 0; } string result = ""; for (int i = 0; i < n; i++) { cin >> dic[i]; cin >> mp[dic[i]]; } cin >> m; for (int k = 0; k < m; k++) { cin >> words[k]; for (int j = 0; j < n; j++) { if (words[k] == dic[j]) { words[k] = mp[dic[j]]; break; } } result = result + words[k]; } cout << result << "\n"; } return 0; }
replace
6
8
6
8
0
p00424
C++
Runtime Error
#include <iostream> using namespace std; int main() { while (1) { char d; char ans[101]; char f[101], g[101]; int n; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> d; f[i] = d; cin >> d; g[i] = d; } int s; cin >> s; for (int i = 0; i < s; i++) { cin >> d; ans[i] = d; for (int j = 0; j < n; j++) { if (ans[i] == f[j]) { ans[i] = g[j]; break; } } } for (int i = 0; i < s; i++) { cout << ans[i]; } cout << endl; } }
#include <iostream> using namespace std; int main() { while (1) { char d; char ans[101000]; char f[1010000], g[101000]; int n; cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) { cin >> d; f[i] = d; cin >> d; g[i] = d; } int s; cin >> s; for (int i = 0; i < s; i++) { cin >> d; ans[i] = d; for (int j = 0; j < n; j++) { if (ans[i] == f[j]) { ans[i] = g[j]; break; } } } for (int i = 0; i < s; i++) { cout << ans[i]; } cout << endl; } }
replace
5
7
5
7
0
p00424
C++
Memory Limit Exceeded
#include <iostream> #include <string> #include <vector> std::string r1[100], r2[100], s[10000000]; int main() { int n; int m; while (true) { std::cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) std::cin >> r1[i] >> r2[i]; std::cin >> m; for (int i = 0; i < m; i++) std::cin >> s[i]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (r1[j] == s[i]) { s[i] = r2[j]; goto p; } } p:; } for (int i = 0; i < m; i++) { if (i == m - 1) std::cout << s[i] << std::endl; else { std::cout << s[i]; } } } }
#include <iostream> #include <string> #include <vector> std::string r1[100], r2[100], s[1000000]; int main() { int n; int m; while (true) { std::cin >> n; if (n == 0) break; for (int i = 0; i < n; i++) std::cin >> r1[i] >> r2[i]; std::cin >> m; for (int i = 0; i < m; i++) std::cin >> s[i]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (r1[j] == s[i]) { s[i] = r2[j]; goto p; } } p:; } for (int i = 0; i < m; i++) { if (i == m - 1) std::cout << s[i] << std::endl; else { std::cout << s[i]; } } } }
replace
3
4
3
4
MLE
p00424
C++
Runtime Error
#include <stdio.h> int main() { int n, m, i, j; char nn[99999999], nm[99999999], mm[99999999]; while (1) { scanf("%d", &n); if (!n) break; for (i = 0; i < n; i++) { scanf(" %c %c", &nn[i], &nm[i]); } scanf("%d", &m); for (i = 0; i < m; i++) { scanf(" %c", &mm[i]); for (j = 0; j < n; j++) if (mm[i] == nn[j]) { mm[i] = nm[j]; break; } } puts(mm); } }
#include <stdio.h> int main() { int n, m, i, j; char nn[1000000], nm[1000000], mm[1000000]; while (1) { scanf("%d", &n); if (!n) break; for (i = 0; i < n; i++) { scanf(" %c %c", &nn[i], &nm[i]); } scanf("%d", &m); for (i = 0; i < m; i++) { scanf(" %c", &mm[i]); for (j = 0; j < n; j++) if (mm[i] == nn[j]) { mm[i] = nm[j]; break; } } puts(mm); } }
replace
4
5
4
5
-11
p00424
C++
Runtime Error
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n, m; string op; while (cin >> n && n) { char c1[40], c2[40]; op = ""; for (int i = 0; i < n; ++i) cin >> c1[i] >> c2[i]; cin >> m; for (int i = 0; i < m; ++i) { char c; cin >> c; for (int j = 0; j < n; ++j) { if (c == c1[j]) { c = c2[j]; break; } } op += c; } cout << op << endl; } return 0; }
#include <cstdio> #include <iostream> #include <string> using namespace std; int main() { int n, m; string op; while (cin >> n && n) { char c1[100], c2[100]; op = ""; for (int i = 0; i < n; ++i) cin >> c1[i] >> c2[i]; cin >> m; for (int i = 0; i < m; ++i) { char c; cin >> c; for (int j = 0; j < n; ++j) { if (c == c1[j]) { c = c2[j]; break; } } op += c; } cout << op << endl; } return 0; }
replace
9
10
9
10
0
p00425
C++
Time Limit Exceeded
#import <cstdio> int main() { for (int n, a, t, c, r; c = r = scanf("%d", &n), n; printf("%d\n", r)) for (char d[] = "123456"; n--; r += *d - 48) scanf("%s", &t), t %= 256, t % 6 - 4 ? a = t % 5 + t % 2 * 2 + c & 3, t = *d, *d = d[a += a / 2 ? 2 - a % 2 * 2 : 1], d[a] = d[5], d[5] = d[5 - a], d[5 - a] = t : c += t + 3; }
#import <cstdio> int main() { for (int n, a, c, r, t; c = r = scanf("%d", &n), n; printf("%d\n", r)) for (char d[] = "123546", s[9]; n--; r += *d - 48) scanf("%s", s), *s % 6 - 4 ? a = *s % 5 + *s % 2 * 2 + c & 3, t = *d, *d = d[++a], d[++a - 1] = d[5], d[5] = d[a % 4 + 1], d[a % 4 + 1] = t : c += *s + 3; }
replace
2
8
2
8
TLE
p00425
C++
Time Limit Exceeded
#include <stdio.h> #include <string.h> int n; char S[11234][6]; int dice[6] = {1, 2, 3, 5, 4, 6}, tmp = 0, ans = 0; int main(void) { while (true) { ans = 0; dice[0] = 1; dice[1] = 2; dice[2] = 3; dice[3] = 5; dice[4] = 4; dice[5] = 6; scanf("%d", &n); // if (n == 0) { break; } for (int i = 0; i < n; ++i) { scanf("%s", &S[i]); } for (int i = 0; i < n; ++i) { if (strcmp(S[i], "North") == 0) { tmp = dice[0]; dice[0] = dice[1]; dice[1] = dice[5]; dice[5] = dice[3]; dice[3] = tmp; ans += dice[0]; } else if (strcmp(S[i], "East") == 0) { tmp = dice[0]; dice[0] = dice[4]; dice[4] = dice[5]; dice[5] = dice[2]; dice[2] = tmp; ans += dice[0]; } else if (strcmp(S[i], "South") == 0) { tmp = dice[0]; dice[0] = dice[3]; dice[3] = dice[5]; dice[5] = dice[1]; dice[1] = tmp; ans += dice[0]; } else if (strcmp(S[i], "West") == 0) { tmp = dice[0]; dice[0] = dice[2]; dice[2] = dice[5]; dice[5] = dice[4]; dice[4] = tmp; ans += dice[0]; } else if (strcmp(S[i], "Right") == 0) { tmp = dice[1]; dice[1] = dice[2]; dice[2] = dice[3]; dice[3] = dice[4]; dice[4] = tmp; ans += dice[0]; } else if (strcmp(S[i], "Left") == 0) { tmp = dice[1]; dice[1] = dice[4]; dice[4] = dice[3]; dice[3] = dice[2]; dice[2] = tmp; ans += dice[0]; } } printf("%d\n", ans + 1); } return 0; }
#include <stdio.h> #include <string.h> int n; char S[11234][6]; int dice[6] = {1, 2, 3, 5, 4, 6}, tmp = 0, ans = 0; int main(void) { while (true) { ans = 0; dice[0] = 1; dice[1] = 2; dice[2] = 3; dice[3] = 5; dice[4] = 4; dice[5] = 6; scanf("%d", &n); if (n == 0) { break; } for (int i = 0; i < n; ++i) { scanf("%s", &S[i]); } for (int i = 0; i < n; ++i) { if (strcmp(S[i], "North") == 0) { tmp = dice[0]; dice[0] = dice[1]; dice[1] = dice[5]; dice[5] = dice[3]; dice[3] = tmp; ans += dice[0]; } else if (strcmp(S[i], "East") == 0) { tmp = dice[0]; dice[0] = dice[4]; dice[4] = dice[5]; dice[5] = dice[2]; dice[2] = tmp; ans += dice[0]; } else if (strcmp(S[i], "South") == 0) { tmp = dice[0]; dice[0] = dice[3]; dice[3] = dice[5]; dice[5] = dice[1]; dice[1] = tmp; ans += dice[0]; } else if (strcmp(S[i], "West") == 0) { tmp = dice[0]; dice[0] = dice[2]; dice[2] = dice[5]; dice[5] = dice[4]; dice[4] = tmp; ans += dice[0]; } else if (strcmp(S[i], "Right") == 0) { tmp = dice[1]; dice[1] = dice[2]; dice[2] = dice[3]; dice[3] = dice[4]; dice[4] = tmp; ans += dice[0]; } else if (strcmp(S[i], "Left") == 0) { tmp = dice[1]; dice[1] = dice[4]; dice[4] = dice[3]; dice[3] = dice[2]; dice[2] = tmp; ans += dice[0]; } } printf("%d\n", ans + 1); } return 0; }
replace
17
18
17
20
TLE
p00425
C++
Time Limit Exceeded
#include <stdio.h> typedef struct { int U, W, E, S, N, D; } dice_t; int t; void shoki(dice_t *dice) { // ダイスの初期位置 dice->U = 1; dice->W = 4; dice->E = 3; dice->S = 2; dice->N = 5; dice->D = 6; } void N(dice_t *dice) { t = dice->U; dice->U = dice->S; dice->S = dice->D; dice->D = dice->N; dice->N = t; } void E(dice_t *dice) { t = dice->U; dice->U = dice->W; dice->W = dice->D; dice->D = dice->E; dice->E = t; } void W(dice_t *dice) { t = dice->U; dice->U = dice->E; dice->E = dice->D; dice->D = dice->W; dice->W = t; } void S(dice_t *dice) { t = dice->U; dice->U = dice->N; dice->N = dice->D; dice->D = dice->S; dice->S = t; } void R(dice_t *dice) { t = dice->S; dice->S = dice->E; dice->E = dice->N; dice->N = dice->W; dice->W = t; } void L(dice_t *dice) { t = dice->S; dice->S = dice->W; dice->W = dice->N; dice->N = dice->E; dice->E = t; } int main(void) { char sousa[10]; int i, n, s; dice_t dice; while (0 == 0) { scanf("%d", &n); if (n == 0) break; shoki(&dice); s = 1; for (i = 0; i < n; i++) { scanf("%d", sousa); switch (sousa[0]) { case 'N': N(&dice); break; case 'E': E(&dice); break; case 'W': W(&dice); break; case 'S': S(&dice); break; case 'R': R(&dice); break; case 'L': L(&dice); break; } s += dice.U; } printf("%d\n", s); } return 0; }
#include <stdio.h> typedef struct { int U, W, E, S, N, D; } dice_t; int t; void shoki(dice_t *dice) { // ダイスの初期位置 dice->U = 1; dice->W = 4; dice->E = 3; dice->S = 2; dice->N = 5; dice->D = 6; } void N(dice_t *dice) { t = dice->U; dice->U = dice->S; dice->S = dice->D; dice->D = dice->N; dice->N = t; } void E(dice_t *dice) { t = dice->U; dice->U = dice->W; dice->W = dice->D; dice->D = dice->E; dice->E = t; } void W(dice_t *dice) { t = dice->U; dice->U = dice->E; dice->E = dice->D; dice->D = dice->W; dice->W = t; } void S(dice_t *dice) { t = dice->U; dice->U = dice->N; dice->N = dice->D; dice->D = dice->S; dice->S = t; } void R(dice_t *dice) { t = dice->S; dice->S = dice->E; dice->E = dice->N; dice->N = dice->W; dice->W = t; } void L(dice_t *dice) { t = dice->S; dice->S = dice->W; dice->W = dice->N; dice->N = dice->E; dice->E = t; } int main(void) { char sousa[10]; int i, n, s; dice_t dice; while (0 == 0) { scanf("%d", &n); if (n == 0) break; shoki(&dice); s = 1; for (i = 0; i < n; i++) { scanf("%s", sousa); switch (sousa[0]) { case 'N': N(&dice); break; case 'E': E(&dice); break; case 'W': W(&dice); break; case 'S': S(&dice); break; case 'R': R(&dice); break; case 'L': L(&dice); break; } s += dice.U; } printf("%d\n", s); } return 0; }
replace
76
77
76
77
TLE
p00425
C++
Runtime Error
#include <iostream> #include <string> #include <utility> using namespace std; #define DUMP(x) cerr << #x << " = " << (x) << endl; void rotate(int *a, int *b, int *c, int *d) { int temp; temp = *d; *d = *c; *c = *b; *b = *a; *a = temp; } int main(int argc, char const *argv[]) { int i, n, total; string input; int up = 1, bottom = 6, left = 4, right = 3, front = 2, back = 5; while (true) { cin >> n; if (n == 0) { break; } up = 1; bottom = 6; left = 4; right = 3; front = 2; back = 5; total = 1; for (i = 0; i < n; i++) { cin >> input; if (input == "North") { rotate(&up, &back, &bottom, &front); } else if (input == "East") { rotate(&up, &right, &bottom, &left); } else if (input == "West") { rotate(&up, &left, &bottom, &right); } else if (input == "South") { rotate(&up, &front, &bottom, &back); } else if (input == "Right") { rotate(&front, &left, &back, &right); } else if (input == "Left") { rotate(&front, &right, &back, &left); } total += up; DUMP(up); DUMP(total); } cout << total << endl; } return 0; }
#include <iostream> #include <string> #include <utility> using namespace std; #define DUMP(x) cerr << #x << " = " << (x) << endl; void rotate(int *a, int *b, int *c, int *d) { int temp; temp = *d; *d = *c; *c = *b; *b = *a; *a = temp; } int main(int argc, char const *argv[]) { int i, n, total; string input; int up = 1, bottom = 6, left = 4, right = 3, front = 2, back = 5; while (true) { cin >> n; if (n == 0) { break; } up = 1; bottom = 6; left = 4; right = 3; front = 2; back = 5; total = 1; for (i = 0; i < n; i++) { cin >> input; if (input == "North") { rotate(&up, &back, &bottom, &front); } else if (input == "East") { rotate(&up, &right, &bottom, &left); } else if (input == "West") { rotate(&up, &left, &bottom, &right); } else if (input == "South") { rotate(&up, &front, &bottom, &back); } else if (input == "Right") { rotate(&front, &left, &back, &right); } else if (input == "Left") { rotate(&front, &right, &back, &left); } total += up; } cout << total << endl; } return 0; }
delete
55
57
55
55
0
up = 2 total = 3 up = 6 total = 9 up = 4 total = 13 up = 2 total = 15 up = 6 total = 21 up = 3 total = 4 up = 2 total = 6 up = 2 total = 8 up = 6 total = 14 up = 6 total = 20 up = 4 total = 24 up = 4 total = 28 up = 6 total = 34
p00426
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int mp[5000000]; int Hash(string s) { int cnt = 0, t = 1; rep(i, s.size()) { cnt += (int)(s[i] - '0') * t; t *= 3; } return cnt; } int main() { int n, m; while (scanf("%d%d", &n, &m), n) { memset(mp, 0, sizeof(mp)); string in = "000000000000000"; rep(i, 3) { int len; scanf("%d", &len); rep(j, len) { int a; scanf("%d", &a); in[--a] = i + '0'; } } queue<string> que; mp[Hash(in)] = 1; que.push(in); while (!que.empty()) { string u = que.front(); que.pop(); if (count(u.begin(), u.begin() + n, '0') == n || count(u.begin(), u.begin() + n, '2') == n) { printf("%d\n", mp[Hash(u)] - 1); goto g; } if (mp[Hash(u)] > m) continue; rep(k, 2) rep(t, 2) { int i, j; if (t) { i = k, j = k + 1; } else { i = k + 1; j = k; } int fi = (int)u.rfind(i + '0', n - 1), fj = (int)u.rfind(j + '0', n - 1); if (fi == -1 || fi < fj) continue; string v = u; v[fi] = j + '0'; if (!mp[Hash(v)]) { mp[Hash(v)] = mp[Hash(u)] + 1; que.push(v); } } } puts("-1"); g:; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int mp[15000000]; int Hash(string s) { int cnt = 0, t = 1; rep(i, s.size()) { cnt += (int)(s[i] - '0') * t; t *= 3; } return cnt; } int main() { int n, m; while (scanf("%d%d", &n, &m), n) { memset(mp, 0, sizeof(mp)); string in = "000000000000000"; rep(i, 3) { int len; scanf("%d", &len); rep(j, len) { int a; scanf("%d", &a); in[--a] = i + '0'; } } queue<string> que; mp[Hash(in)] = 1; que.push(in); while (!que.empty()) { string u = que.front(); que.pop(); if (count(u.begin(), u.begin() + n, '0') == n || count(u.begin(), u.begin() + n, '2') == n) { printf("%d\n", mp[Hash(u)] - 1); goto g; } if (mp[Hash(u)] > m) continue; rep(k, 2) rep(t, 2) { int i, j; if (t) { i = k, j = k + 1; } else { i = k + 1; j = k; } int fi = (int)u.rfind(i + '0', n - 1), fj = (int)u.rfind(j + '0', n - 1); if (fi == -1 || fi < fj) continue; string v = u; v[fi] = j + '0'; if (!mp[Hash(v)]) { mp[Hash(v)] = mp[Hash(u)] + 1; que.push(v); } } } puts("-1"); g:; } }
replace
4
5
4
5
0
p00427
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #define rep(i, s, n) for (int i = s; i < n; i++) #define Z 100001 using namespace std; int d[Z + 1]; int main() { int n, m, k, r, l; while (true) { cin >> n >> k >> m >> r; if (!(n + m + k + r)) break; rep(i, 0, Z) d[i] = 0; k = 1, l = n; rep(i, 0, Z) d[i] += k / l, k %= l, k *= 10; if (m) rep(i, 1, n) { k = 1, l = i * n; rep(j, 0, Z) d[j] += k / l, k %= l, k *= 10; } for (int i = Z; i > 0; i--) d[i - 1] += d[i] / 10, d[i] %= 10; cout << d[0] << "."; rep(i, 1, r + 1) cout << d[i]; cout << endl; } return 0; }
#include <algorithm> #include <iostream> #define rep(i, s, n) for (int i = s; i < n; i++) #define Z 10005 using namespace std; int d[Z + 1]; int main() { int n, m, k, r, l; while (true) { cin >> n >> k >> m >> r; if (!(n + m + k + r)) break; rep(i, 0, Z) d[i] = 0; k = 1, l = n; rep(i, 0, Z) d[i] += k / l, k %= l, k *= 10; if (m) rep(i, 1, n) { k = 1, l = i * n; rep(j, 0, Z) d[j] += k / l, k %= l, k *= 10; } for (int i = Z; i > 0; i--) d[i - 1] += d[i] / 10, d[i] %= 10; cout << d[0] << "."; rep(i, 1, r + 1) cout << d[i]; cout << endl; } return 0; }
replace
3
4
3
4
TLE
p00427
C++
Runtime Error
#include <algorithm> #include <cfloat> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <vector> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 1100 int N, K, M, R; int ans[NUM]; void calc(int bunshi, int bunbo) { for (int i = 0; i < NUM; i++) { ans[i] += bunshi / bunbo; bunshi %= bunbo; bunshi *= 10; if (bunshi == 0) return; } } void func() { for (int i = 0; i < NUM; i++) ans[i] = 0; if (M == 0) { calc(1, N); } else { // M == 1 calc(1, N); for (int a = 1; a <= N - 1; a++) { calc(1, N * a); } } for (int a = NUM - 1; a >= 1; a--) { if (ans[a] >= 10) { ans[a - 1] += ans[a] / 10; ans[a] %= 10; } } printf("%d.", ans[0]); for (int a = 1; a <= R; a++) { printf("%d", ans[a]); } printf("\n"); } int main() { while (true) { scanf("%d %d %d %d", &N, &K, &M, &R); if (N == 0 && K == 0 && M == 0 && R == 0) break; func(); } return 0; }
#include <algorithm> #include <cfloat> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <vector> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 11000 int N, K, M, R; int ans[NUM]; void calc(int bunshi, int bunbo) { for (int i = 0; i < NUM; i++) { ans[i] += bunshi / bunbo; bunshi %= bunbo; bunshi *= 10; if (bunshi == 0) return; } } void func() { for (int i = 0; i < NUM; i++) ans[i] = 0; if (M == 0) { calc(1, N); } else { // M == 1 calc(1, N); for (int a = 1; a <= N - 1; a++) { calc(1, N * a); } } for (int a = NUM - 1; a >= 1; a--) { if (ans[a] >= 10) { ans[a - 1] += ans[a] / 10; ans[a] %= 10; } } printf("%d.", ans[0]); for (int a = 1; a <= R; a++) { printf("%d", ans[a]); } printf("\n"); } int main() { while (true) { scanf("%d %d %d %d", &N, &K, &M, &R); if (N == 0 && K == 0 && M == 0 && R == 0) break; func(); } return 0; }
replace
19
20
19
20
0
p00427
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int answer[10500]; void add_gyakusu(int x) { int t = 1; for (int i = 0; i < 10200; i++) { answer[i] += t / x; t %= x; t *= 10; } } void kuriagari() { for (int i = 10199; i >= 0; i--) { answer[i - 1] += answer[i] / 10; answer[i] %= 10; } } int main() { int n, k, m, r; while (true) { cin >> n >> k >> m >> r; fill(answer, answer + 10500, 0); if (n + k + m + r == 0) return 0; add_gyakusu(n); if (m == 1) { for (int i = 1; i < n;) { add_gyakusu(i * n); } } kuriagari(); cout << answer[0] << '.'; for (int i = 1; i <= r; i++) { cout << answer[i]; } cout << endl; } }
#include <algorithm> #include <iostream> using namespace std; int answer[10500]; void add_gyakusu(int x) { int t = 1; for (int i = 0; i < 10200; i++) { answer[i] += t / x; t %= x; t *= 10; } } void kuriagari() { for (int i = 10199; i >= 0; i--) { answer[i - 1] += answer[i] / 10; answer[i] %= 10; } } int main() { int n, k, m, r; while (true) { cin >> n >> k >> m >> r; fill(answer, answer + 10500, 0); if (n + k + m + r == 0) return 0; add_gyakusu(n); if (m == 1) { for (int i = 1; i < n; i++) { add_gyakusu(i * n); } } kuriagari(); cout << answer[0] << '.'; for (int i = 1; i <= r; i++) { cout << answer[i]; } cout << endl; } }
replace
31
32
31
32
TLE
p00429
C++
Time Limit Exceeded
#include <iostream> #include <string> using namespace std; // sツづ個静ヲツ督ェツつゥツづァツづ個連ツ堕アツ青板づーツ陛板つキ // sst ツづ按づァツ return 2 int f(string s) { unsigned int count; for (count = 1; count < s.size(); count++) { if (s.at(count - 1) != s.at(count)) break; } return count; } int main() { int n; string str; while (1) { cin >> n; if (n == 0) break; cin >> str; for (int i = 0; i < n; i++) { string ans; for (unsigned int j = 0; j < str.size();) { char buf[1024]; int len = f(str.substr(j)); // sprintf_s(buf, 1024, "%d%c", len, str.at(j)); ans += buf; j += len; } str = ans; } cout << str << endl; } }
#include <iostream> #include <string> using namespace std; // sツづ個静ヲツ督ェツつゥツづァツづ個連ツ堕アツ青板づーツ陛板つキ // sst ツづ按づァツ return 2 int f(string s) { unsigned int count; for (count = 1; count < s.size(); count++) { if (s.at(count - 1) != s.at(count)) break; } return count; } int main() { int n; string str; while (1) { cin >> n; if (n == 0) break; cin >> str; for (int i = 0; i < n; i++) { string ans; for (unsigned int j = 0; j < str.size();) { char buf[1024]; int len = f(str.substr(j)); sprintf(buf, "%d%c", len, str.at(j)); ans += buf; j += len; } str = ans; } cout << str << endl; } }
replace
28
29
28
29
TLE
p00429
C++
Runtime Error
#include <cstdio> #include <iostream> using namespace std; int str[21][250]; int main() { int n; while (cin >> n, n) { int a, r, cntlen; char input[101]; cin >> input; for (int i = 0;; i++) { if (input[i] == '\0') { str[0][i] = -1; break; } str[0][i] = input[i] - '0'; } for (int i = 0; i < n; i++) { /*for(int j=0;str[i][j]!=-1;j++){ printf("%d",str[i][j]); }puts("");*/ a = -1; cntlen = 0; for (int j = 0;; j++) { if (str[i][j] == -1 || a != str[i][j]) { if (~a) { str[i + 1][cntlen] = r; str[i + 1][cntlen + 1] = a; cntlen += 2; } if (str[i][j] == -1) { str[i + 1][cntlen] = -1; break; } a = str[i][j]; r = 1; } else { r++; if (r == 10) { str[i + 1][cntlen] = 1; cntlen++; r = 0; } } } } for (int i = 0; str[n][i] != -1; i++) { printf("%d", str[n][i]); } puts(""); } return 0; }
#include <cstdio> #include <iostream> using namespace std; int str[21][100000]; int main() { int n; while (cin >> n, n) { int a, r, cntlen; char input[101]; cin >> input; for (int i = 0;; i++) { if (input[i] == '\0') { str[0][i] = -1; break; } str[0][i] = input[i] - '0'; } for (int i = 0; i < n; i++) { /*for(int j=0;str[i][j]!=-1;j++){ printf("%d",str[i][j]); }puts("");*/ a = -1; cntlen = 0; for (int j = 0;; j++) { if (str[i][j] == -1 || a != str[i][j]) { if (~a) { str[i + 1][cntlen] = r; str[i + 1][cntlen + 1] = a; cntlen += 2; } if (str[i][j] == -1) { str[i + 1][cntlen] = -1; break; } a = str[i][j]; r = 1; } else { r++; if (r == 10) { str[i + 1][cntlen] = 1; cntlen++; r = 0; } } } } for (int i = 0; str[n][i] != -1; i++) { printf("%d", str[n][i]); } puts(""); } return 0; }
replace
4
5
4
5
0
p00429
C++
Runtime Error
#include <cstring> #include <iostream> #define REP(i, a, n) for (int i = a; i < n; i++) using namespace std; int n; char str[21][10000]; int main(void) { while (cin >> n, n != 0) { cin >> str[0]; REP(i, 0, n) { int j = 0; int k = 0; int len = strlen(str[i]); while (k < len) { int s = k; while (k < len && str[i][k] == str[i][k + 1]) k++; int cnt = k - s + 1; int l = 0; int d[100]; while (cnt != 0) { d[l] = cnt % 10; cnt /= 10; l++; } while (l > 0) { str[i + 1][j++] = '0' + d[--l]; } str[i + 1][j++] = str[i][s]; k++; } str[i + 1][j++] = '\0'; } cout << str[n] << endl; } return 0; }
#include <cstring> #include <iostream> #define REP(i, a, n) for (int i = a; i < n; i++) using namespace std; int n; char str[21][100000]; int main(void) { while (cin >> n, n != 0) { cin >> str[0]; REP(i, 0, n) { int j = 0; int k = 0; int len = strlen(str[i]); while (k < len) { int s = k; while (k < len && str[i][k] == str[i][k + 1]) k++; int cnt = k - s + 1; int l = 0; int d[100]; while (cnt != 0) { d[l] = cnt % 10; cnt /= 10; l++; } while (l > 0) { str[i + 1][j++] = '0' + d[--l]; } str[i + 1][j++] = str[i][s]; k++; } str[i + 1][j++] = '\0'; } cout << str[n] << endl; } return 0; }
replace
6
7
6
7
0
p00429
C++
Runtime Error
#include <cstdlib> #include <iostream> #include <sstream> #include <string> using namespace std; void reset_stringstream(stringstream &ss) { ss.str(""); ss.clear(stringstream::goodbit); } int main() { int n, count = 1, p = 0; string str; int r, a, x[10000]; int size; stringstream ss; string newstr; while (cin >> n) { if (n == 0) break; cin >> str; for (int i = 0; i < n; i++) { newstr = ""; size = str.size(); count = 1; x[0] = atoi(str.substr(0, 1).c_str()); for (int k = 1; k < size; k++) { x[k] = atoi(str.substr(k, 1).c_str()); if (x[k] == x[k - 1]) { count++; if (k == size - 1) { r = count; a = x[k - 1]; // cout << r << " " << a;ok ss << r << a; newstr += ss.str(); reset_stringstream(ss); str = newstr; count = 1; } } else { // cout << count << " " << x[k-1] << endl; r = count; a = x[k - 1]; ss << r << a; newstr += ss.str(); reset_stringstream(ss); count = 1; if (k == size - 1) { r = 1; a = x[k]; ss << r << a; newstr += ss.str(); reset_stringstream(ss); str = newstr; } } } count = 1; } cout << str << endl; } return 0; }
#include <cstdlib> #include <iostream> #include <sstream> #include <string> using namespace std; void reset_stringstream(stringstream &ss) { ss.str(""); ss.clear(stringstream::goodbit); } int main() { int n, count = 1, p = 0; string str; int r, a, x[100000]; int size; stringstream ss; string newstr; while (cin >> n) { if (n == 0) break; cin >> str; for (int i = 0; i < n; i++) { newstr = ""; size = str.size(); count = 1; x[0] = atoi(str.substr(0, 1).c_str()); for (int k = 1; k < size; k++) { x[k] = atoi(str.substr(k, 1).c_str()); if (x[k] == x[k - 1]) { count++; if (k == size - 1) { r = count; a = x[k - 1]; // cout << r << " " << a;ok ss << r << a; newstr += ss.str(); reset_stringstream(ss); str = newstr; count = 1; } } else { // cout << count << " " << x[k-1] << endl; r = count; a = x[k - 1]; ss << r << a; newstr += ss.str(); reset_stringstream(ss); count = 1; if (k == size - 1) { r = 1; a = x[k]; ss << r << a; newstr += ss.str(); reset_stringstream(ss); str = newstr; } } } count = 1; } cout << str << endl; } return 0; }
replace
14
15
14
15
0
p00429
C++
Runtime Error
#include <stdio.h> #include <string.h> int main() { int n; char str[10000]; char tmp[10000]; while (1) { scanf("%d", &n); if (n == 0) { break; } scanf("%s", str); while (n > 0) { int i, j, len; len = strlen(str); memset(tmp, '\0', sizeof(tmp)); char c = '\0'; char countbuf[10], valuebuf[10]; int count; for (i = 0; i < len; i++) { if (c != str[i]) { count = 0; for (j = i; j < len; j++) { if (str[i] == str[j]) { count++; } else { break; } } memset(valuebuf, '\0', sizeof(valuebuf)); valuebuf[0] = str[i]; sprintf(countbuf, "%d", count); strcat(tmp, countbuf); strcat(tmp, valuebuf); memset(countbuf, '\0', sizeof(countbuf)); c = str[i]; } } memcpy(str, tmp, sizeof(tmp)); n--; } printf("%s\n", tmp); } return 0; }
#include <stdio.h> #include <string.h> int main() { int n; char str[100000]; char tmp[100000]; while (1) { scanf("%d", &n); if (n == 0) { break; } scanf("%s", str); while (n > 0) { int i, j, len; len = strlen(str); memset(tmp, '\0', sizeof(tmp)); char c = '\0'; char countbuf[10], valuebuf[10]; int count; for (i = 0; i < len; i++) { if (c != str[i]) { count = 0; for (j = i; j < len; j++) { if (str[i] == str[j]) { count++; } else { break; } } memset(valuebuf, '\0', sizeof(valuebuf)); valuebuf[0] = str[i]; sprintf(countbuf, "%d", count); strcat(tmp, countbuf); strcat(tmp, valuebuf); memset(countbuf, '\0', sizeof(countbuf)); c = str[i]; } } memcpy(str, tmp, sizeof(tmp)); n--; } printf("%s\n", tmp); } return 0; }
replace
5
7
5
7
0
p00429
C++
Time Limit Exceeded
#include <iostream> #include <sstream> #include <string> using namespace std; string itos(int t) { ostringstream oss; oss << t; return oss.str(); } string opr(string str) { string res = ""; for (int i = 0; i < str.size();) { int idx = i + 1; while (idx < str.size() && str[i] == str[idx]) idx++; res += itos(idx - i) + str[i]; } return res; } int main() { int n; while (cin >> n, n) { string str; cin >> str; for (int i = 0; i < n; i++) str = opr(str); cout << str << endl; } }
#include <iostream> #include <sstream> #include <string> using namespace std; string itos(int t) { ostringstream oss; oss << t; return oss.str(); } string opr(string str) { string res = ""; for (int i = 0; i < str.size();) { int idx = i + 1; while (idx < str.size() && str[i] == str[idx]) idx++; res += itos(idx - i) + str[i]; i = idx; } return res; } int main() { int n; while (cin >> n, n) { string str; cin >> str; for (int i = 0; i < n; i++) str = opr(str); cout << str << endl; } }
insert
19
19
19
20
TLE
p00429
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iostream> #include <string> using namespace std; int N; string S; string::iterator CountSeqStr(string::iterator start, string *s, int *n) { *s = *start; *n = 0; string tmp; for (; tmp = *start, tmp == *s && start != S.end(); ++start) { (*n)++; } return --start; } string F() { string retS; string s; string::iterator it; int n; for (it = S.begin(); it != S.end(); ++it) { it = CountSeqStr(it, &s, &n); char *strn; sprintf(strn, "%d", n); retS.append(string(strn)); retS.append(s); } return retS; } int main() { while (cin >> N && N) { cin >> S; for (int i = 0; i < N; i++) { string tmp; S = F(); } cout << S << endl; } return 0; }
#include <cstdio> #include <cstdlib> #include <iostream> #include <string> using namespace std; int N; string S; string::iterator CountSeqStr(string::iterator start, string *s, int *n) { *s = *start; *n = 0; string tmp; for (; tmp = *start, tmp == *s && start != S.end(); ++start) { (*n)++; } return --start; } string F() { string retS; string s; string::iterator it; int n; for (it = S.begin(); it != S.end(); ++it) { it = CountSeqStr(it, &s, &n); char strn[10000]; sprintf(strn, "%d", n); retS.append(string(strn)); retS.append(s); } return retS; } int main() { while (cin >> N && N) { cin >> S; for (int i = 0; i < N; i++) { string tmp; S = F(); } cout << S << endl; } return 0; }
replace
26
27
26
27
-11
p00429
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, i; char data[101]; char out[101]; char r; int k, m; char num[11] = "0123456789"; while (cin >> n) { if (n == 0) { break; } cin >> data; for (int j = 0; j < n; j++) { k = 0; m = 1; r = data[0]; for (i = 1; data[i] != '\0'; i++) { if (data[i] == r) { m += 1; } else { if (m < 10) { out[k] = num[m]; k += 1; } else if (m < 100) { out[k] = num[m / 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } else { out[k] = num[m / 100]; k += 1; out[k] = num[m / 10 - m / 100 * 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } out[k] = r; k += 1; r = data[i]; m = 1; } } if (m < 10) { out[k] = num[m]; k += 1; } else if (m < 100) { out[k] = num[m / 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } else { out[k] = num[m / 100]; k += 1; out[k] = num[m / 10 - m / 100 * 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } out[k] = r; k += 1; out[k] = '\0'; for (i = 0; out[i] != '\0'; i++) { data[i] = out[i]; } data[i] = '\0'; } cout << data << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, i; char data[2000001]; char out[2000001]; char r; int k, m; char num[11] = "0123456789"; while (cin >> n) { if (n == 0) { break; } cin >> data; for (int j = 0; j < n; j++) { k = 0; m = 1; r = data[0]; for (i = 1; data[i] != '\0'; i++) { if (data[i] == r) { m += 1; } else { if (m < 10) { out[k] = num[m]; k += 1; } else if (m < 100) { out[k] = num[m / 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } else { out[k] = num[m / 100]; k += 1; out[k] = num[m / 10 - m / 100 * 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } out[k] = r; k += 1; r = data[i]; m = 1; } } if (m < 10) { out[k] = num[m]; k += 1; } else if (m < 100) { out[k] = num[m / 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } else { out[k] = num[m / 100]; k += 1; out[k] = num[m / 10 - m / 100 * 10]; k += 1; out[k] = num[m - m / 10 * 10]; k += 1; } out[k] = r; k += 1; out[k] = '\0'; for (i = 0; out[i] != '\0'; i++) { data[i] = out[i]; } data[i] = '\0'; } cout << data << endl; } return 0; }
replace
4
6
4
6
0
p00429
C++
Time Limit Exceeded
#include <stdio.h> #include <string.h> #define MAXLEN 1024 int main(void) { int n; char src[MAXLEN], *p, *q; int ch, cnt; while (scanf("%d", &n), n) { scanf("%s", src); for (int i = 0; i < n; i++) { char buf[MAXLEN] = {0}; ch = *src; cnt = 1; q = buf; for (p = src + 1; 1; p++) { // printf("p=<%s>, buf=<%s>, (ch=%c, cnt=%d)\n", //p, buf, ch, cnt); if (*p == ch) { cnt++; } else { char tmp[100]; sprintf(tmp, "%d", cnt); strcpy(q, tmp); q += strlen(tmp); *q++ = ch; ch = *p; cnt = 1; if (ch == 0) break; } } strcpy(src, buf); } puts(src); } return 0; }
#include <stdio.h> #include <string.h> #define MAXLEN 65536 int main(void) { int n; char src[MAXLEN], *p, *q; int ch, cnt; while (scanf("%d", &n), n) { scanf("%s", src); for (int i = 0; i < n; i++) { char buf[MAXLEN] = {0}; ch = *src; cnt = 1; q = buf; for (p = src + 1; 1; p++) { // printf("p=<%s>, buf=<%s>, (ch=%c, cnt=%d)\n", //p, buf, ch, cnt); if (*p == ch) { cnt++; } else { char tmp[100]; sprintf(tmp, "%d", cnt); strcpy(q, tmp); q += strlen(tmp); *q++ = ch; ch = *p; cnt = 1; if (ch == 0) break; } } strcpy(src, buf); } puts(src); } return 0; }
replace
3
4
3
4
TLE
p00429
C++
Runtime Error
#include <stack> #include <stdio.h> using namespace std; int main() { char buf1[1000], buf2[1000], pre; int n, p, count, tmp; stack<int> S; while (true) { scanf("%d", &n); if (n == 0) break; scanf("%s", buf1); for (int i = 0; i < n; i++) { p = count = 0; if (i % 2 == 0) { for (int k = 0; buf1[k] != '\0';) { if (k == 0) { pre = buf1[k]; count++; k++; } else { if (pre == buf1[k]) { if (buf1[k + 1] != '\0') { count++; } else { count++; if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf2[p++] = '0' + tmp; } buf2[p++] = pre; buf2[p++] = '\0'; } else { buf2[p++] = '0' + count; buf2[p++] = pre; buf2[p++] = '\0'; } } k++; } else { if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf2[p++] = '0' + tmp; } buf2[p++] = pre; } else { buf2[p++] = '0' + count; buf2[p++] = pre; } pre = buf1[k]; count = 0; } } } } else { for (int k = 0; buf2[k] != '\0';) { if (k == 0) { pre = buf2[k]; count++; k++; } else { if (pre == buf2[k]) { if (buf2[k + 1] != '\0') { count++; } else { count++; if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf1[p++] = '0' + tmp; } buf1[p++] = pre; buf1[p++] = '\0'; } else { buf1[p++] = '0' + count; buf1[p++] = pre; buf1[p++] = '\0'; } } k++; } else { if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf1[p++] = '0' + tmp; } buf1[p++] = pre; } else { buf1[p++] = '0' + count; buf1[p++] = pre; } pre = buf2[k]; count = 0; } } } } } if (n % 2 == 1) printf("%s\n", buf2); else { printf("%s\n", buf1); } } return 0; }
#include <stack> #include <stdio.h> using namespace std; int main() { char buf1[100000], buf2[100000], pre; int n, p, count, tmp; stack<int> S; while (true) { scanf("%d", &n); if (n == 0) break; scanf("%s", buf1); for (int i = 0; i < n; i++) { p = count = 0; if (i % 2 == 0) { for (int k = 0; buf1[k] != '\0';) { if (k == 0) { pre = buf1[k]; count++; k++; } else { if (pre == buf1[k]) { if (buf1[k + 1] != '\0') { count++; } else { count++; if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf2[p++] = '0' + tmp; } buf2[p++] = pre; buf2[p++] = '\0'; } else { buf2[p++] = '0' + count; buf2[p++] = pre; buf2[p++] = '\0'; } } k++; } else { if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf2[p++] = '0' + tmp; } buf2[p++] = pre; } else { buf2[p++] = '0' + count; buf2[p++] = pre; } pre = buf1[k]; count = 0; } } } } else { for (int k = 0; buf2[k] != '\0';) { if (k == 0) { pre = buf2[k]; count++; k++; } else { if (pre == buf2[k]) { if (buf2[k + 1] != '\0') { count++; } else { count++; if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf1[p++] = '0' + tmp; } buf1[p++] = pre; buf1[p++] = '\0'; } else { buf1[p++] = '0' + count; buf1[p++] = pre; buf1[p++] = '\0'; } } k++; } else { if (count >= 10) { while (count != 0) { S.push(count % 10); count /= 10; } while (!S.empty()) { tmp = S.top(); S.pop(); buf1[p++] = '0' + tmp; } buf1[p++] = pre; } else { buf1[p++] = '0' + count; buf1[p++] = pre; } pre = buf2[k]; count = 0; } } } } } if (n % 2 == 1) printf("%s\n", buf2); else { printf("%s\n", buf1); } } return 0; }
replace
6
7
6
7
0
p00429
C++
Runtime Error
#include <cstdio> #include <iostream> #include <string.h> using namespace std; int main() { char in[2][10001], key, temp[10001]; int n, now, cnt, wrt; bool turn; while (cin >> n && n) { cin >> in[0]; turn = 1; for (int i = 0; i < n; i++) { turn = !turn; now = 0; wrt = 0; while (now < strlen(in[turn])) { key = in[turn][now]; cnt = 0; while (now < strlen(in[turn]) && key == in[turn][now]) { now++; cnt++; } sprintf(temp, "%d", cnt); for (int j = 0; j < strlen(temp); j++) { in[!turn][wrt] = temp[j]; wrt++; } in[!turn][wrt] = key; wrt++; } in[!turn][wrt] = '\0'; } cout << in[!turn] << endl; } return 0; }
#include <cstdio> #include <iostream> #include <string.h> using namespace std; int main() { char in[2][100001], key, temp[100001]; int n, now, cnt, wrt; bool turn; while (cin >> n && n) { cin >> in[0]; turn = 1; for (int i = 0; i < n; i++) { turn = !turn; now = 0; wrt = 0; while (now < strlen(in[turn])) { key = in[turn][now]; cnt = 0; while (now < strlen(in[turn]) && key == in[turn][now]) { now++; cnt++; } sprintf(temp, "%d", cnt); for (int j = 0; j < strlen(temp); j++) { in[!turn][wrt] = temp[j]; wrt++; } in[!turn][wrt] = key; wrt++; } in[!turn][wrt] = '\0'; } cout << in[!turn] << endl; } return 0; }
replace
7
8
7
8
0
p00429
C++
Runtime Error
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char ss[10000], sst[10000]; // “ü—Í—p‚Æ“r’†Œo‰ß—p‚Ì•¶Žš—ñ”z—ñ int n, i, j, ki, a, b; while (0 <= scanf("%d", &n)) { if (n == 0) break; scanf(" %s ", ss); while (n > 0) { --n; j = 0; // “ü—Í‚³‚ꂽ•¶Žš—ñ”z—ñ‚Ì“YŽš i = 0; // “r’†Œo‰ß‚Ì•¶Žš—ñ”z—ñ‚Ì“YŽš // ‚±‚Ìfor•¶‚Pƒ‹[ƒv‚Ő”Žš‚Ì‚©‚½‚Ü‚è‚P‚Â‚ðˆ—‚·‚é for (;;) { if (ss[j] == '\0') break; ki = ss[j]; b = 1; // ˜A‘±‚µ‚Ä‚¢‚é”Žš‚𐔂¦‚éiŒÂ”‚Íb‚É“ü‚ê‚éj for (a = j;; a++) { if (ss[a] != ss[a + 1]) break; ++b; } // Œ…”‚ª‘å‚«‚¢Žž‚̏ˆ— if (b > 99) { sst[i] = b / 100 + '0'; ++i; } if (b > 9) { sst[i] = (b / 10) % 10 + '0'; ++i; } sst[i] = b % 10 + '0'; sst[i + 1] = ki; i = i + 2; j = a + 1; sst[i] = '\0'; } // “r’†Œo‰ß‚ð“ü—Í—p”z—ñ‚É“ü‚ê‚㋁[ƒv // strcpy(ss,sst); for (i = 0;; i++) { ss[i] = sst[i]; if (sst[i] == '\0') break; } } printf("%s\n", sst); } return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char ss[100000], sst[100000]; // “ü—Í—p‚Æ“r’†Œo‰ß—p‚Ì•¶Žš—ñ”z—ñ int n, i, j, ki, a, b; while (0 <= scanf("%d", &n)) { if (n == 0) break; scanf(" %s ", ss); while (n > 0) { --n; j = 0; // “ü—Í‚³‚ꂽ•¶Žš—ñ”z—ñ‚Ì“YŽš i = 0; // “r’†Œo‰ß‚Ì•¶Žš—ñ”z—ñ‚Ì“YŽš // ‚±‚Ìfor•¶‚Pƒ‹[ƒv‚Ő”Žš‚Ì‚©‚½‚Ü‚è‚P‚Â‚ðˆ—‚·‚é for (;;) { if (ss[j] == '\0') break; ki = ss[j]; b = 1; // ˜A‘±‚µ‚Ä‚¢‚é”Žš‚𐔂¦‚éiŒÂ”‚Íb‚É“ü‚ê‚éj for (a = j;; a++) { if (ss[a] != ss[a + 1]) break; ++b; } // Œ…”‚ª‘å‚«‚¢Žž‚̏ˆ— if (b > 99) { sst[i] = b / 100 + '0'; ++i; } if (b > 9) { sst[i] = (b / 10) % 10 + '0'; ++i; } sst[i] = b % 10 + '0'; sst[i + 1] = ki; i = i + 2; j = a + 1; sst[i] = '\0'; } // “r’†Œo‰ß‚ð“ü—Í—p”z—ñ‚É“ü‚ê‚㋁[ƒv // strcpy(ss,sst); for (i = 0;; i++) { ss[i] = sst[i]; if (sst[i] == '\0') break; } } printf("%s\n", sst); } return 0; }
replace
5
7
5
7
0
p00429
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #define INF 100000000 #include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> using namespace std; typedef long long ll; typedef pair<int, int> P; static const double eps = 1e-8; int main() { int n; while (~scanf("%d", &n)) { if (n == 0) break; string num; cin >> num; for (int i = 0; i < n; i++) { string next; for (int j = 0; j < num.size();) { int c = 0; char alph; for (int k = 0; k <= 9; k++) { for (int len = 1; j + len - 1 < num.size(); len++) { string tmp = num.substr(j, len); if (count(tmp.begin(), tmp.end(), '0' + k) == len) { c++; alph = '0' + k; } } } j += c; char buf[32]; sprintf(buf, "%d", c); string tmp = buf; next.append(tmp); next.push_back(alph); } num = next; } cout << num << endl; } }
#define _USE_MATH_DEFINES #define INF 100000000 #include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> using namespace std; typedef long long ll; typedef pair<int, int> P; static const double eps = 1e-8; int main() { int n; while (~scanf("%d", &n)) { if (n == 0) break; string num; cin >> num; for (int i = 0; i < n; i++) { string next; for (int j = 0; j < num.size();) { int c = 0; char alph; for (int k = 0; k <= 9; k++) { for (int len = 1; j + len - 1 < num.size(); len++) { string tmp = num.substr(j, len); if (count(tmp.begin(), tmp.end(), '0' + k) == len) { c++; alph = '0' + k; } else break; } } j += c; char buf[32]; sprintf(buf, "%d", c); string tmp = buf; next.append(tmp); next.push_back(alph); } num = next; } cout << num << endl; } }
replace
43
44
43
45
TLE
p00429
C++
Memory Limit Exceeded
#include <cstdio> #include <cstring> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n, num, cont, v; string a, nex; stringstream ss; while (1) { scanf("%d", &n); if (n == 0) { break; } cin >> a; for (int i = 0; i < n; i++) { cont = 0; while (1) { if (cont >= a.size()) { break; } num = a[cont]; v = 0; while (1) { if (a[cont] != num) { break; } v++; cont++; } ss.clear(); ss << v; nex += ss.str(); nex += num; } a = nex; nex = ""; } cout << a << endl; } }
#include <cstdio> #include <cstring> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { int n, num, cont, v; string a, nex; stringstream ss; while (1) { scanf("%d", &n); if (n == 0) { break; } cin >> a; for (int i = 0; i < n; i++) { cont = 0; while (1) { if (cont >= a.size()) { break; } num = a[cont]; v = 0; while (1) { if (a[cont] != num) { break; } v++; cont++; } ss.str(""); ss << v; nex += ss.str(); nex += num; } a = nex; nex = ""; } cout << a << endl; } }
replace
38
40
38
39
MLE
p00430
C++
Runtime Error
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> #define rep(i, s, n) for (int i = (s); (n) > i; i++) #define REP(i, n) rep(i, 0, n) #define RANGE(x, a, b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a, b, c, d) \ (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b)) #define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d)) #define PW(x) ((x) * (x)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MODU 1000000007 #define bitcheck(a, b) ((a >> b) & 1) #define bitset(a, b) (a |= (1 << b)) #define bitunset(a, b) (a &= ~(1 << b)) #define MP(a, b) make_pair((a), (b)) #define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #define izryt bool using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } pii Dir[8] = { //?§???? {0, 1}, {-1, 0}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; signed main() { int n; while (scanf("%d", &n)) { if (!n) break; vector<int> used; function<void(int, int)> func = [&](int sum, int bef) { if (sum == n) { REP(i, used.size()) { printf("%d", used[i]); if (i != (int)used.size() - 1) printf(" "); } printf("\n"); return; } for (int i = bef; 0 <= i; i--) { if (sum + i <= n) { used.push_back(i); func(sum + i, i); used.erase(--used.end()); } } }; func(0, n); } return 0; }
#include <algorithm> #include <array> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <vector> #define rep(i, s, n) for (int i = (s); (n) > i; i++) #define REP(i, n) rep(i, 0, n) #define RANGE(x, a, b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a, b, c, d) \ (RANGE(a, c, d) || RANGE(b, c, d) || RANGE(c, a, b) || RANGE(d, a, b)) #define INCLU(a, b, c, d) (RANGE(a, c, d) && (b, c, d)) #define PW(x) ((x) * (x)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MODU 1000000007 #define bitcheck(a, b) ((a >> b) & 1) #define bitset(a, b) (a |= (1 << b)) #define bitunset(a, b) (a &= ~(1 << b)) #define MP(a, b) make_pair((a), (b)) #define Manh(a, b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #define izryt bool using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } pii Dir[8] = { //?§???? {0, 1}, {-1, 0}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; signed main() { int n; while (scanf("%d", &n)) { if (!n) break; vector<int> used; function<void(int, int)> func = [&](int sum, int bef) { if (sum == n) { REP(i, used.size()) { printf("%d", used[i]); if (i != (int)used.size() - 1) printf(" "); } printf("\n"); return; } for (int i = bef; 1 <= i; i--) { if (sum + i <= n) { used.push_back(i); func(sum + i, i); used.erase(--used.end()); } } }; func(0, n); } return 0; }
replace
66
67
66
67
-11
p00430
C++
Time Limit Exceeded
#include <stdio.h> int n, number[30]; void rec(int sum, int mins, int cnt) { if (sum == n) { for (int i = 0; i < cnt; i++) { if (i) { printf(" "); } printf("%d", number[i]); } printf("\n"); return; } for (int i = mins; i > 0; i++) { if (sum + i > n) continue; number[cnt] = i; rec(sum + i, i, cnt + 1); number[cnt] = 0; } } int main() { while (true) { scanf("%d", &n); if (n == 0) { break; } rec(0, n, 0); } return 0; }
#include <stdio.h> int n, number[30]; void rec(int sum, int mins, int cnt) { if (sum == n) { for (int i = 0; i < cnt; i++) { if (i) { printf(" "); } printf("%d", number[i]); } printf("\n"); return; } for (int i = mins; i > 0; i--) { if (sum + i > n) continue; number[cnt] = i; rec(sum + i, i, cnt + 1); number[cnt] = 0; } } int main() { while (true) { scanf("%d", &n); if (n == 0) { break; } rec(0, n, 0); } return 0; }
replace
18
19
18
19
TLE
p00430
C++
Runtime Error
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) \ for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define popcount __builtin_popcount const double EPS = 1e-10; typedef long long ll; typedef pair<int, int> pint; int main() { int n; while (scanf("%d", &n), n) { int b[16]; memset(b, 0, sizeof(b)); b[0] = n; while (true) { int t = find(b, b + n, 0) - b; for (int i = 0; i < t - 1; ++i) printf("%d ", b[i]); printf("%d\n", b[t - 1]); if (t == n) break; int u; u = t - 1; while (b[u] == 1) --u; --b[u]; ++u; fill(b + u, b + n, 0); int s = t - u + 1; while (s--) { if (b[u] == b[u - 1]) ++u; ++b[u]; } } } }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) \ for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define popcount __builtin_popcount const double EPS = 1e-10; typedef long long ll; typedef pair<int, int> pint; int main() { int n; while (scanf("%d", &n), n) { int b[31]; memset(b, 0, sizeof(b)); b[0] = n; while (true) { int t = find(b, b + n, 0) - b; for (int i = 0; i < t - 1; ++i) printf("%d ", b[i]); printf("%d\n", b[t - 1]); if (t == n) break; int u; u = t - 1; while (b[u] == 1) --u; --b[u]; ++u; fill(b + u, b + n, 0); int s = t - u + 1; while (s--) { if (b[u] == b[u - 1]) ++u; ++b[u]; } } } }
replace
45
46
45
46
0
p00431
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int n, g[101][101], g_size[101]; bool used[101]; int rec(int idx) { int ret = 1; for (int i = 0; i < g_size[idx]; i++) { if (!used[g[idx][i]]) { used[g[idx][i]] = true; ret = max(ret, rec(g[idx][i]) + 1); used[g[idx][i]] = false; } } return ret; } int main() { while (cin >> n, n) { for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; g[a][g_size[a]++] = b; g[b][g_size[b]++] = a; } int ans = 1; for (int i = 1; i <= 100; i++) { if (g_size[i] > 0) { used[i] = true; ans = max(ans, rec(i)); used[i] = false; } } cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int n, g[101][101], g_size[101]; bool used[101]; int rec(int idx) { int ret = 1; for (int i = 0; i < g_size[idx]; i++) { if (!used[g[idx][i]]) { used[g[idx][i]] = true; ret = max(ret, rec(g[idx][i]) + 1); used[g[idx][i]] = false; } } return ret; } int main() { while (cin >> n, n) { fill_n(g_size, 101, 0); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; g[a][g_size[a]++] = b; g[b][g_size[b]++] = a; } int ans = 1; for (int i = 1; i <= 100; i++) { if (g_size[i] > 0) { used[i] = true; ans = max(ans, rec(i)); used[i] = false; } } cout << ans << endl; } }
insert
21
21
21
22
TLE
p00431
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <stdio.h> #include <vector> using namespace std; bool d[101], dd[101]; // true = 使った。 int ans = 0; int n; vector<int> G[101]; int dfs(int from, int now) { for (int i = 0; i < G[from].size(); i++) { if (!d[G[from][i]]) { d[G[from][i]] = true; if (G[from].size() > G[G[from][i]].size() + 2) dd[G[from][i]] = true; ans = max(ans, dfs(G[from][i], now + 1)); d[G[from][i]] = false; } } return now; } int main(void) { ans = 0; while (cin >> n, n) { ans = 0; int from, to; for (int i = 0; i < 101; i++) d[i] = dd[i] = false; for (int i = 0; i < n; i++) { cin >> from >> to; G[from].push_back(to); G[to].push_back(from); } for (int i = 0; i <= n; i++) { if (!dd[i]) { dfs(i, 1); } } for (int i = 0; i < 101; i++) while (G[i].size()) G[i].pop_back(); cout << ans - 1 << endl; } return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <vector> using namespace std; bool d[101], dd[101]; // true = 使った。 int ans = 0; int n; vector<int> G[101]; int dfs(int from, int now) { for (int i = 0; i < G[from].size(); i++) { if (!d[G[from][i]]) { d[G[from][i]] = true; if (G[from].size() > 2) dd[G[from][i]] = true; ans = max(ans, dfs(G[from][i], now + 1)); d[G[from][i]] = false; } } return now; } int main(void) { ans = 0; while (cin >> n, n) { ans = 0; int from, to; for (int i = 0; i < 101; i++) d[i] = dd[i] = false; for (int i = 0; i < n; i++) { cin >> from >> to; G[from].push_back(to); G[to].push_back(from); } for (int i = 0; i <= n; i++) { if (!dd[i]) { dfs(i, 1); } } for (int i = 0; i < 101; i++) while (G[i].size()) G[i].pop_back(); cout << ans - 1 << endl; } return 0; }
replace
17
18
17
18
TLE
p00431
C++
Time Limit Exceeded
#include <stdio.h> #include <time.h> #define N 101 int find_length(int a, int cur_length); int conn[N][N]; int used[N]; int main() { int i, j; int a, b; int n; int max_length, length; time_t start_time, t; while (1) { start_time = time(NULL); for (j = 0; j < N; j++) { for (i = 0; i < N; i++) { conn[j][i] = 0; } } scanf("%d", &n); if (n == 0) { break; } for (int i = 0; i < n; i++) { scanf("%d %d", &a, &b); conn[a][b] = 1; conn[b][a] = 1; } for (a = 0; a < N; a++) { used[a] = 0; } max_length = 0; for (a = 0; a < N; a++) { length = find_length(a, 1); if (length > max_length) { max_length = length; } if (time(NULL) - start_time > 3) { break; } } printf("%d\n", max_length); } } int find_length(int a, int cur_length) { int b; int length, max_length; used[a] = 1; max_length = cur_length; for (b = 0; b < N; b++) { if (conn[a][b] == 1 && used[b] != 1) { length = find_length(b, cur_length + 1); if (length > max_length) { max_length = length; } } } used[a] = 0; return max_length; }
#include <stdio.h> #include <time.h> #define N 101 int find_length(int a, int cur_length); int conn[N][N]; int used[N]; int main() { int i, j; int a, b; int n; int max_length, length; time_t start_time, t; while (1) { start_time = time(NULL); for (j = 0; j < N; j++) { for (i = 0; i < N; i++) { conn[j][i] = 0; } } scanf("%d", &n); if (n == 0) { break; } for (int i = 0; i < n; i++) { scanf("%d %d", &a, &b); conn[a][b] = 1; conn[b][a] = 1; } for (a = 0; a < N; a++) { used[a] = 0; } max_length = 0; for (a = 0; a < N; a++) { length = find_length(a, 1); if (length > max_length) { max_length = length; } if (time(NULL) - start_time > 1) { break; } } printf("%d\n", max_length); } } int find_length(int a, int cur_length) { int b; int length, max_length; used[a] = 1; max_length = cur_length; for (b = 0; b < N; b++) { if (conn[a][b] == 1 && used[b] != 1) { length = find_length(b, cur_length + 1); if (length > max_length) { max_length = length; } } } used[a] = 0; return max_length; }
replace
45
46
45
46
TLE
p00431
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, t1, t2, i = 0; int a[10] = {11, 19, 24, 10, 65, 9, 35, 51, 25, 20}; cin >> n; while (n != 0) { cin >> t1 >> t2; cout << a[i] << endl; i++; cin >> n; } }
#include <iostream> using namespace std; int main() { int n, t1, t2, i = 0; int a[10] = {11, 19, 24, 10, 65, 9, 35, 51, 25, 20}; cin >> n; while (n != 0) { for (int I = 0; I < n; I++) cin >> t1 >> t2; cout << a[i] << endl; i++; cin >> n; } }
replace
7
8
7
9
-11
p00432
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <vector> #define F first #define S second using namespace std; typedef pair<int, int> P; int n, r; vector<P> x[10002]; vector<P> xx[10002]; int main(void) { while (cin >> n >> r && n) { for (int i = 0; i < 10002; i++) { x[i].clear(); xx[i].clear(); } for (int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; for (int j = x1; j < x2; j++) { bool f = true; for (int k = 0; k < (int)x[j].size(); k++) { if (x[j][k].F <= y2 && x[j][k].S >= y1) { x[j][k].F = min(x[j][k].F, y1); x[j][k].S = max(x[i][k].S, y2); f = false; break; } } if (f) x[j].push_back(P(y1, y2)); } } for (int i = 0; i < 10000; i++) { if (x[i].empty()) continue; sort(x[i].begin(), x[i].end()); xx[i].push_back(x[i][0]); for (int j = 1, k = 0; j < (int)x[i].size(); j++) { if (xx[i][k].S >= x[i][j].F) { xx[i][k].S = max(xx[i][k].S, x[i][j].S); } else { xx[i].push_back(x[i][j]); k++; } } // x[i].clear(); /* cout << "x = " << i << endl; for(int j = 0; j < (int)xx[i].size(); j++){ cout << "( " << xx[i][j].F << " , " << xx[i][j].S << " )" << endl; } cout << endl; //*/ } int res = 0; for (int i = 0; i < 10000; i++) { for (int j = 0; j < (int)xx[i].size(); j++) { res += xx[i][j].S - xx[i][j].F; } } cout << res << endl; if (r - 1) { res = 0; for (int i = 0; i < 10000; i++) { res += 2 * (int)xx[i].size(); for (int j = 0; j < (int)xx[i].size(); j++) { res += 2 * (xx[i][j].S - xx[i][j].F); if (i) { for (int k = 0; k < (int)xx[i - 1].size(); k++) { if (xx[i][j].F < xx[i - 1][k].S && xx[i][j].S > xx[i - 1][k].F) { res -= min(xx[i][j].S, xx[i - 1][k].S) - max(xx[i][j].F, xx[i - 1][k].F); } } } if (i + 1 < 10000) { for (int k = 0; k < (int)xx[i + 1].size(); k++) { if (xx[i][j].F < xx[i + 1][k].S && xx[i][j].S > xx[i + 1][k].F) { res -= min(xx[i][j].S, xx[i + 1][k].S) - max(xx[i][j].F, xx[i + 1][k].F); } } } } } cout << res << endl; } } }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <vector> #define F first #define S second using namespace std; typedef pair<int, int> P; int n, r; vector<P> x[10002]; vector<P> xx[10002]; int main(void) { while (cin >> n >> r && n) { for (int i = 0; i < 10002; i++) { x[i].clear(); xx[i].clear(); } for (int i = 0; i < n; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; for (int j = x1; j < x2; j++) { bool f = true; for (int k = 0; k < (int)x[j].size(); k++) { if (x[j][k].F <= y2 && x[j][k].S >= y1) { x[j][k].F = min(x[j][k].F, y1); x[j][k].S = max(x[j][k].S, y2); f = false; break; } } if (f) x[j].push_back(P(y1, y2)); } } for (int i = 0; i < 10000; i++) { if (x[i].empty()) continue; sort(x[i].begin(), x[i].end()); xx[i].push_back(x[i][0]); for (int j = 1, k = 0; j < (int)x[i].size(); j++) { if (xx[i][k].S >= x[i][j].F) { xx[i][k].S = max(xx[i][k].S, x[i][j].S); } else { xx[i].push_back(x[i][j]); k++; } } // x[i].clear(); /* cout << "x = " << i << endl; for(int j = 0; j < (int)xx[i].size(); j++){ cout << "( " << xx[i][j].F << " , " << xx[i][j].S << " )" << endl; } cout << endl; //*/ } int res = 0; for (int i = 0; i < 10000; i++) { for (int j = 0; j < (int)xx[i].size(); j++) { res += xx[i][j].S - xx[i][j].F; } } cout << res << endl; if (r - 1) { res = 0; for (int i = 0; i < 10000; i++) { res += 2 * (int)xx[i].size(); for (int j = 0; j < (int)xx[i].size(); j++) { res += 2 * (xx[i][j].S - xx[i][j].F); if (i) { for (int k = 0; k < (int)xx[i - 1].size(); k++) { if (xx[i][j].F < xx[i - 1][k].S && xx[i][j].S > xx[i - 1][k].F) { res -= min(xx[i][j].S, xx[i - 1][k].S) - max(xx[i][j].F, xx[i - 1][k].F); } } } if (i + 1 < 10000) { for (int k = 0; k < (int)xx[i + 1].size(); k++) { if (xx[i][j].F < xx[i + 1][k].S && xx[i][j].S > xx[i + 1][k].F) { res -= min(xx[i][j].S, xx[i + 1][k].S) - max(xx[i][j].F, xx[i + 1][k].F); } } } } } cout << res << endl; } } }
replace
27
28
27
28
0
p00432
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; struct Tag { int a; int b1, b2; bool start; Tag() : a(0), b1(0), b2(0), start(false) {} Tag(int aa, int bb1, int bb2, bool s) : a(aa), b1(bb1), b2(bb2), start(s) {} }; bool cmp(const Tag &t1, const Tag &t2) { if (t1.a != t2.a) return t1.a < t2.a; return !t1.start; } int main() { while (true) { int N, R; cin >> N >> R; if (!N && !R) break; vector<Tag> xtag, ytag; for (int i = 0; i < N; ++i) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xtag.push_back(Tag(x1, y1, y2, true)); xtag.push_back(Tag(x2, y1, y2, false)); ytag.push_back(Tag(y1, x1, x2, true)); ytag.push_back(Tag(y2, x1, x2, false)); } sort(xtag.begin(), xtag.end(), cmp); sort(ytag.begin(), ytag.end(), cmp); int max_y = ytag[ytag.size() - 1].a; int area = 0; int len = 0; for (int y = 0; y < max_y; ++y) { int depth = 0; int startx = 0; int prevx = -1; for (int i = 0; i < xtag.size(); ++i) { if (xtag[i].b1 <= y && y < xtag[i].b2) { if (xtag[i].start) { if (depth == 0) { if (xtag[i].a != prevx) ++len; else --len; startx = xtag[i].a; } ++depth; } else { if (--depth == 0) { area += xtag[i].a - startx; prevx = xtag[i].a; ++len; } } } } } cout << area << endl; if (R == 1) continue; int max_x = xtag[xtag.size() - 1].a; for (int x = 0; x < max_x; ++x) { int depth = 0; int prevy = -1; for (int i = 0; i < ytag.size(); ++i) { if (ytag[i].b1 <= x && x < ytag[i].b2) { if (ytag[i].start) { if (depth == 0) { if (prevy != ytag[i].a) ++len; else --len; } ++depth; } else { if (--depth == 0) { ++len; prevy = ytag[i].a; } } } } } cout << len << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; struct Tag { int a; int b1, b2; bool start; Tag() : a(0), b1(0), b2(0), start(false) {} Tag(int aa, int bb1, int bb2, bool s) : a(aa), b1(bb1), b2(bb2), start(s) {} }; bool cmp(const Tag &t1, const Tag &t2) { if (t1.a != t2.a) return t1.a < t2.a; return !t1.start; } int main() { while (true) { int N, R; cin >> N >> R; if (!N && !R) break; vector<Tag> xtag, ytag; for (int i = 0; i < N; ++i) { int x1, y1, x2, y2; scanf("%d %d %d %d", &x1, &y1, &x2, &y2); xtag.push_back(Tag(x1, y1, y2, true)); xtag.push_back(Tag(x2, y1, y2, false)); ytag.push_back(Tag(y1, x1, x2, true)); ytag.push_back(Tag(y2, x1, x2, false)); } sort(xtag.begin(), xtag.end(), cmp); stable_sort(ytag.begin(), ytag.end(), cmp); int max_y = ytag[ytag.size() - 1].a; int area = 0; int len = 0; for (int y = 0; y < max_y; ++y) { int depth = 0; int startx = 0; int prevx = -1; for (int i = 0; i < xtag.size(); ++i) { if (xtag[i].b1 <= y && y < xtag[i].b2) { if (xtag[i].start) { if (depth == 0) { if (xtag[i].a != prevx) ++len; else --len; startx = xtag[i].a; } ++depth; } else { if (--depth == 0) { area += xtag[i].a - startx; prevx = xtag[i].a; ++len; } } } } } cout << area << endl; if (R == 1) continue; int max_x = xtag[xtag.size() - 1].a; for (int x = 0; x < max_x; ++x) { int depth = 0; int prevy = -1; for (int i = 0; i < ytag.size(); ++i) { if (ytag[i].b1 <= x && x < ytag[i].b2) { if (ytag[i].start) { if (depth == 0) { if (prevy != ytag[i].a) ++len; else --len; } ++depth; } else { if (--depth == 0) { ++len; prevy = ytag[i].a; } } } } } cout << len << endl; } return 0; }
replace
39
40
39
40
0
p00432
C++
Runtime Error
#include <iostream> #include <map> #include <vector> using namespace std; int dp[4001], p[4001]; typedef pair<int, pair<int, int>> Event; int main() { for (;;) { int n, r; cin >> n >> r; if (!(n || r)) return 0; map<int, vector<Event>> events; int mx = 0, c = 0, area = 0, circumference = 0; for (int i = 0; i < n; i++) { int sx, sy, ex, ey; cin >> sx >> sy >> ex >> ey; events[sy].push_back(make_pair(1, make_pair(sx, ex))); events[ey].push_back(make_pair(-1, make_pair(sx, ex))); mx = max(mx, ex); } fill(dp, dp + mx + 1, 0); fill(p, p + mx + 1, 0); for (map<int, vector<Event>>::iterator v = events.begin(); v != events.end(); ++v) { int count = 0, a = 0, b = 0; for (int i = 0; i < mx; i++) { if (dp[i]) { count++; if (dp[i + 1]) a++; if (p[i]) b++; } p[i] = dp[i]; } circumference += ((v->first - c) * (count - a) + count - b) * 2; area += (v->first - c) * count; c = v->first; for (vector<Event>::iterator e = v->second.begin(); e != v->second.end(); ++e) for (int i = e->second.first; i < e->second.second; i++) dp[i] += e->first; } /* fill(dp, dp+mx, 0); for (map<int, vector<Event> >::iterator v = events.begin(); v != events.end(); ++v) { int count = 0; for (int i = 0; i < mx; i++) if (dp[i]) count++; area += (v->first - c) * count; c = v->first; for (vector<Event>::iterator e = v->second.begin(); e != v->second.end(); ++e) for (int i = e->second.first; i < e->second.second; i++) dp[i] += e->first; for (int i = 0; i < mx; i++) cout << dp[i] << ' '; cout << endl; } */ cout << area << endl; if (r == 2) cout << circumference << endl; } }
#include <iostream> #include <map> #include <vector> using namespace std; int dp[10001], p[10001]; typedef pair<int, pair<int, int>> Event; int main() { for (;;) { int n, r; cin >> n >> r; if (!(n || r)) return 0; map<int, vector<Event>> events; int mx = 0, c = 0, area = 0, circumference = 0; for (int i = 0; i < n; i++) { int sx, sy, ex, ey; cin >> sx >> sy >> ex >> ey; events[sy].push_back(make_pair(1, make_pair(sx, ex))); events[ey].push_back(make_pair(-1, make_pair(sx, ex))); mx = max(mx, ex); } fill(dp, dp + mx + 1, 0); fill(p, p + mx + 1, 0); for (map<int, vector<Event>>::iterator v = events.begin(); v != events.end(); ++v) { int count = 0, a = 0, b = 0; for (int i = 0; i < mx; i++) { if (dp[i]) { count++; if (dp[i + 1]) a++; if (p[i]) b++; } p[i] = dp[i]; } circumference += ((v->first - c) * (count - a) + count - b) * 2; area += (v->first - c) * count; c = v->first; for (vector<Event>::iterator e = v->second.begin(); e != v->second.end(); ++e) for (int i = e->second.first; i < e->second.second; i++) dp[i] += e->first; } /* fill(dp, dp+mx, 0); for (map<int, vector<Event> >::iterator v = events.begin(); v != events.end(); ++v) { int count = 0; for (int i = 0; i < mx; i++) if (dp[i]) count++; area += (v->first - c) * count; c = v->first; for (vector<Event>::iterator e = v->second.begin(); e != v->second.end(); ++e) for (int i = e->second.first; i < e->second.second; i++) dp[i] += e->first; for (int i = 0; i < mx; i++) cout << dp[i] << ' '; cout << endl; } */ cout << area << endl; if (r == 2) cout << circumference << endl; } }
replace
6
7
6
7
0
p00433
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { while (true) { int a, b, c = 0, d = 0; for (int i = 0; i < 4; i++) { cin >> a; c = c + a; } for (int i = 0; i < 4; i++) { cin >> b; d = d + b; } if (c < d) cout << d << endl; else { cout << c << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int a, b, c = 0, d = 0; for (int i = 0; i < 4; i++) { cin >> a; c = c + a; } for (int i = 0; i < 4; i++) { cin >> b; d = d + b; } if (c < d) cout << d << endl; else { cout << c << endl; } return 0; }
replace
3
18
3
16
TLE
p00433
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() const int INF = 1 << 29; int main() { int v[] = {}; REP(i, 2) { REP(j, 4) { int a; cin >> a; v[i] += a; } } cout << max(v[0], v[1]) << endl; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() const int INF = 1 << 29; int main() { int v[4] = {}; REP(i, 2) { REP(j, 4) { int a; cin >> a; v[i] += a; } } cout << max(v[0], v[1]) << endl; }
replace
19
20
19
20
-6
*** stack smashing detected ***: terminated
p00434
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { int temp, a; int t[31]; t[temp] = 0; a = 0; for (int i = 0; i < 31; i++) { t[i] = 0; } for (int i = 0; i < 29; i++) { cin >> temp; t[temp] = 1; } for (temp = 1; temp <= 30; temp++) { if (t[temp] == 0) { cout << temp << endl; } } }
#include <iostream> using namespace std; int main(void) { int temp, a; int t[30]; a = 0; for (int i = 0; i < 31; i++) { t[i] = 0; } for (int i = 0; i < 29; i++) { cin >> temp; t[temp] = 1; } for (temp = 1; temp <= 30; temp++) { if (t[temp] == 0) { cout << temp << endl; } } }
replace
4
6
4
5
-11
p00434
C++
Runtime Error
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // #include <windows.h> #include <algorithm> #include <functional> #include <iostream> #include <queue> #include <set> using namespace std; typedef unsigned int uint; typedef long long int llint; typedef pair<llint, llint> pii; #define mpq(T) priority_queue<T, vector<T>, greater<T>> #define FOR(i, a, b) for (int i = (a), i < (b); i++) #define REP(i, a) for (int i = 0; i < (a); i++) class BIT { private: int s; llint *d; public: BIT(int size) { s = size; d = (llint *)malloc(sizeof(llint) * s); for (int i = 0; i < s; i++) { d[i] = 0; } } void add(int b, int x) { for (int i = b + 1; i <= s; i += (i & -i)) { d[i - 1] += x; } } llint sum(int b) { llint all = 0; for (int i = b + 1; i > 0; i -= (i & -i)) { all += d[i - 1]; } return all; } ~BIT() { free(d); } }; class unionfind { private: int s; int *o; int *r; public: unionfind(int dsize) { s = dsize; o = (int *)malloc(sizeof(int) * s); r = (int *)malloc(sizeof(int) * s); for (int i = 0; i < s; i++) { o[i] = i; r[i] = 0; } } int mfind(int b) { if (o[b] != b) { o[b] = mfind(o[b]); } return o[b]; } void munion(int a, int b) { int aw = mfind(a); int bw = mfind(b); if (aw == bw) { return; } if (r[aw] > r[bw]) { o[bw] = a; } else if (r[aw] < r[bw]) { o[aw] = bw; } else { o[bw] = aw; r[aw]++; } s--; } int size() { return s; } ~unionfind() { free(o); free(r); } }; template <class T> int lbound(T *d, T key, int s, int e) { s--; while (e - s > 1) { int m = (s + e) / 2; if (d[m] < key) { s = m; } else { e = m; } } return e; } template <class T> int ubound(T *d, T key, int s, int e) { s--; while (e - s > 1) { int m = (s + e) / 2; if (key < d[m]) { e = m; } else { s = m; } } return e; } class zpress { private: int ms; pii *md; int n; int s; llint *d; int *t; public: zpress(int dsize = 1000000) { int ms = dsize; md = (pii *)malloc(sizeof(pii) * ms); d = (llint *)malloc(sizeof(llint) * ms); t = (int *)malloc(sizeof(int) * ms); n = 0; } void in(llint x) { in2(x, n); n++; } void in2(llint x, int b) { md[b] = make_pair(x, b); } void syori() { syori2(n); } void syori2(int k) { sort(md, md + k); llint mae = LLONG_MIN; s = 0; REP(i, k) { if (md[i].first != mae) { d[s] = md[i].first; s++; mae = md[i].first; } t[md[i].second] = s - 1; } } llint iti(int b) { return t[b]; } int size() { return s; } int first(llint x) { return lbound(d, x, 0, s); } int end(llint x) { return ubound(d, x, 0, s); ; } ~zpress() { free(md); free(d); free(t); } }; class xorshift { private: unsigned int a, b, c, d; public: xorshift(unsigned int aw = 123456789, unsigned int bw = 362436069, unsigned int cw = 521288629, unsigned int dw = 88675123, unsigned int e = 97) { a = aw; b = bw; c = cw; d = dw; for (unsigned int i = 0; i < e; i++) { operator()(); } } unsigned int operator()() { unsigned int w = a ^ (a << 11); a = b; b = c; c = d; d = (d ^ (d >> 19)) ^ (w ^ (w >> 8)); return d; } }; llint gcd(llint a, llint b) { while (1) { llint w = a % b; if (w == 0) { return b; } a = b; b = w; } } llint sei(llint d, llint p) { if (d < 0) { d -= ((d + 1) / p - 1) * p; } else { d %= p; } return d; } llint inv(llint a, llint p) { llint r0 = sei(a, p); llint r1 = p; llint a0 = 1; llint b0 = 0; llint a1 = 0; llint b1 = 1; while (1) { llint q = r0 / r1; llint w = r0 - q * r1; if (w == 0) { break; } r0 = r1; r1 = w; w = a0 - q * a1; a0 = a1; a1 = w; } return sei(a1, p); } template <llint P> class mod { private: llint d; public: mod(llint a = 0) { d = a; d = sei(d, P); } mod operator-() const { return mod(P - d); } mod operator+=(const mod &a) { d = d + a.d; d = sei(d, P); return *this; } mod operator-=(const mod &a) { return operator+=(-a); } mod operator*=(const mod &a) { d = d * a.d; d = sei(d, P); return *this; } mod operator/=(const mod &a) { return a * mod(inv(d, P)); } mod operator+(const mod &a) const { mod w = *this; return (w += a); } mod operator-(const mod &a) const { mod w = *this; return (w -= a); } mod operator*(const mod &a) const { mod w = *this; return (w *= a); } mod operator/(const mod &a) const { mod w = *this; return (w /= a); } bool operator==(const mod &a) const { return (d == a.d); } bool operator!=(const mod &a) const { return (d != a.d); } operator llint() const { return d; } }; ///////////////////////////////////////////////////// FILE *fi; FILE *fo; void err(char *a) { printf("%s\n", a); getchar(); } llint in() { llint w; fscanf(fi, "%lld", &w); return w; } void ins(char *a) { fscanf(fi, "%s", a); } void out(llint a) { fprintf(fo, "%lld\n", a); } void outs(char *a) { fprintf(fo, "%s\n", a); } void func(); int main() { fi = stdin; fo = stdout; func(); return 0; } bool t[30]; void func() { fill(t, t + 39, true); REP(i, 28) { t[in() - 1] = false; } REP(i, 30) { if (t[i]) { out(i + 1); } } }
#include <limits.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // #include <windows.h> #include <algorithm> #include <functional> #include <iostream> #include <queue> #include <set> using namespace std; typedef unsigned int uint; typedef long long int llint; typedef pair<llint, llint> pii; #define mpq(T) priority_queue<T, vector<T>, greater<T>> #define FOR(i, a, b) for (int i = (a), i < (b); i++) #define REP(i, a) for (int i = 0; i < (a); i++) class BIT { private: int s; llint *d; public: BIT(int size) { s = size; d = (llint *)malloc(sizeof(llint) * s); for (int i = 0; i < s; i++) { d[i] = 0; } } void add(int b, int x) { for (int i = b + 1; i <= s; i += (i & -i)) { d[i - 1] += x; } } llint sum(int b) { llint all = 0; for (int i = b + 1; i > 0; i -= (i & -i)) { all += d[i - 1]; } return all; } ~BIT() { free(d); } }; class unionfind { private: int s; int *o; int *r; public: unionfind(int dsize) { s = dsize; o = (int *)malloc(sizeof(int) * s); r = (int *)malloc(sizeof(int) * s); for (int i = 0; i < s; i++) { o[i] = i; r[i] = 0; } } int mfind(int b) { if (o[b] != b) { o[b] = mfind(o[b]); } return o[b]; } void munion(int a, int b) { int aw = mfind(a); int bw = mfind(b); if (aw == bw) { return; } if (r[aw] > r[bw]) { o[bw] = a; } else if (r[aw] < r[bw]) { o[aw] = bw; } else { o[bw] = aw; r[aw]++; } s--; } int size() { return s; } ~unionfind() { free(o); free(r); } }; template <class T> int lbound(T *d, T key, int s, int e) { s--; while (e - s > 1) { int m = (s + e) / 2; if (d[m] < key) { s = m; } else { e = m; } } return e; } template <class T> int ubound(T *d, T key, int s, int e) { s--; while (e - s > 1) { int m = (s + e) / 2; if (key < d[m]) { e = m; } else { s = m; } } return e; } class zpress { private: int ms; pii *md; int n; int s; llint *d; int *t; public: zpress(int dsize = 1000000) { int ms = dsize; md = (pii *)malloc(sizeof(pii) * ms); d = (llint *)malloc(sizeof(llint) * ms); t = (int *)malloc(sizeof(int) * ms); n = 0; } void in(llint x) { in2(x, n); n++; } void in2(llint x, int b) { md[b] = make_pair(x, b); } void syori() { syori2(n); } void syori2(int k) { sort(md, md + k); llint mae = LLONG_MIN; s = 0; REP(i, k) { if (md[i].first != mae) { d[s] = md[i].first; s++; mae = md[i].first; } t[md[i].second] = s - 1; } } llint iti(int b) { return t[b]; } int size() { return s; } int first(llint x) { return lbound(d, x, 0, s); } int end(llint x) { return ubound(d, x, 0, s); ; } ~zpress() { free(md); free(d); free(t); } }; class xorshift { private: unsigned int a, b, c, d; public: xorshift(unsigned int aw = 123456789, unsigned int bw = 362436069, unsigned int cw = 521288629, unsigned int dw = 88675123, unsigned int e = 97) { a = aw; b = bw; c = cw; d = dw; for (unsigned int i = 0; i < e; i++) { operator()(); } } unsigned int operator()() { unsigned int w = a ^ (a << 11); a = b; b = c; c = d; d = (d ^ (d >> 19)) ^ (w ^ (w >> 8)); return d; } }; llint gcd(llint a, llint b) { while (1) { llint w = a % b; if (w == 0) { return b; } a = b; b = w; } } llint sei(llint d, llint p) { if (d < 0) { d -= ((d + 1) / p - 1) * p; } else { d %= p; } return d; } llint inv(llint a, llint p) { llint r0 = sei(a, p); llint r1 = p; llint a0 = 1; llint b0 = 0; llint a1 = 0; llint b1 = 1; while (1) { llint q = r0 / r1; llint w = r0 - q * r1; if (w == 0) { break; } r0 = r1; r1 = w; w = a0 - q * a1; a0 = a1; a1 = w; } return sei(a1, p); } template <llint P> class mod { private: llint d; public: mod(llint a = 0) { d = a; d = sei(d, P); } mod operator-() const { return mod(P - d); } mod operator+=(const mod &a) { d = d + a.d; d = sei(d, P); return *this; } mod operator-=(const mod &a) { return operator+=(-a); } mod operator*=(const mod &a) { d = d * a.d; d = sei(d, P); return *this; } mod operator/=(const mod &a) { return a * mod(inv(d, P)); } mod operator+(const mod &a) const { mod w = *this; return (w += a); } mod operator-(const mod &a) const { mod w = *this; return (w -= a); } mod operator*(const mod &a) const { mod w = *this; return (w *= a); } mod operator/(const mod &a) const { mod w = *this; return (w /= a); } bool operator==(const mod &a) const { return (d == a.d); } bool operator!=(const mod &a) const { return (d != a.d); } operator llint() const { return d; } }; ///////////////////////////////////////////////////// FILE *fi; FILE *fo; void err(char *a) { printf("%s\n", a); getchar(); } llint in() { llint w; fscanf(fi, "%lld", &w); return w; } void ins(char *a) { fscanf(fi, "%s", a); } void out(llint a) { fprintf(fo, "%lld\n", a); } void outs(char *a) { fprintf(fo, "%s\n", a); } void func(); int main() { fi = stdin; fo = stdout; func(); return 0; } bool t[30]; void func() { fill(t, t + 30, true); REP(i, 28) { t[in() - 1] = false; } REP(i, 30) { if (t[i]) { out(i + 1); } } }
replace
346
347
346
347
0
p00434
C++
Runtime Error
#include <stdio.h> #define N 10 int main(void) { int flg[N + 1]; int id; for (int i = 1; i <= N; i++) flg[i] = 0; while (scanf("%d", &id) != EOF) { flg[id] = 1; } for (int i = 1; i <= N; i++) { if (flg[i] == 0) printf("%d\n", i); } return 0; }
#include <stdio.h> #define N 30 int main(void) { int flg[N + 1]; int id; for (int i = 1; i <= N; i++) flg[i] = 0; while (scanf("%d", &id) != EOF) { flg[id] = 1; } for (int i = 1; i <= N; i++) { if (flg[i] == 0) printf("%d\n", i); } return 0; }
replace
1
2
1
2
-6
*** stack smashing detected ***: terminated
p00434
C++
Runtime Error
#include <iostream> #include <queue> using namespace std; int main(void) { // Your code here! int a, tf; queue<int> h; for (int i = 1; i <= 28; i++) { cin >> a; h.push(a); } for (int i = 1; i <= 30; i++) { tf = 0; for (int i2 = 1; i2 <= 28; i2++) { a = h.front(); h.pop(); if (i == a) { tf = 1; break; } else h.push(a); } if (tf == 0) cout << i << endl; } }
#include <iostream> #include <queue> using namespace std; int main(void) { // Your code here! int a, tf; queue<int> h; for (int i = 1; i <= 28; i++) { cin >> a; h.push(a); } for (int i = 1; i <= 30; i++) { tf = 0; for (int i2 = 1; i2 <= 28; i2++) { if (h.empty()) break; a = h.front(); h.pop(); if (i == a) { tf = 1; break; } else h.push(a); } if (tf == 0) cout << i << endl; } }
insert
14
14
14
16
0
p00435
C++
Runtime Error
#include <iostream> #include <stdio.h> using namespace std; int main() { int num; char a[100], b[100]; int i, j; for (i = 0;; i++) { scanf("%c", &a[i]); if (a[i] == '\n') { break; } if (a[i] >= 'A' && a[i] <= 'C') { b[i] = a[i] + 23; } else { b[i] = a[i] - 3; } printf("%c", b[i]); } cout << endl; return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main() { int num; char a[1000], b[1000]; int i, j; for (i = 0;; i++) { scanf("%c", &a[i]); if (a[i] == '\n') { break; } if (a[i] >= 'A' && a[i] <= 'C') { b[i] = a[i] + 23; } else { b[i] = a[i] - 3; } printf("%c", b[i]); } cout << endl; return 0; }
replace
5
6
5
6
0
p00435
C++
Runtime Error
#include <stdio.h> char *f(char *s) { char *a = s; for (; *s; s++) *s = (*s - 42) % 26 + 65; return a; } int main() { char *s; scanf("%s", s); printf("%s\n", f(s)); }
#include <stdio.h> char *f(char *s) { char *a = s; for (; *s; s++) *s = (*s - 42) % 26 + 65; return a; } int main() { char s[1001]; scanf("%s", s); printf("%s\n", f(s)); }
replace
10
11
10
11
0
p00435
C++
Time Limit Exceeded
#include <cstdio> using namespace std; int main() { while (true) { char a; scanf("%c", &a); if ('A' <= a && a <= 'Z') { a = (a + 23 - 'A') % 26 + 'A'; printf("%c", a); } else { printf("%c", a); } } return 0; }
#include <cstdio> using namespace std; int main() { while (true) { char a; scanf("%c", &a); if ('A' <= a && a <= 'Z') { a = (a + 23 - 'A') % 26 + 'A'; printf("%c", a); } else { printf("%c", a); break; } } return 0; }
insert
12
12
12
13
TLE
p00435
C++
Runtime Error
#include <cstdio> int main() { char a[1000]; scanf("%s", &a); for (int i = 0; a[i] != EOF; i++) a[i] = 'A' + ((a[i] - 'A' + 3) % 26); printf("%s", a); return 0; }
#include <cstdio> int main() { char c; while (1) { scanf("%c", &c); if (c == '\n') break; if (c < 'D') c = c + 26; printf("%c", c - 3); } printf("\n"); return 0; }
replace
3
8
3
13
0
p00435
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string str; cin >> str; int i; for (i = 0; i < str.size(); i++) { if (str[i] < 'D') str[i] = str[i] + 23; else str[i] = str[i] - 3; } for (i = 0; str.size(); i++) cout << str[i]; cout << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string str; cin >> str; int i; for (i = 0; i < str.size(); i++) { if (str[i] < 'D') str[i] = str[i] + 23; else str[i] = str[i] - 3; } cout << str << endl; return 0; }
replace
13
16
13
14
-11
p00436
C++
Runtime Error
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n, m; cin >> n >> m; vector<int> v(n); rep(i, 2 * n) v[i] = i + 1; rep(i, m) { int k; cin >> k; vector<int> a, b; if (k == 0) { rep(j, n) { a.push_back(v[j]); a.push_back(v[j + n]); } v.clear(); copy(a.begin(), a.end(), back_inserter(v)); } else { rep(j, k) { a.push_back(v[j]); } REP(j, k, 2 * n) { b.push_back(v[j]); } v.clear(); copy(b.begin(), b.end(), back_inserter(v)); copy(a.begin(), a.end(), back_inserter(v)); } } rep(i, 2 * n) { cout << v[i] << endl; } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1 << 30 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n, m; cin >> n >> m; vector<int> v(2 * n); rep(i, 2 * n) v[i] = i + 1; rep(i, m) { int k; cin >> k; vector<int> a, b; if (k == 0) { rep(j, n) { a.push_back(v[j]); a.push_back(v[j + n]); } v.clear(); copy(a.begin(), a.end(), back_inserter(v)); } else { rep(j, k) { a.push_back(v[j]); } REP(j, k, 2 * n) { b.push_back(v[j]); } v.clear(); copy(b.begin(), b.end(), back_inserter(v)); copy(a.begin(), a.end(), back_inserter(v)); } } rep(i, 2 * n) { cout << v[i] << endl; } return 0; }
replace
23
24
23
24
0
p00436
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, m, n; int i, j, k; int arr[100]; int arr2[100]; cin >> a; for (i = 0; i < 2 * a; i++) arr[i] = i + 1; cin >> m; for (i = 0; i < m; i++) { cin >> n; if (n == 0) { for (j = 0; j < a; j++) { arr2[j * 2] = arr[j]; arr2[j * 2 + 1] = arr[j + a]; } for (j = 0; j < a * 2; j++) arr[j] = arr2[j]; } else { for (j = n, k = 0; j < 2 * a; j++, k++) arr2[k] = arr[j]; for (j = 0; j < n; j++, k++) arr2[k] = arr[j]; for (j = 0; j < a * 2; j++) arr[j] = arr2[j]; } } for (i = 0; i < 2 * a; i++) cout << arr[i] << endl; return 0; }
#include <iostream> using namespace std; int main() { int a, m, n; int i, j, k; int arr[300]; int arr2[300]; cin >> a; for (i = 0; i < 2 * a; i++) arr[i] = i + 1; cin >> m; for (i = 0; i < m; i++) { cin >> n; if (n == 0) { for (j = 0; j < a; j++) { arr2[j * 2] = arr[j]; arr2[j * 2 + 1] = arr[j + a]; } for (j = 0; j < a * 2; j++) arr[j] = arr2[j]; } else { for (j = n, k = 0; j < 2 * a; j++, k++) arr2[k] = arr[j]; for (j = 0; j < n; j++, k++) arr2[k] = arr[j]; for (j = 0; j < a * 2; j++) arr[j] = arr2[j]; } } for (i = 0; i < 2 * a; i++) cout << arr[i] << endl; return 0; }
replace
8
10
8
10
0
p00436
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #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; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } 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 pb push_back #define mp make_pair #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 range(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) range(i, 0, n) #define clr(a, b) memset((a), (b), sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; const double eps = 1e-10; const double pi = acos(-1.0); const ll INF = 1LL << 62; const int inf = 1 << 29; void shufful(vi &cur, int q) { vi next; int n = cur.size(); next.resize(n); if (q) { rep(i, n - q) next[i] = cur[i + q]; rep(i, q) next[n - q + i] = cur[i]; } else { rep(i, n / 2) next[2 * i] = cur[i]; rep(i, n / 2) next[2 * i + 1] = cur[n / 2 + i]; } rep(i, 2 * n) cur[i] = next[i]; return; } int main(void) { int n; cin >> n; vi cur; rep(i, 2 * n) cur.pb(i + 1); int m; cin >> m; rep(i, m) { int q; cin >> q; shufful(cur, q); } rep(i, 2 * n) cout << cur[i] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #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; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } 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 pb push_back #define mp make_pair #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 range(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) range(i, 0, n) #define clr(a, b) memset((a), (b), sizeof(a)) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; const double eps = 1e-10; const double pi = acos(-1.0); const ll INF = 1LL << 62; const int inf = 1 << 29; void shufful(vi &cur, int q) { vi next; int n = cur.size(); next.resize(n); if (q) { rep(i, n - q) next[i] = cur[i + q]; rep(i, q) next[n - q + i] = cur[i]; } else { rep(i, n / 2) next[2 * i] = cur[i]; rep(i, n / 2) next[2 * i + 1] = cur[n / 2 + i]; } rep(i, n) cur[i] = next[i]; return; } int main(void) { int n; cin >> n; vi cur; rep(i, 2 * n) cur.pb(i + 1); int m; cin >> m; rep(i, m) { int q; cin >> q; shufful(cur, q); } rep(i, 2 * n) cout << cur[i] << endl; return 0; }
replace
76
77
76
77
-6
double free or corruption (!prev)
p00436
C++
Time Limit Exceeded
#include <iostream> #include <string> #include <vector> using namespace std; int main() { while (true) { cin; if (cin.fail()) break; } }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int a; cin >> a; vector<int> s(a * 2); for (int x = 0; x < a * 2; x++) { s[x] = x + 1; } int b; cin >> b; for (int c = 0; c < b; c++) { int d; cin >> d; vector<int> e(a * 2); for (int f = 0; f < a * 2; f++) { e[f] = s[f]; } if (d == 0) { for (int g = 0; g < a * 2; g++) { if (g % 2 == 0) { s[g] = e[g / 2]; } else { s[g] = e[a + (g - 1) / 2]; } } } else { for (int i = 0; i < 2 * a - d; i++) { s[i] = e[d + i]; } for (int i = 0; i < d; i++) { s[i + (2 * a - d)] = e[i]; } } } for (int q : s) { cout << q << endl; } }
replace
6
10
6
40
TLE
p00436
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int n; vector<int> card, t, m; void cut(int k) { for (int i = 1, j = 0; i <= k; i++, j++) t[j] = card[i]; for (int i = k + 1, j = 0; i <= 2 * n; i++, j++) m[j] = card[i]; for (int i = 1, j = 0; i <= 2 * n - k + 1; i++, j++) card[i] = m[j]; for (int i = 2 * n - k + 1, j = 0; i <= 2 * n; i++, j++) card[i] = t[j]; } void r_shuffle() { for (int i = 1; i <= n; i++) { t[i - 1] = card[i]; m[i - 1] = card[i + n]; } for (int i = 1, j = 0; i <= 2 * n; i += 2, j++) { card[i] = t[j]; card[i + 1] = m[j]; } } int main() { int h, k; cin >> n >> h; card.resize(2 * n + 1); t.resize(n + 1); m.resize(n + 1); for (int i = 1; i <= 2 * n; i++) card[i] = i; for (int i = 0; i < h; i++) { cin >> k; if (k == 0) r_shuffle(); else cut(k); } for (int i = 1; i <= n * 2; i++) cout << card[i] << endl; }
#include <iostream> #include <vector> using namespace std; int n; vector<int> card, t, m; void cut(int k) { for (int i = 1, j = 0; i <= k; i++, j++) t[j] = card[i]; for (int i = k + 1, j = 0; i <= 2 * n; i++, j++) m[j] = card[i]; for (int i = 1, j = 0; i <= 2 * n - k + 1; i++, j++) card[i] = m[j]; for (int i = 2 * n - k + 1, j = 0; i <= 2 * n; i++, j++) card[i] = t[j]; } void r_shuffle() { for (int i = 1; i <= n; i++) { t[i - 1] = card[i]; m[i - 1] = card[i + n]; } for (int i = 1, j = 0; i <= 2 * n; i += 2, j++) { card[i] = t[j]; card[i + 1] = m[j]; } } int main() { int h, k; cin >> n >> h; card.resize(1001); t.resize(512); m.resize(512); for (int i = 1; i <= 2 * n; i++) card[i] = i; for (int i = 0; i < h; i++) { cin >> k; if (k == 0) r_shuffle(); else cut(k); } for (int i = 1; i <= n * 2; i++) cout << card[i] << endl; }
replace
33
36
33
36
0
p00437
C++
Runtime Error
#include <cstdio> using namespace std; int main() { int a, b, c, n, total, kind; int rist[1000][3], ristsize; int isacheced[101]; scanf("%d %d %d", &a, &b, &c); while (a != 0 && b != 0 && c != 0) { scanf("%d", &n); total = a + b + c; ristsize = 0; for (int i = 0; i <= total; i++) { isacheced[i] = 2; } for (int i = 0; i < n; i++) { scanf("%d %d %d %d", &a, &b, &c, &kind); if (kind == 1) { isacheced[a] = 1; isacheced[b] = 1; isacheced[c] = 1; } else { rist[ristsize][0] = a; rist[ristsize][1] = b; rist[ristsize][2] = c; ristsize++; } } for (int i = 0; i < ristsize; i++) { if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][1]] == 1) { isacheced[rist[i][2]] = 0; } else if (isacheced[rist[i][1]] == 1 && isacheced[rist[i][2]] == 1) { isacheced[rist[i][0]] = 0; } else if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][2]] == 1) { isacheced[rist[i][1]] = 0; } } for (int i = 1; i <= total; i++) { printf("%d\n", isacheced[i]); } scanf("%d %d %d", &a, &b, &c); } return 0; }
#include <cstdio> using namespace std; int main() { int a, b, c, n, total, kind; int rist[1000][3], ristsize; int isacheced[301]; scanf("%d %d %d", &a, &b, &c); while (a != 0 && b != 0 && c != 0) { scanf("%d", &n); total = a + b + c; ristsize = 0; for (int i = 0; i <= total; i++) { isacheced[i] = 2; } for (int i = 0; i < n; i++) { scanf("%d %d %d %d", &a, &b, &c, &kind); if (kind == 1) { isacheced[a] = 1; isacheced[b] = 1; isacheced[c] = 1; } else { rist[ristsize][0] = a; rist[ristsize][1] = b; rist[ristsize][2] = c; ristsize++; } } for (int i = 0; i < ristsize; i++) { if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][1]] == 1) { isacheced[rist[i][2]] = 0; } else if (isacheced[rist[i][1]] == 1 && isacheced[rist[i][2]] == 1) { isacheced[rist[i][0]] = 0; } else if (isacheced[rist[i][0]] == 1 && isacheced[rist[i][2]] == 1) { isacheced[rist[i][1]] = 0; } } for (int i = 1; i <= total; i++) { printf("%d\n", isacheced[i]); } scanf("%d %d %d", &a, &b, &c); } return 0; }
replace
7
8
7
8
0
p00437
C++
Runtime Error
#include <cstring> #include <iostream> int main() { int a, b, c; int N; while (std::cin >> a >> b >> c, a | b | c) { std::cin >> N; int data[1024][4]; int check[128]; for (int i = 0; i < 101; i++) check[i] = 2; for (int i = 0; i < N; i++) { scanf("%d%d%d%d", &data[i][0], &data[i][1], &data[i][2], &data[i][3]); if (data[i][3] == 1) { check[data[i][0]] = 1; check[data[i][1]] = 1; check[data[i][2]] = 1; } } for (int i = 0; i < N; i++) { if (data[i][3] == 0) { int sum = 0; if (check[data[i][0]] == 1) sum++; if (check[data[i][1]] == 1) sum++; if (check[data[i][2]] == 1) sum++; if (sum == 2) { for (int j = 0; j < 3; j++) { if (check[data[i][j]] != 1) check[data[i][j]] = 0; } } } } for (int i = 0; i < a + b + c; i++) { printf("%d\n", check[i + 1]); } } return 0; }
#include <cstring> #include <iostream> int main() { int a, b, c; int N; while (std::cin >> a >> b >> c, a | b | c) { std::cin >> N; int data[1024][4]; int check[301]; for (int i = 0; i < 301; i++) check[i] = 2; for (int i = 0; i < N; i++) { scanf("%d%d%d%d", &data[i][0], &data[i][1], &data[i][2], &data[i][3]); if (data[i][3] == 1) { check[data[i][0]] = 1; check[data[i][1]] = 1; check[data[i][2]] = 1; } } for (int i = 0; i < N; i++) { if (data[i][3] == 0) { int sum = 0; if (check[data[i][0]] == 1) sum++; if (check[data[i][1]] == 1) sum++; if (check[data[i][2]] == 1) sum++; if (sum == 2) { for (int j = 0; j < 3; j++) { if (check[data[i][j]] != 1) check[data[i][j]] = 0; } } } } for (int i = 0; i < a + b + c; i++) { printf("%d\n", check[i + 1]); } } return 0; }
replace
8
10
8
10
0
p00437
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define each(itr, c) \ for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second int main() { int a, b, c; while (cin >> a >> b >> c, a | b | c) { int n; cin >> n; //??¨???????¨????????????° int m = a + b + c; //???????????????????????? vector<int> v(m, 2); vector<int> x(m), y(m), z(m), r(m); rep(i, n) { scanf(" %d %d %d %d", &x[i], &y[i], &z[i], &r[i]); --x[i]; --y[i]; --z[i]; } //????????£?????????????????????????????????????????¨?????£??? rep(i, n) { if (r[i] == 0) continue; v[x[i]] = 1; v[y[i]] = 1; v[z[i]] = 1; } //?????????????????????????????? rep(t, n) rep(i, n) { if (r[i] == 1) continue; //??????2????????£???(1)??§?¢??????????????????°???????????????(0) if (v[x[i]] == 1 && v[y[i]] == 1) v[z[i]] = 0; if (v[y[i]] == 1 && v[z[i]] == 1) v[x[i]] = 0; if (v[z[i]] == 1 && v[x[i]] == 1) v[y[i]] = 0; } // output rep(i, m) printf("%d\n", v[i]); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define each(itr, c) \ for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second int main() { int a, b, c; while (cin >> a >> b >> c, a | b | c) { int n; cin >> n; //??¨???????¨????????????° int m = a + b + c; //???????????????????????? vector<int> v(m, 2); vector<int> x(n), y(n), z(n), r(n); rep(i, n) { scanf(" %d %d %d %d", &x[i], &y[i], &z[i], &r[i]); --x[i]; --y[i]; --z[i]; } //????????£?????????????????????????????????????????¨?????£??? rep(i, n) { if (r[i] == 0) continue; v[x[i]] = 1; v[y[i]] = 1; v[z[i]] = 1; } //?????????????????????????????? rep(t, n) rep(i, n) { if (r[i] == 1) continue; //??????2????????£???(1)??§?¢??????????????????°???????????????(0) if (v[x[i]] == 1 && v[y[i]] == 1) v[z[i]] = 0; if (v[y[i]] == 1 && v[z[i]] == 1) v[x[i]] = 0; if (v[z[i]] == 1 && v[x[i]] == 1) v[y[i]] = 0; } // output rep(i, m) printf("%d\n", v[i]); } return 0; }
replace
24
25
24
25
0
p00437
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main(void) { int a, b, c, n; while (cin >> a >> b >> c >> n, a + b + c + n) { vector<int> in(a + b + c + 1, 2); vector<vector<int>> jud(n, vector<int>(4, 0)); for (int l = 0; l < n; l++) { int i, j, k, r; cin >> i >> j >> k >> r; if (r == 1) { in[i] = in[j] = in[k] = 1; } jud[l][0] = i; jud[l][1] = j; jud[l][2] = k; jud[l][3] = r; } for (int i = 0; i < jud.size(); i++) { if (jud[i][3] == 0) { if (in[jud[i][0]] == 1 && in[jud[i][1]] == 1) in[jud[i][2]] = 0; if (in[jud[i][2]] == 1 && in[jud[i][0]] == 1) in[jud[i][1]] = 0; if (in[jud[i][2]] == 1 && in[jud[i][1]] == 1) in[jud[i][0]] = 0; } } for (int i = 1; i < in.size(); i++) cout << in[i] << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main(void) { int a, b, c, n; while (cin >> a >> b >> c, a + b + c) { cin >> n; vector<int> in(a + b + c + 1, 2); vector<vector<int>> jud(n, vector<int>(4, 0)); for (int l = 0; l < n; l++) { int i, j, k, r; cin >> i >> j >> k >> r; if (r == 1) { in[i] = in[j] = in[k] = 1; } jud[l][0] = i; jud[l][1] = j; jud[l][2] = k; jud[l][3] = r; } for (int i = 0; i < jud.size(); i++) { if (jud[i][3] == 0) { if (in[jud[i][0]] == 1 && in[jud[i][1]] == 1) in[jud[i][2]] = 0; if (in[jud[i][2]] == 1 && in[jud[i][0]] == 1) in[jud[i][1]] = 0; if (in[jud[i][2]] == 1 && in[jud[i][1]] == 1) in[jud[i][0]] = 0; } } for (int i = 1; i < in.size(); i++) cout << in[i] << endl; } return 0; }
replace
7
8
7
9
TLE
p00437
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define loop(i, n) for (int i = 1; i <= n; i++) struct test { int i, j, k; }; vector<test> t; int p[302]; int main() { int a, b, c, n, i, j, k, r; while (cin >> a >> b >> c) { cin >> n; t.clear(); loop(i, a + b + c) p[i] = 2; loop(h, n) { cin >> i >> j >> k >> r; if (r == 1) { p[h] = p[h] = p[h] = 1; } else { t.push_back({i, j, k}); } } for (int h = 0; h < t.size(); h++) { i = t[h].i; j = t[h].j; k = t[h].k; if (p[i] == 1 && p[j] == 1) { p[k] = 0; } else if (p[j] == 1 && p[k] == 1) { p[i] = 0; } else if (p[k] == 1 && p[i] == 1) { p[j] = 0; } } loop(i, a + b + c) cout << p[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define loop(i, n) for (int i = 1; i <= n; i++) struct test { int i, j, k; }; vector<test> t; int p[302]; int main() { int a, b, c, n, i, j, k, r; while (cin >> a >> b >> c) { cin >> n; t.clear(); loop(i, a + b + c) p[i] = 2; loop(h, n) { cin >> i >> j >> k >> r; if (r == 1) { p[i] = p[j] = p[k] = 1; } else { t.push_back({i, j, k}); } } for (int h = 0; h < t.size(); h++) { i = t[h].i; j = t[h].j; k = t[h].k; if (p[i] == 1 && p[j] == 1) { p[k] = 0; } else if (p[j] == 1 && p[k] == 1) { p[i] = 0; } else if (p[k] == 1 && p[i] == 1) { p[j] = 0; } } loop(i, a + b + c) cout << p[i] << endl; } return 0; }
replace
20
21
20
21
0
p00437
C++
Runtime Error
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = b; a < c; a++) using namespace std; int con[1001 * 2]; int an[1001]; int ans[1001]; int main() { while (1) { rep(i, 0, 1001) ans[i] = 2; int a, b, c; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; int n; cin >> n; rep(i, 0, n) { // int x,y,z,an; cin >> con[i] >> con[n + i] >> con[n * 2 + i] >> an[i]; // x--;y--;z--; // cout << i << a+i << a+b+i << endl; if (an[i] == 1) { ans[con[i]] = 1; ans[con[n + i]] = 1; ans[con[n * 2 + i]] = 1; } } rep(i, 0, n) { // cout << con[i] << con[i+n] << con[i+n+2] << endl; if (an[i] == 0) if (ans[con[i]] == 1 && ans[con[n + i]] == 1 && ans[con[n * 2 + i]] == 2) { ans[con[i + n * 2]] = 0; } if (an[i] == 0) if (ans[con[i]] == 1 && ans[con[n + i]] == 2 && ans[con[n * 2 + i]] == 1) { ans[con[i + n]] = 0; } if (an[i] == 0) if (ans[con[i]] == 2 && ans[con[n + i]] == 1 && ans[con[n * 2 + i]] == 1) { ans[con[i]] = 0; } } rep(i, 1, a + b + c + 1) { cout << ans[i] << endl; } } return 0; }
#include <bits/stdc++.h> #define rep(a, b, c) for (int a = b; a < c; a++) using namespace std; int con[3003]; int an[1001]; int ans[1001]; int main() { while (1) { rep(i, 0, 1001) ans[i] = 2; int a, b, c; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; int n; cin >> n; rep(i, 0, n) { // int x,y,z,an; cin >> con[i] >> con[n + i] >> con[n * 2 + i] >> an[i]; // x--;y--;z--; // cout << i << a+i << a+b+i << endl; if (an[i] == 1) { ans[con[i]] = 1; ans[con[n + i]] = 1; ans[con[n * 2 + i]] = 1; } } rep(i, 0, n) { // cout << con[i] << con[i+n] << con[i+n+2] << endl; if (an[i] == 0) if (ans[con[i]] == 1 && ans[con[n + i]] == 1 && ans[con[n * 2 + i]] == 2) { ans[con[i + n * 2]] = 0; } if (an[i] == 0) if (ans[con[i]] == 1 && ans[con[n + i]] == 2 && ans[con[n * 2 + i]] == 1) { ans[con[i + n]] = 0; } if (an[i] == 0) if (ans[con[i]] == 2 && ans[con[n + i]] == 1 && ans[con[n * 2 + i]] == 1) { ans[con[i]] = 0; } } rep(i, 1, a + b + c + 1) { cout << ans[i] << endl; } } return 0; }
replace
3
4
3
4
0
p00437
C++
Runtime Error
#include <iostream> using namespace std; int ans[500]; int a, b, c, N; int r[1000], x[1000], y[1000], z[1000]; void init() { for (int i = 0; i < 2000; i++) ans[i] = 2; } int main() { while (cin >> a >> b >> c && a && b && c) { init(); cin >> N; for (int i = 0; i < N; i++) { cin >> x[i] >> y[i] >> z[i] >> r[i]; if (r[i] == 1) ans[x[i]] = 1, ans[y[i]] = 1, ans[z[i]] = 1; } for (int i = 0; i < N; i++) { if (r[i] == 1) continue; if (ans[x[i]] == 1 && ans[y[i]] == 1) ans[z[i]] = 0; if (ans[y[i]] == 1 && ans[z[i]] == 1) ans[x[i]] = 0; if (ans[z[i]] == 1 && ans[x[i]] == 1) ans[y[i]] = 0; } for (int i = 1; i <= a + b + c; i++) { cout << ans[i] << endl; } } return 0; }
#include <iostream> using namespace std; int ans[500]; int a, b, c, N; int r[1000], x[1000], y[1000], z[1000]; void init() { for (int i = 0; i < 500; i++) ans[i] = 2; } int main() { while (cin >> a >> b >> c && a && b && c) { init(); cin >> N; for (int i = 0; i < N; i++) { cin >> x[i] >> y[i] >> z[i] >> r[i]; if (r[i] == 1) ans[x[i]] = 1, ans[y[i]] = 1, ans[z[i]] = 1; } for (int i = 0; i < N; i++) { if (r[i] == 1) continue; if (ans[x[i]] == 1 && ans[y[i]] == 1) ans[z[i]] = 0; if (ans[y[i]] == 1 && ans[z[i]] == 1) ans[x[i]] = 0; if (ans[z[i]] == 1 && ans[x[i]] == 1) ans[y[i]] = 0; } for (int i = 1; i <= a + b + c; i++) { cout << ans[i] << endl; } } return 0; }
replace
6
7
6
7
0
p00437
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { while (true) { int parts[301], d[301][3], g[1000]; int a, b, c, N; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; cin >> N; for (int i = 1; i <= a + b + c; i++) { parts[i] = 2; } for (int i = 0; i < N; i++) { cin >> d[i][0] >> d[i][1] >> d[i][2] >> g[i]; if (g[i] == 1) { for (int j = 0; j < 3; j++) parts[d[i][j]] = 1; } } for (int i = 0; i < N; i++) { if (g[i] == 0) { for (int j = 0; j < 3; j++) { if (parts[d[i][(j + 1) % 3]] == 1 && parts[d[i][(j + 2) % 3]] == 1) parts[d[i][j]] = 0; } } } for (int i = 1; i <= a + b + c; i++) { cout << parts[i] << endl; } } return 0; }
#include <iostream> using namespace std; int main() { while (true) { int parts[301], d[1000][3], g[1000]; int a, b, c, N; cin >> a >> b >> c; if (a == 0 && b == 0 && c == 0) break; cin >> N; for (int i = 1; i <= a + b + c; i++) { parts[i] = 2; } for (int i = 0; i < N; i++) { cin >> d[i][0] >> d[i][1] >> d[i][2] >> g[i]; if (g[i] == 1) { for (int j = 0; j < 3; j++) parts[d[i][j]] = 1; } } for (int i = 0; i < N; i++) { if (g[i] == 0) { for (int j = 0; j < 3; j++) { if (parts[d[i][(j + 1) % 3]] == 1 && parts[d[i][(j + 2) % 3]] == 1) parts[d[i][j]] = 0; } } } for (int i = 1; i <= a + b + c; i++) { cout << parts[i] << endl; } } return 0; }
replace
4
5
4
5
TLE
p00437
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; vector<int> ans; bool check(vector<int> v) { int count = 0, no; for (int i = 0; i < 3; ++i) if (ans[v[i]] != 1) { no = v[i]; ++count; } if (count > 1) return false; else if (count == 0) { cout << "ERROR" << endl; return false; } else ans[no] = 0; return true; } vector<int> make_result(int a, int b, int c, int r) { vector<int> ret; ret.push_back(a); ret.push_back(b); ret.push_back(c); ret.push_back(r); return ret; } int main() { int a, b, c; while (cin >> a >> b >> c, a || b || c) { int n = a + b + c; int N; cin >> N; ans.erase(ans.begin(), ans.end()); for (int i = 0; i < n; ++i) ans.push_back(2); vector<vector<int>> results; for (int i = 0; i < N; ++i) { int r; cin >> a >> b >> c >> r; --a, --b, --c; if (r == 1) ans[a] = ans[b] = ans[c] = 1; else results.push_back(make_result(a, b, c, r)); } while (1) { bool update = false; for (int i = 0; i < results.size(); ++i) if (update = check(results[i])) results.erase(results.begin() + i, results.begin() + i); if (!update) break; } for (int i = 0; i < n; ++i) cout << ans[i] << endl; } }
#include <iostream> #include <vector> using namespace std; vector<int> ans; bool check(vector<int> v) { int count = 0, no; for (int i = 0; i < 3; ++i) if (ans[v[i]] != 1) { no = v[i]; ++count; } if (count > 1) return false; else if (count == 0) { cout << "ERROR" << endl; return false; } else ans[no] = 0; return true; } vector<int> make_result(int a, int b, int c, int r) { vector<int> ret; ret.push_back(a); ret.push_back(b); ret.push_back(c); ret.push_back(r); return ret; } int main() { int a, b, c; while (cin >> a >> b >> c, a || b || c) { int n = a + b + c; int N; cin >> N; ans.erase(ans.begin(), ans.end()); for (int i = 0; i < n; ++i) ans.push_back(2); vector<vector<int>> results; for (int i = 0; i < N; ++i) { int r; cin >> a >> b >> c >> r; --a, --b, --c; if (r == 1) ans[a] = ans[b] = ans[c] = 1; else results.push_back(make_result(a, b, c, r)); } bool update = false; for (int i = 0; i < results.size(); ++i) if (update = check(results[i])) results.erase(results.begin() + i, results.begin() + i); for (int i = 0; i < n; ++i) cout << ans[i] << endl; } }
replace
62
71
62
66
TLE
p00437
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = 1; i <= n; i++) #define drep(i, n) for (int i = n; i >= 0; i--) #define INF 100000005 #define MAX 100001 #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; //__gcd(a,b), __builtin_popcount(a); int a[1000][4]; int b[302]; int main() { int x, y, z, n, t; while (1) { scanf("%d%d%d", &x, &y, &z); scanf("%d", &n); fill(b, b + 302, 2); for (int i = 0; i < n; i++) { scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]); if (a[i][3]) b[a[i][0]] = b[a[i][1]] = b[a[i][2]] = 1; } for (int i = 0; i < n; i++) { t = 0; if (a[i][3] == 0) { rep(j, 3) if (b[a[i][j]] == 1) t++; if (t == 2) rep(j, 3) if (b[a[i][j]] == 2) b[a[i][j]] = 0; } } rrep(i, x + y + z) printf("%d\n", b[i]); } return 0; }
#include <bits/stdc++.h> #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = 1; i <= n; i++) #define drep(i, n) for (int i = n; i >= 0; i--) #define INF 100000005 #define MAX 100001 #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; //__gcd(a,b), __builtin_popcount(a); int a[1000][4]; int b[302]; int main() { int x, y, z, n, t; while (1) { scanf("%d%d%d", &x, &y, &z); if (!x && !y && !z) break; scanf("%d", &n); fill(b, b + 302, 2); for (int i = 0; i < n; i++) { scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]); if (a[i][3]) b[a[i][0]] = b[a[i][1]] = b[a[i][2]] = 1; } for (int i = 0; i < n; i++) { t = 0; if (a[i][3] == 0) { rep(j, 3) if (b[a[i][j]] == 1) t++; if (t == 2) rep(j, 3) if (b[a[i][j]] == 2) b[a[i][j]] = 0; } } rrep(i, x + y + z) printf("%d\n", b[i]); } return 0; }
insert
20
20
20
22
TLE
p00437
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b, c; while (cin >> a >> b >> c, a, b, c) { int q[350]; for (int i = 0; i < a + b + c; i++) q[i] = 2; int n; cin >> n; int z = 0; int ls[350][3]; for (int i = 0; i < n; i++) { int d, e, f, g; cin >> d >> e >> f >> g; if (g == 0) { ls[z][0] = d; ls[z][1] = e; ls[z][2] = f; z++; } else { q[d - 1] = 1; q[e - 1] = 1; q[f - 1] = 1; } } for (int i = 0; i < z; i++) { int d = 0, e = 0, f = 0; if (q[ls[i][0] - 1] == 1) d = 1; if (q[ls[i][1] - 1] == 1) e = 1; if (q[ls[i][2] - 1] == 1) f = 1; if (d == 1 && e == 1) { q[ls[i][2] - 1] = 0; } if (d == 1 && f == 1) { q[ls[i][1] - 1] = 0; } if (e == 1 && f == 1) { q[ls[i][0] - 1] = 0; } } for (int i = 0; i < a + b + c; i++) { cout << q[i] << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int a, b, c; while (cin >> a >> b >> c, a, b, c) { int q[350]; for (int i = 0; i < a + b + c; i++) q[i] = 2; int n; cin >> n; int z = 0; int ls[1200][5]; for (int i = 0; i < n; i++) { int d, e, f, g; cin >> d >> e >> f >> g; if (g == 0) { ls[z][0] = d; ls[z][1] = e; ls[z][2] = f; z++; } else { q[d - 1] = 1; q[e - 1] = 1; q[f - 1] = 1; } } for (int i = 0; i < z; i++) { int d = 0, e = 0, f = 0; if (q[ls[i][0] - 1] == 1) d = 1; if (q[ls[i][1] - 1] == 1) e = 1; if (q[ls[i][2] - 1] == 1) f = 1; if (d == 1 && e == 1) { q[ls[i][2] - 1] = 0; } if (d == 1 && f == 1) { q[ls[i][1] - 1] = 0; } if (e == 1 && f == 1) { q[ls[i][0] - 1] = 0; } } for (int i = 0; i < a + b + c; i++) { cout << q[i] << endl; } } return 0; }
replace
13
14
13
14
0
p00437
C++
Runtime Error
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> constexpr int MOD = 1000000007; constexpr int INF = 2000000000; using namespace std; int main() { int a, b, c; int A[101], B[101], C[101], D[101]; int ans[301]; int n; while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) { cin >> n; for (int i = 1; i <= a + b + c; i++) { ans[i] = 2; } for (int i = 0; i < n; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i]; if (D[i] == 1) { ans[A[i]] = ans[B[i]] = ans[C[i]] = 1; } } for (int i = 0; i < n; i++) { if (D[i] == 0) { if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1) ans[A[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1) ans[B[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2) ans[C[i]] = 0; } } for (int i = 1; i <= a + b + c; i++) cout << ans[i] << endl; } }
#include <algorithm> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> constexpr int MOD = 1000000007; constexpr int INF = 2000000000; using namespace std; int main() { int a, b, c; int A[1001], B[1001], C[1001], D[1001]; int ans[10001]; int n; while (cin >> a >> b >> c && a != 0 && b != 0 && c != 0) { cin >> n; for (int i = 1; i <= a + b + c; i++) { ans[i] = 2; } for (int i = 0; i < n; i++) { cin >> A[i] >> B[i] >> C[i] >> D[i]; if (D[i] == 1) { ans[A[i]] = ans[B[i]] = ans[C[i]] = 1; } } for (int i = 0; i < n; i++) { if (D[i] == 0) { if (ans[A[i]] == 2 && ans[B[i]] == 1 && ans[C[i]] == 1) ans[A[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 2 && ans[C[i]] == 1) ans[B[i]] = 0; if (ans[A[i]] == 1 && ans[B[i]] == 1 && ans[C[i]] == 2) ans[C[i]] = 0; } } for (int i = 1; i <= a + b + c; i++) cout << ans[i] << endl; } }
replace
19
21
19
21
0
p00438
C++
Runtime Error
#include <iostream> using namespace std; int a, b, n; struct cross { bool isbuilding; int access; }; cross map[16][16]; void read() { cin >> n; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { map[i][j].isbuilding = false; map[i][j].access = 0; } } for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; x--; y--; map[x][y].isbuilding = true; } map[0][0].access = 1; return; } void dp_a(int crossa, int crossb) { if (crossa + 1 == a) { return; } if (map[crossa + 1][crossb].isbuilding) { return; } map[crossa + 1][crossb].access += map[crossa][crossb].access; return; } void dp_b(int crossa, int crossb) { if (crossb + 1 == b) { return; } if (map[crossa][crossb + 1].isbuilding) { return; } map[crossa][crossb + 1].access += map[crossa][crossb].access; return; } void solve() { for (int i = 0; i < a + b - 2; i++) { int times; if (i < (a < b) ? a : b) { times = i + 1; } else if (i <= (a > b) ? a : b) { times = (a < b) ? a : b; } else { times = a + b - i - 1; } for (int j = 0; j < times; j++) { dp_a(j, i - j); dp_b(j, i - j); } } return; } int main() { while (1) { cin >> a >> b; if (!a && !b) { break; } read(); solve(); cout << map[a - 1][b - 1].access << endl; } return 0; }
#include <iostream> using namespace std; int a, b, n; struct cross { bool isbuilding; int access; }; cross map[100][100]; void read() { cin >> n; for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { map[i][j].isbuilding = false; map[i][j].access = 0; } } for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; x--; y--; map[x][y].isbuilding = true; } map[0][0].access = 1; return; } void dp_a(int crossa, int crossb) { if (crossa + 1 == a) { return; } if (map[crossa + 1][crossb].isbuilding) { return; } map[crossa + 1][crossb].access += map[crossa][crossb].access; return; } void dp_b(int crossa, int crossb) { if (crossb + 1 == b) { return; } if (map[crossa][crossb + 1].isbuilding) { return; } map[crossa][crossb + 1].access += map[crossa][crossb].access; return; } void solve() { for (int i = 0; i < a + b - 2; i++) { int times; if (i < (a < b) ? a : b) { times = i + 1; } else if (i <= (a > b) ? a : b) { times = (a < b) ? a : b; } else { times = a + b - i - 1; } for (int j = 0; j < times; j++) { dp_a(j, i - j); dp_b(j, i - j); } } return; } int main() { while (1) { cin >> a >> b; if (!a && !b) { break; } read(); solve(); cout << map[a - 1][b - 1].access << endl; } return 0; }
replace
8
9
8
9
0
p00438
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int main() { int a, b, x, y; while (std::cin >> a >> b) { if (a == 0 && b == 0) { break; } std::vector<std::vector<int>> road(a, std::vector<int>(b, 1)); int num = 0; std::cin >> num; for (int i = 0; i < num; ++i) { std::cin >> x >> y; road.at(x).at(y) = 0; } for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) { // start point & point under construction if (road.at(i).at(j) != 0 && (i + j) != 0) { if (i == 0) { if (road.at(i).at(j - 1) != 0) { road.at(i).at(j) = road.at(i).at(j - 1); } else { road.at(i).at(j) = 0; } } else if (j == 0) { if (road.at(i - 1).at(j) != 0) { road.at(i).at(j) = road.at(i - 1).at(j); } else { road.at(i).at(j) = 0; } } else { road.at(i).at(j) = road.at(i).at(j - 1) + road.at(i - 1).at(j); } } } } std::cout << road.at(a - 1).at(b - 1) << std::endl; } }
#include <algorithm> #include <iostream> #include <vector> int main() { int a, b, x, y; while (std::cin >> a >> b) { if (a == 0 && b == 0) { break; } std::vector<std::vector<int>> road(a, std::vector<int>(b, 1)); int num = 0; std::cin >> num; for (int i = 0; i < num; ++i) { std::cin >> x >> y; road.at(x - 1).at(y - 1) = 0; } for (int i = 0; i < a; ++i) { for (int j = 0; j < b; ++j) { // start point & point under construction if (road.at(i).at(j) != 0 && (i + j) != 0) { if (i == 0) { if (road.at(i).at(j - 1) != 0) { road.at(i).at(j) = road.at(i).at(j - 1); } else { road.at(i).at(j) = 0; } } else if (j == 0) { if (road.at(i - 1).at(j) != 0) { road.at(i).at(j) = road.at(i - 1).at(j); } else { road.at(i).at(j) = 0; } } else { road.at(i).at(j) = road.at(i).at(j - 1) + road.at(i - 1).at(j); } } } } std::cout << road.at(a - 1).at(b - 1) << std::endl; } }
replace
20
21
20
21
0
p00438
C++
Runtime Error
#include <iostream> #include <vector> int main() { while (1) { int a, b; std::cin >> a >> b; if (a == 0 && b == 0) break; int n; std::cin >> n; std::vector<std::vector<int>> dp(a, std::vector<int>(b, 0)); for (int i = 0; i != n; ++i) { int c, d; std::cin >> c >> d; dp[c - 1][d - 1] = -1; } for (int i = 0; i != a; ++i) { for (int j = 0; j != b; ++j) { if (i == 0 && j == 0) dp[i][j] = 1; else if (dp[i][j] != -1) { if (i == 0 && dp[i][j - 1] != -1) dp[i][j] = dp[i][j - 1]; else if (j == 0 && dp[i - 1][j] != -1) dp[i][j] = dp[i - 1][j]; else if (dp[i - 1][j] != -1 && dp[i][j - 1] != -1) dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; else if (dp[i - 1][j] != -1) dp[i][j] = dp[i - 1][j]; else if (dp[i][j - 1] != -1) dp[i][j] = dp[i][j - 1]; } } } std::cout << dp[a - 1][b - 1] << std::endl; } return 0; }
#include <iostream> #include <vector> int main() { while (1) { int a, b; std::cin >> a >> b; if (a == 0 && b == 0) break; int n; std::cin >> n; std::vector<std::vector<int>> dp(a, std::vector<int>(b, 0)); for (int i = 0; i != n; ++i) { int c, d; std::cin >> c >> d; dp[c - 1][d - 1] = -1; } for (int i = 0; i != a; ++i) { for (int j = 0; j != b; ++j) { if (i == 0 && j == 0) dp[i][j] = 1; else if (dp[i][j] != -1) { if (i != 0 && dp[i - 1][j] != -1) { dp[i][j] += dp[i - 1][j]; } if (j != 0 && dp[i][j - 1] != -1) { dp[i][j] += dp[i][j - 1]; } } } } std::cout << dp[a - 1][b - 1] << std::endl; } return 0; }
replace
25
35
25
31
0
p00438
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // 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); const int DX[] = {0, 1, 0, -1}; const int DY[] = {-1, 0, 1, 0}; // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); string a; LL b; cin >> a >> b; LL length = a.length(); LL d = (b % length); d = d > 0 ? d - 1 : length - 1; dump(d); cout << a[d] << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // 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); const int DX[] = {0, 1, 0, -1}; const int DY[] = {-1, 0, 1, 0}; // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; int main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); int width, height, n; while (true) { cin >> width >> height; if (width == 0 && height == 0) { break; } cin >> n; vector<PII> bad(n); VVI table(height, VI(width)); REP(i, n) { int x, y; cin >> x >> y; x--; y = height - y; table[y][x] = -1; } table[height - 1][0] = 1; int value; for (int y = height - 1; y >= 0; --y) { REP(x, width) { if (table[y][x] == -1) continue; if (x > 0) { value = table[y][x - 1]; table[y][x] += value > -1 ? value : 0; } if (y < height - 1) { value = table[y + 1][x]; table[y][x] += value > -1 ? value : 0; } } } cout << table[0][width - 1] << endl; } return 0; }
replace
90
98
90
126
0
d = 0
p00438
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> using namespace std; const double PI = 3.14159265358979323846; int map[1001][1001]; int w, h; int f(int x, int y) { if ((map[x][y] == -1) || (x < 0) || (y < 0) || (w <= x) || (h <= y)) { return 0; } if ((x == 0) && (y == 0)) { return 1; } if (map[x][y] != 0) { return map[x][y]; } return f(x - 1, y) + f(x, y - 1); } int main() { while (true) { int n; cin >> w >> h >> n; if ((w == 0) && (h == 0)) return 0; for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { map[i][j] = 0; } } for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; map[x - 1][y - 1] = -1; } cout << f(w - 1, h - 1) << endl; } }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; const double PI = 3.14159265358979323846; int map[16][16]; int w, h; int f(int x, int y) { if ((map[x][y] == -1) || (x < 0) || (y < 0) || (w <= x) || (h <= y)) { return 0; } if ((x == 0) && (y == 0)) { return 1; } if (map[x][y] != 0) { return map[x][y]; } return f(x - 1, y) + f(x, y - 1); } int main() { while (true) { int n; cin >> w >> h >> n; if ((w == 0) && (h == 0)) return 0; for (int i = 0; i < w; ++i) { for (int j = 0; j < h; ++j) { map[i][j] = 0; } } for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; map[x - 1][y - 1] = -1; } cout << f(w - 1, h - 1) << endl; } }
replace
8
9
8
9
0
p00438
C++
Runtime Error
#include <iostream> #include <vector> int main() { int a, b; while (std::cin >> a >> b) { if (a == 0 && b == 0) break; int n; std::cin >> n; std::vector<std::vector<int>> map(a, std::vector<int>(b, 1)); // 地図 for (int i = 0; i < n; ++i) { int x, y; std::cin >> x >> y; if (x == 0 && y == 0) break; map[x - 1][y - 1] = 0; if (x == 1) { for (int y1 = y; y1 < b; y1++) { map[x - 1][y1] = 0; } } if (y == 1) { for (int x1 = x; x1 < a; x1++) { map[x - 1][x1] = 0; } } } for (int i = 1; i < a; ++i) { for (int j = 1; j < b; ++j) { if (map[i][j] > 0) { map[i][j] = map[i - 1][j] + map[i][j - 1]; } } } std::cout << map[a - 1][b - 1] << std::endl; } return 0; }
#include <iostream> #include <vector> int main() { int a, b; while (std::cin >> a >> b) { if (a == 0 && b == 0) break; int n; std::cin >> n; std::vector<std::vector<int>> map(a, std::vector<int>(b, 1)); // 地図 for (int i = 0; i < n; ++i) { int x, y; std::cin >> x >> y; if (x == 0 && y == 0) break; map[x - 1][y - 1] = 0; if (x == 1) { for (int y1 = y; y1 < b; y1++) { map[x - 1][y1] = 0; } } if (y == 1) { for (int x1 = x; x1 < a; x1++) { map[x1][y - 1] = 0; } } } for (int i = 1; i < a; ++i) { for (int j = 1; j < b; ++j) { if (map[i][j] > 0) { map[i][j] = map[i - 1][j] + map[i][j - 1]; } } } std::cout << map[a - 1][b - 1] << std::endl; } return 0; }
replace
26
27
26
27
0
p00439
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; int num[100005]; while (cin >> n >> k && n && k) { for (int i = 0; i < n; i++) cin >> num[i]; int ans = 0; for (int i = 0; i < n - k + 1; i++) { int sum = 0; for (int j = 0; j < k; j++) { sum += num[i + j]; } ans = max(ans, sum); } cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int main() { int n, k; int num[100005]; while (cin >> n >> k && n && k) { for (int i = 0; i < n; i++) cin >> num[i]; int ans = 0; for (int i = 0; i < k; i++) ans += num[i]; int sum = ans; for (int i = 1; i < n - k + 1; i++) { sum -= num[i - 1]; sum += num[i + k - 1]; ans = max(ans, sum); } cout << ans << endl; } }
replace
11
16
11
17
TLE
p00439
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int n, k; int a[100000]; while (cin >> n >> k) { if (n == 0 && k == 0) { break; } for (int i = 0; i < n; i++) { cin >> a[i]; } int max = a[0]; for (int i = 0; i <= n - k; i++) { int t = 0; int l = 0; for (int j = i; j < n; j++) { l++; t += a[j]; if (t > max) { max = t; } if (l == k) { break; } } } cout << max << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, k; int a[100000]; while (cin >> n >> k) { if (n == 0 && k == 0) { break; } for (int i = 0; i < n; i++) { cin >> a[i]; } int max = a[0]; int t = 0; for (int i = 0; i < k; i++) { t += a[i]; } if (t > max) { max = t; } for (int i = k; i < n; i++) { t += a[i]; t -= a[i - k]; if (t > max) { max = t; } } cout << max << endl; } return 0; }
replace
17
29
17
29
TLE
p00439
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main(void) { int n, k, input[5000]; while (cin >> n >> k, n | k) { int sum = 0; for (int i = 0; i < n; ++i) { cin >> input[i]; if (i < k) sum += input[i]; } int i, j, ans = sum; i = 0; j = k - 1; while (j < n - 1) { sum -= input[i++]; sum += input[++j]; ans = max(ans, sum); } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main(void) { int n, k, input[100000]; while (cin >> n >> k, n | k) { int sum = 0; for (int i = 0; i < n; ++i) { cin >> input[i]; if (i < k) sum += input[i]; } int i, j, ans = sum; i = 0; j = k - 1; while (j < n - 1) { sum -= input[i++]; sum += input[++j]; ans = max(ans, sum); } cout << ans << endl; } return 0; }
replace
6
7
6
7
0
p00439
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int a[100010], n, k; while (cin >> n >> k, n || k) { for (int i = 0; i < n; i++) cin >> a[i]; int mx = -1; for (int i = 0; i <= n - k; i++) { int sum = 0; for (int j = i; j < i + k; j++) sum += a[j]; mx = max(mx, sum); } cout << mx << endl; } }
#include <iostream> using namespace std; int main() { int a[100010], n, k; while (cin >> n >> k, n || k) { for (int i = 0; i < n; i++) cin >> a[i]; int mx = -1; int sum = 0; for (int i = 0; i < k; i++) sum += a[i]; mx = sum; for (int i = k; i < n; i++) { sum -= a[i - k]; sum += a[i]; mx = max(mx, sum); } cout << mx << endl; } }
replace
8
12
8
15
TLE
p00439
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int N, K; int a[10001]; void solve() { for (int i = 0; i < N; i++) { scanf("%d", &a[i + 1]); a[i + 1] += a[i]; } int ma = 0; for (int i = K; i <= N; i++) ma = max(ma, a[i] - a[i - K]); printf("%d\n", ma); } int main() { while (scanf("%d%d", &N, &K), N || K) solve(); }
#include <bits/stdc++.h> using namespace std; int N, K; int a[100001]; void solve() { for (int i = 0; i < N; i++) { scanf("%d", &a[i + 1]); a[i + 1] += a[i]; } int ma = 0; for (int i = K; i <= N; i++) ma = max(ma, a[i] - a[i - K]); printf("%d\n", ma); } int main() { while (scanf("%d%d", &N, &K), N || K) solve(); }
replace
4
5
4
5
0
p00439
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { while (1) { int n, k; cin >> n >> k; if (n == 0 && k == 0) { break; } vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int s = 0; int m = 0; while (s + 2 < n) { int cm = 0; for (int j = 0; j < k; j++) { cm += a[s + j]; } if (cm > m) { m = cm; } s++; } cout << m << endl; } }
#include <iostream> #include <vector> using namespace std; int main() { while (1) { int n, k; cin >> n >> k; if (n == 0 && k == 0) { break; } vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int s = 0; int m = 0; while (s + k - 1 < n) { int cm = 0; for (int j = 0; j < k; j++) { cm += a[s + j]; } if (cm > m) { m = cm; } s++; } cout << m << endl; } }
replace
17
18
17
18
0
p00439
C++
Time Limit Exceeded
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; const int mod = 100000; struct Mod { public: int num; Mod() : Mod(0) { ; } Mod(long long int n) : num((n % mod + mod) % mod) { static_assert(mod < INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'"); } Mod(int n) : Mod(static_cast<long long int>(n)) { ; } operator int() { return num; } }; Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); } Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; } Mod operator+(const Mod a, const long long int b) { return b + a; } Mod operator++(Mod &a) { return a + Mod(1); } Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); } Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; } Mod operator--(Mod &a) { return a - Mod(1); } Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); } Mod operator*(const long long int a, const Mod b) { return Mod(a) * b; } Mod operator*(const Mod a, const long long int b) { return Mod(b) * a; } Mod operator*(const Mod a, const int b) { return Mod(b) * a; } Mod operator+=(Mod &a, const Mod b) { return a = a + b; } Mod operator+=(long long int &a, const Mod b) { return a = a + b; } Mod operator-=(Mod &a, const Mod b) { return a = a - b; } Mod operator-=(long long int &a, const Mod b) { return a = a - b; } Mod operator*=(Mod &a, const Mod b) { return a = a * b; } Mod operator*=(long long int &a, const Mod b) { return a = a * b; } Mod operator*=(Mod &a, const long long int &b) { return a = a * b; } Mod operator^(const Mod a, const int n) { if (n == 0) return Mod(1); Mod res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } Mod mod_pow(const Mod a, const long long int n) { if (n == 0) return Mod(1); Mod res = mod_pow((a * a), (n / 2)); if (n % 2) res = res * a; return res; } Mod inv(const Mod a) { return a ^ (mod - 2); } Mod operator/(const Mod a, const Mod b) { assert(b.num != 0); return a * inv(b); } Mod operator/(const long long int a, const Mod b) { return Mod(a) / b; } Mod operator/=(Mod &a, const Mod b) { return a = a / b; } #define MAX_MOD_N 1024000 Mod fact[MAX_MOD_N], factinv[MAX_MOD_N]; void init(const int amax = MAX_MOD_N) { fact[0] = Mod(1); factinv[0] = 1; for (int i = 0; i < amax - 1; ++i) { fact[i + 1] = fact[i] * Mod(i + 1); factinv[i + 1] = factinv[i] / Mod(i + 1); } } Mod comb(const int a, const int b) { return fact[a] * factinv[b] * factinv[a - b]; } int main() { while (1) { int N, K; cin >> N >> K; vector<int> as(N); for (int i = 0; i < N; ++i) { cin >> as[i]; } long long int sum = 0; for (int i = 0; i < K; ++i) { sum += as[i]; } long long int ans = sum; for (int i = K; i < N; ++i) { sum += as[i] - as[i - K]; ans = max(ans, sum); } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; const int mod = 100000; struct Mod { public: int num; Mod() : Mod(0) { ; } Mod(long long int n) : num((n % mod + mod) % mod) { static_assert(mod < INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'"); } Mod(int n) : Mod(static_cast<long long int>(n)) { ; } operator int() { return num; } }; Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); } Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; } Mod operator+(const Mod a, const long long int b) { return b + a; } Mod operator++(Mod &a) { return a + Mod(1); } Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); } Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; } Mod operator--(Mod &a) { return a - Mod(1); } Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); } Mod operator*(const long long int a, const Mod b) { return Mod(a) * b; } Mod operator*(const Mod a, const long long int b) { return Mod(b) * a; } Mod operator*(const Mod a, const int b) { return Mod(b) * a; } Mod operator+=(Mod &a, const Mod b) { return a = a + b; } Mod operator+=(long long int &a, const Mod b) { return a = a + b; } Mod operator-=(Mod &a, const Mod b) { return a = a - b; } Mod operator-=(long long int &a, const Mod b) { return a = a - b; } Mod operator*=(Mod &a, const Mod b) { return a = a * b; } Mod operator*=(long long int &a, const Mod b) { return a = a * b; } Mod operator*=(Mod &a, const long long int &b) { return a = a * b; } Mod operator^(const Mod a, const int n) { if (n == 0) return Mod(1); Mod res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } Mod mod_pow(const Mod a, const long long int n) { if (n == 0) return Mod(1); Mod res = mod_pow((a * a), (n / 2)); if (n % 2) res = res * a; return res; } Mod inv(const Mod a) { return a ^ (mod - 2); } Mod operator/(const Mod a, const Mod b) { assert(b.num != 0); return a * inv(b); } Mod operator/(const long long int a, const Mod b) { return Mod(a) / b; } Mod operator/=(Mod &a, const Mod b) { return a = a / b; } #define MAX_MOD_N 1024000 Mod fact[MAX_MOD_N], factinv[MAX_MOD_N]; void init(const int amax = MAX_MOD_N) { fact[0] = Mod(1); factinv[0] = 1; for (int i = 0; i < amax - 1; ++i) { fact[i + 1] = fact[i] * Mod(i + 1); factinv[i + 1] = factinv[i] / Mod(i + 1); } } Mod comb(const int a, const int b) { return fact[a] * factinv[b] * factinv[a - b]; } int main() { while (1) { int N, K; cin >> N >> K; if (!N) break; vector<int> as(N); for (int i = 0; i < N; ++i) { cin >> as[i]; } long long int sum = 0; for (int i = 0; i < K; ++i) { sum += as[i]; } long long int ans = sum; for (int i = K; i < N; ++i) { sum += as[i] - as[i - K]; ans = max(ans, sum); } cout << ans << endl; } return 0; }
insert
87
87
87
89
TLE
p00439
C++
Runtime Error
// Bokan ga bokka--nn!! // Daily Lunch Special Tanoshii !! #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; typedef long long ll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 #define s(x) scanf("%d", &x) #define rep(i, x) for (int i = 0; i < x; i++) int main() { while (1) { int n, k; scanf("%d %d", &n, &k); if (!n) return 0; int ret = -INF; int res = 0; queue<int> que; for (int i = 0; i < k; i++) { int s; scanf("%d", &s); res += s; que.push(s); } ret = max(ret, res); for (int i = k; i <= n; i++) { int s; scanf("%d", &s); res += s; res -= (que.front()); ret = max(ret, res); que.pop(); que.push(s); } printf("%d\n", ret); } }
// Bokan ga bokka--nn!! // Daily Lunch Special Tanoshii !! #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; typedef long long ll; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 2000000000 #define s(x) scanf("%d", &x) #define rep(i, x) for (int i = 0; i < x; i++) int main() { while (1) { int n, k; scanf("%d %d", &n, &k); if (!n) return 0; int ret = -INF; int res = 0; queue<int> que; for (int i = 0; i < k; i++) { int s; scanf("%d", &s); res += s; que.push(s); } ret = max(ret, res); for (int i = k; i < n; i++) { int s; scanf("%d", &s); res += s; res -= (que.front()); ret = max(ret, res); que.pop(); que.push(s); } printf("%d\n", ret); } }
replace
43
44
43
44
0
p00439
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int in, k; while (cin >> in >> k) { if (in == 0 && k == 0) break; int data[in]; int sum; for (int i = 0; i < in; i++) { cin >> data[i]; } for (int i = 0; i <= in - k; i++) { int tmp = 0; for (int j = i; j < i + k; j++) { tmp += data[j]; } if (i == 0 || sum < tmp) sum = tmp; } cout << sum << endl; } return 0; }
#include <iostream> using namespace std; int main() { int in, k; while (cin >> in >> k) { if (in == 0 && k == 0) break; int data[in]; int sum; for (int i = 0; i < in; i++) { cin >> data[i]; } int tmp = 0; for (int i = 0; i < k; i++) { tmp += data[i]; } sum = tmp; int num = 0; for (int i = k; i < in; i++) { tmp -= data[num]; num++; tmp += data[i]; if (i == 0 || sum < tmp) sum = tmp; } cout << sum << endl; } return 0; }
replace
18
23
18
30
TLE
p00439
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { vector<int> sum; int n, m, x, max; while (cin >> n >> m, n || m) { cin >> x; sum.push_back(0); sum.push_back(x); max = -1000000; for (int i = 2; i <= n; i++) { cin >> x; sum.push_back(sum[i - 1] + x); } for (int i = 0; i < n; i++) { if (sum[m + i] - sum[i] > max) max = sum[m + i] - sum[i]; } cout << max << endl; sum.clear(); } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { vector<int> sum; int n, m, x, max; while (cin >> n >> m, n || m) { cin >> x; sum.push_back(0); sum.push_back(x); max = -1000000; for (int i = 2; i <= n; i++) { cin >> x; sum.push_back(sum[i - 1] + x); } for (int i = 0; i < n - m + 1; i++) { if (sum[m + i] - sum[i] > max) max = sum[m + i] - sum[i]; } cout << max << endl; sum.clear(); } return 0; }
replace
15
16
15
16
0
p00439
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { while (1) { int n, k; int sum = 0, mx = 0; int ans[10000] = {0}; cin >> n >> k; if (n == 0 && k == 0) break; for (int i = 0; i < n; i++) cin >> ans[i]; for (int i = 0; i < k; i++) { sum += ans[i]; } mx = sum; for (int i = k; i < n; i++) { sum += ans[i]; sum -= ans[i - k]; mx = max(mx, sum); } cout << mx << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <string> using namespace std; int main() { while (1) { int n, k; int sum = 0, mx = 0; int ans[100000] = {0}; cin >> n >> k; if (n == 0 && k == 0) break; for (int i = 0; i < n; i++) cin >> ans[i]; for (int i = 0; i < k; i++) { sum += ans[i]; } mx = sum; for (int i = k; i < n; i++) { sum += ans[i]; sum -= ans[i - k]; mx = max(mx, sum); } cout << mx << endl; } return 0; }
replace
9
10
9
10
0
p00439
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { while (1) { int N, M; int lis[20000]; cin >> N >> M; if (N == 0 && M == 0) break; for (int i = 0; i < N; i++) cin >> lis[i]; int now = 0, ans = 0; for (int i = 0; i < M; i++) now += lis[i], ans += lis[i]; for (int i = 1; i + M <= N; i++) now = now - lis[i - 1] + lis[i + M - 1], ans = max(now, ans); cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> using namespace std; int main() { while (1) { int N, M; int lis[100002]; cin >> N >> M; if (N == 0 && M == 0) break; for (int i = 0; i < N; i++) cin >> lis[i]; int now = 0, ans = 0; for (int i = 0; i < M; i++) now += lis[i], ans += lis[i]; for (int i = 1; i + M <= N; i++) now = now - lis[i - 1] + lis[i + M - 1], ans = max(now, ans); cout << ans << endl; } return 0; }
replace
8
9
8
9
0
p00439
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) int main(void) { int n, k; while (cin >> n >> k, n + k) { vector<int> a(n); rep(i, n) cin >> a[i]; int ret = -100000; rep(i, n - k + 1) { int sum = 0; rep(j, k) { sum += a[i + j]; } ret = max(ret, sum); } cout << ret << endl; } }
#include <iostream> #include <vector> using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) int main(void) { int n, k; while (cin >> n >> k, n + k) { vector<int> a(n); rep(i, n) cin >> a[i]; int ret = -100000; int sum = 0; rep(i, k) sum += a[i]; for (int i = k; i < n; i++) { sum = sum + a[i] - a[i - k]; ret = max(ret, sum); } cout << ret << endl; } }
replace
14
17
14
18
TLE
p00439
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { while (1) { int ans = 0, n, k, box[10000] = {0}, sum = 0; ; cin >> n >> k; if (n == 0 && k == 0) break; for (int i = 0; i < k; i++) { cin >> box[i]; sum += box[i]; } ans = sum; for (int i = k; i < n; i++) { cin >> box[i]; sum += box[i] - box[i - k]; if (sum > ans) ans = sum; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { while (1) { int ans = 0, n, k, box[100005] = {0}, sum = 0; ; cin >> n >> k; if (n == 0 && k == 0) break; for (int i = 0; i < k; i++) { cin >> box[i]; sum += box[i]; } ans = sum; for (int i = k; i < n; i++) { cin >> box[i]; sum += box[i] - box[i - k]; if (sum > ans) ans = sum; } cout << ans << endl; } return 0; }
replace
4
5
4
5
0
p00439
C++
Runtime Error
#include <iostream> const int MAX_N = 1 << 17, INF = 1 << 24; class SegmentTree { public: SegmentTree(int _n) { n = 1; while (n < _n) n *= 2; for (int i = 0; i < 2 * n - 1; i++) { data[i] = 0; } } void add(int k, int a) { k += n - 1; data[k] = a; while (k > 0) { k = (k - 1) / 2; data[k] = data[k * 2 + 1] + data[k * 2 + 2]; } } int calculate(int a, int b) { return _calculate(a, b, 0, 0, n); } private: int data[MAX_N]; int n; int _calculate(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) return data[k]; else { int l_child = _calculate(a, b, 2 * k + 1, l, (l + r) / 2), r_child = _calculate(a, b, 2 * k + 2, (l + r) / 2, r); return l_child + r_child; } } }; int main() { int n, k; while (std::cin >> n >> k, n) { SegmentTree st(n); for (int i = 0; i < n; i++) { int a_i; std::cin >> a_i; st.add(i, a_i); } int res = -INF; for (int i = 0; i + k - 1 < n; i++) { res = std::max(res, st.calculate(i, i + k)); } std::cout << res << std::endl; } }
#include <iostream> const int MAX_N = 1 << 18, INF = 1 << 24; class SegmentTree { public: SegmentTree(int _n) { n = 1; while (n < _n) n *= 2; for (int i = 0; i < 2 * n - 1; i++) { data[i] = 0; } } void add(int k, int a) { k += n - 1; data[k] = a; while (k > 0) { k = (k - 1) / 2; data[k] = data[k * 2 + 1] + data[k * 2 + 2]; } } int calculate(int a, int b) { return _calculate(a, b, 0, 0, n); } private: int data[MAX_N]; int n; int _calculate(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) return data[k]; else { int l_child = _calculate(a, b, 2 * k + 1, l, (l + r) / 2), r_child = _calculate(a, b, 2 * k + 2, (l + r) / 2, r); return l_child + r_child; } } }; int main() { int n, k; while (std::cin >> n >> k, n) { SegmentTree st(n); for (int i = 0; i < n; i++) { int a_i; std::cin >> a_i; st.add(i, a_i); } int res = -INF; for (int i = 0; i + k - 1 < n; i++) { res = std::max(res, st.calculate(i, i + k)); } std::cout << res << std::endl; } }
replace
2
3
2
3
0
p00439
C++
Runtime Error
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <queue> #include <stack> #include <vector> using namespace std; typedef long long ll; int a[10000]; int main() { int n, k; while (cin >> n >> k && n && k) { for (int i = 0; i < n; i++) { cin >> a[i]; } ll pre = 0; for (int i = 0; i < k; i++) { pre += a[i]; } ll ret = pre; for (int i = 0; i < n - k; i++) { pre = pre - a[i] + a[k + i]; ret = max(ret, pre); } cout << ret << endl; } }
#include <algorithm> #include <cctype> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <queue> #include <stack> #include <vector> using namespace std; typedef long long ll; int a[1000000]; int main() { int n, k; while (cin >> n >> k && n && k) { for (int i = 0; i < n; i++) { cin >> a[i]; } ll pre = 0; for (int i = 0; i < k; i++) { pre += a[i]; } ll ret = pre; for (int i = 0; i < n - k; i++) { pre = pre - a[i] + a[k + i]; ret = max(ret, pre); } cout << ret << endl; } }
replace
14
15
14
15
0