buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <stdio.h> int main(void) { int total; int book[9]; int sum; int i; while (1) { scanf("%d", &total); if (total == 0) { break; } sum = 0; for (i = 0; i < 9; i++) { scanf("%d", &book[i]); sum += book[i]; } } printf("%d\n", total - sum); return (0); }
#include <stdio.h> int main(void) { int total; int book[9]; int sum; int i; while (1) { scanf("%d", &total); if (total == 0) { break; } sum = 0; for (i = 0; i < 9; i++) { scanf("%d", &book[i]); sum += book[i]; } printf("%d\n", total - sum); } return (0); }
[["-", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
0
106
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define mem(x, y) (x *)malloc(sizeof(x) * (y)) #define PI 3.14159265358979 int main() { int sum; while (scanf("%d", &sum), sum) ; { int i; for (i = 0; i < 9; i++) { int price; scanf("%d", &price); sum -= price; } printf("%d\n", sum); } return 0; }
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define mem(x, y) (x *)malloc(sizeof(x) * (y)) #define PI 3.14159265358979 int main() { int sum; while (scanf("%d", &sum), sum) { int i; for (i = 0; i < 9; i++) { int price; scanf("%d", &price); sum -= price; } printf("%d\n", sum); } return 0; }
[["-", 0, 14, 8, 9, 0, 52, 8, 1, 0, 35]]
0
93
#include <stdio.h> main() { int value, data, i; while (1) { scanf("%d", &value); if (!value) break; for (i = 0; i < 9; i++) { scanf("%d", data); value -= data; } printf("%d\n", value); } return 0; }
#include <stdio.h> main() { int value, data, i; while (1) { scanf("%d", &value); if (!value) break; for (i = 0; i < 9; i++) { scanf("%d", &data); value -= data; } printf("%d\n", value); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
0
79
s, i; main(x) { for (; scanf("%d", &x) * x; ++i % 10 && printf("%d\n", s)) s = i % 10 ? s - x : x; } //////////
s, i; main(x) { for (; scanf("%d", &x) * x; ++i % 10 || printf("%d\n", s)) s = i % 10 ? s - x : x; } //////////
[["-", 0, 14, 8, 9, 0, 7, 26, 16, 17, 98], ["+", 0, 14, 8, 9, 0, 7, 26, 16, 17, 106]]
0
53
#include <stdio.h> int main(void) { int a, s; int i, n, x; while (1) { scanf("%d", &a); if (n == 0) { break; } s = 0; for (i = 0; i < 9; i++) { scanf("%d", &x); s += a; } x = n - s; printf("%d\n", x); } return 0; }
#include <stdio.h> int main(void) { int a, s; int i, n, x; while (1) { scanf("%d", &n); if (n == 0) { break; } s = 0; for (i = 0; i < 9; i++) { scanf("%d", &a); s += a; } x = n - s; printf("%d\n", x); } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22]]
1
99
#include <iostream> using namespace std; int main() { for (int i = 0; i < 5; i++) { int B[10]; for (int i = 0; i < 10; i++) { cin >> B[i]; if (B[i] == 0) { return 0; //プログラムの強制終了 } } int sum = 0; for (int i = 1; i < 9; i++) { sum += B[i]; } cout << B[0] - sum << endl; } return 0; }
#include <iostream> using namespace std; int main() { for (int i = 0; i < 5; i++) { int B[10]; for (int i = 0; i < 10; i++) { cin >> B[i]; if (B[i] == 0) { return 0; //プログラムの強制終了 } } int sum = 0; for (int i = 1; i < 10; i++) { sum += B[i]; } cout << B[0] - sum << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
114
#include <stdio.h> int main(void) { int N, i, k; while (0) { scanf("%d", &N); if (N == 0) break; for (i = 0; i < 9; i++) { scanf("%d", &k); N -= k; } printf("%d\n", N); } return 0; }
#include <stdio.h> int main(void) { int N, i, k; while (0 == 0) { scanf("%d", &N); if (N == 0) break; for (i = 0; i < 9; i++) { scanf("%d", &k); N -= k; } printf("%d\n", N); } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 13]]
1
82
#include <iostream> using namespace std; int main() { int n, m, i; while (cin >> n, n) for (i = 0; i < 9; i++) { cin >> m; n -= m; } cout << n << endl; }
#include <iostream> using namespace std; int main() { int n, m, i; while (cin >> n, n) { for (i = 0; i < 9; i++) { cin >> m; n -= m; } cout << n << endl; } }
[["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
56
#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; } int z() { int h = in(); int m = in(); int s = in(); return h * 3600 + m * 60 + s; } void func() { while (1) { int n = in(); if (n == 0) { return; } REP(i, 9) { n -= in(); out(n); } } }
#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; } int z() { int h = in(); int m = in(); int s = in(); return h * 3600 + m * 60 + s; } void func() { while (1) { int n = in(); if (n == 0) { return; } REP(i, 9) { n -= in(); } out(n); } }
[["+", 8, 9, 0, 52, 8, 9, 0, 9, 0, 46], ["-", 8, 9, 0, 52, 8, 9, 0, 9, 0, 46]]
1
1,848
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { for (int i = 0; i < 9; i++) { int inp; cin >> inp; n -= inp; } cout << n << endl; } }
#include <iostream> using namespace std; int main() { int n; while (cin >> n, n) { for (int i = 0; i < 9; i++) { int inp; cin >> inp; n -= inp; } cout << n << endl; } }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
56
#include <iostream> using namespace std; int main() { int total, books; while (true) { cin >> total; if (total == 0) break; } for (int i = 1; i <= 9; i++) { cin >> books; total -= books; cout << total << "\n"; } return 0; }
#include <iostream> using namespace std; int main() { int total, books; while (true) { cin >> total; if (total == 0) { break; } for (int i = 1; i <= 9; i++) { cin >> books; total -= books; } cout << total << "\n"; } return 0; }
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 46]]
1
70
#include <iostream> using namespace std; int a, b; int main() { while (true) { cin >> a; if (a == 0) break; for (int i = 0; i < 9; i++) { cin >> b; a -= b; } cout << b << endl; } return 0; }
#include <iostream> using namespace std; int a, b; int main() { while (true) { cin >> a; if (a == 0) break; for (int i = 0; i < 9; i++) { cin >> b; a -= b; } cout << a << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
68
#include <bits/stdc++.h> using namespace std; int main() { int s, a; while (cin >> s) { if (s == 0) break; cin >> s; for (int i = 0; i < 9; i++) { cin >> a; s -= a; } cout << s << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int s, a; while (cin >> s) { if (s == 0) break; for (int i = 0; i < 9; i++) { cin >> a; s -= a; } cout << s << endl; } }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
67
#include <iostream> using namespace std; int main() { int x, y, i; while (cin >> x) { for (int i = 0; i < 9; i++) { cin >> y; x -= y; } cout << x << endl; } }
#include <iostream> using namespace std; int main() { int x, y; while (cin >> x, x) { for (int i = 0; i < 9; i++) { cin >> y; x -= y; } cout << x << endl; } }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 52, 15, 339, 51, 34, 31, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21]]
1
57
#include <bits/stdc++.h> using namespace std; int main() { int h, e; while (1) { cin >> h; if (h == 0) break; for (int i = 0; i < 9; i++) { cin >> e; h -= e; } cout << e << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h, e; while (1) { cin >> h; if (h == 0) break; for (int i = 0; i < 9; i++) { cin >> e; h -= e; } cout << h << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
1
68
#include <cstdio> int main() { int a, b, i; for (i = 0; b = 0, scanf("%d", i % 10 ? &b : &a), a; ++i, printf("%d\n", a)) a -= b; }
#include <cstdio> int main() { int a, b, i; for (i = 0; b = 0, scanf("%d", i % 10 ? &b : &a), a; ++i, printf(i % 10 ? "" : "%d\n", a)) a -= b; }
[["+", 12, 2, 3, 4, 0, 41, 15, 16, 31, 22], ["+", 12, 2, 3, 4, 0, 41, 15, 16, 17, 109], ["+", 12, 2, 3, 4, 0, 41, 15, 16, 12, 13], ["+", 26, 34, 12, 2, 3, 4, 0, 41, 0, 101], ["+", 12, 2, 3, 4, 0, 41, 64, 5, 0, 62], ["+", 26, 34, 12, 2, 3, 4, 0, 41, 0, 102], ["+", 12, 2, 3, 4, 0, 41, 75, 5, 0, 62]]
1
61
#include <bits/stdc++.h> using namespace std; int n, m, f[100][100] = {0}, ff[100][100] = {0}, ans = 0; void s(int x, int y, int depth); int main() { while (1) { cin >> n >> m; if (n == 0 && m == 0) break; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> f[i][j]; ff[i][j] = f[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int k = 0; if (f[i][j] == 1) { // k=s(i,j,1,n,m); s(i, j, 1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { f[i][j] = ff[i][j]; } } } // if(k>ans)ans=k; ans = max(ans, k); } } cout << ans << endl; } return 0; } void s(int x, int y, int depth) { ans = max(ans, depth); if (f[x - 1][y] == 0 && f[x][y - 1] == 0 && f[x + 1][y] == 0 && f[x][y + 1] == 0) { return; } f[x][y] = 0; if (x > 0 && f[x - 1][y] == 1) s(x - 1, y, depth + 1); if (y > 0 && f[x][y - 1] == 1) s(x, y - 1, depth + 1); if (f[x + 1][y] == 1) s(x + 1, y, depth + 1); if (f[x][y + 1] == 1) s(x, y + 1, depth + 1); f[x][y] = 1; }
#include <bits/stdc++.h> using namespace std; int n, m, f[100][100] = {0}, ff[100][100] = {0}, ans = 0; void s(int x, int y, int depth); int main() { while (1) { ans = 0; cin >> n >> m; if (n == 0 && m == 0) break; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> f[i][j]; ff[i][j] = f[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int k = 0; if (f[i][j] == 1) { // k=s(i,j,1,n,m); s(i, j, 1); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { f[i][j] = ff[i][j]; } } } // if(k>ans)ans=k; ans = max(ans, k); } } cout << ans << endl; } return 0; } void s(int x, int y, int depth) { ans = max(ans, depth); if (f[x - 1][y] == 0 && f[x][y - 1] == 0 && f[x + 1][y] == 0 && f[x][y + 1] == 0) { return; } f[x][y] = 0; if (x > 0 && f[x - 1][y] == 1) s(x - 1, y, depth + 1); if (y > 0 && f[x][y - 1] == 1) s(x, y - 1, depth + 1); if (f[x + 1][y] == 1) s(x + 1, y, depth + 1); if (f[x][y + 1] == 1) s(x, y + 1, depth + 1); f[x][y] = 1; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
481
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dx[] = {1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define mp make_pair #define fi first #define sc second int m, n; bool sea[100][100]; int maxi = 0; void dfs(int i, int j, int d) { maxi = max(d, maxi); sea[i][j] = false; REP(k, 4) { int x = i + dx[k]; int y = j + dy[k]; if ((0 <= x && x < n && 0 <= y && y < m) && sea[x][y]) { dfs(x, y, d + 1); } } sea[i][j] = true; } int main() { while (true) { cin >> m >> n; if (m == 0 && n == 0) break; REP(i, n) REP(j, m) scanf("%d", &sea[i][j]); REP(i, n) { REP(j, m) { if (sea[i][j]) dfs(i, j, 1); } } printf("%d\n", maxi); } return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; using namespace std; #define pb push_back int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dx[] = {1, -1, 0, 0, 1, -1, -1, 1}; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define mp make_pair #define fi first #define sc second int m, n; bool sea[100][100]; int maxi = 0; void dfs(int i, int j, int d) { maxi = max(d, maxi); sea[i][j] = false; REP(k, 4) { int x = i + dx[k]; int y = j + dy[k]; if ((0 <= x && x < n && 0 <= y && y < m) && sea[x][y]) { dfs(x, y, d + 1); } } sea[i][j] = true; } int main() { while (true) { maxi = 0; cin >> m >> n; if (m == 0 && n == 0) break; REP(i, n) REP(j, m) scanf("%d", &sea[i][j]); REP(i, n) { REP(j, m) { if (sea[i][j]) dfs(i, j, 1); } } printf("%d\n", maxi); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
351
#include <algorithm> #include <iostream> using namespace std; int mp[91][91]; int W, H; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int dfs(int x, int y, int d) { int cnt = d; for (int i = 0; i < 4; i++) { int mx = x + dx[i]; int my = y + dy[i]; if (my >= 0 && mx >= 0 && my < H && mx < W && mp[my][mx]) { mp[my][mx] = 0; cnt = max(cnt, dfs(mx, my, d + 1)); mp[my][mx] = 1; } } return cnt; } int main() { while (cin >> W >> H) { for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { cin >> mp[y][x]; } } int ans = 0; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { if (mp[y][x]) { mp[y][x] = 0; ans = max(ans, dfs(x, y, 1)); mp[y][x] = 1; } } } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int mp[91][91]; int W, H; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; int dfs(int x, int y, int d) { int cnt = d; for (int i = 0; i < 4; i++) { int mx = x + dx[i]; int my = y + dy[i]; if (my >= 0 && mx >= 0 && my < H && mx < W && mp[my][mx]) { mp[my][mx] = 0; cnt = max(cnt, dfs(mx, my, d + 1)); mp[my][mx] = 1; } } return cnt; } int main() { while (cin >> W >> H, W || H) { for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { cin >> mp[y][x]; } } int ans = 0; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { if (mp[y][x]) { mp[y][x] = 0; ans = max(ans, dfs(x, y, 1)); mp[y][x] = 1; } } } cout << ans << endl; } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 31, 22], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 12, 22]]
1
330
#include <iostream> #include <vector> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; int m, n; VVI S; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; int answer = 0, now = 0; int search(int x, int y) { now++; answer = max(answer, now); S[y][x] = 0; for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (S[ny][nx] == 1) { search(nx, ny); } } S[y][x] = 1; now--; } int main(void) { while (cin >> m >> n && m && n) { // m*n S = VVI(n + 2, VI(m + 2, 0)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> S[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (S[i][j] == 1) { search(j, i); } } cout << answer << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; int m, n; VVI S; const int dx[4] = {0, 0, 1, -1}; const int dy[4] = {1, -1, 0, 0}; int answer = 0, now = 0; int search(int x, int y) { now++; answer = max(answer, now); S[y][x] = 0; for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (S[ny][nx] == 1) { search(nx, ny); } } S[y][x] = 1; now--; } int main(void) { while (cin >> m >> n && m && n) { answer = now = 0; // m*n S = VVI(n + 2, VI(m + 2, 0)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> S[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (S[i][j] == 1) { search(j, i); } } cout << answer << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
314
#include <cstdio> #include <iostream> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) int h, w; int cell[128][128]; int ans; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int check(int x, int y) { if (x < 0 || y < 0 || y >= h || x >= w) return 0; return 1; } void func(int x, int y, int count) { rep(i, 4) { if (check(x + dx[i], y + dy[i]) && cell[y + dy[i]][x + dx[i]] == 1) { cell[y + dy[i]][x + dx[i]] = 0; func(x + dx[i], y + dy[i], count + 1); cell[y + dy[i]][x + dx[i]] = 1; } else { ans = max(ans, count); } } } int main(void) { while (scanf("%d%d", &w, &h), w) { rep(i, h) rep(j, w) scanf("%d", &cell[i][j]); rep(i, h) rep(j, w) if (cell[i][j]) func(j, i, 0); rep(i, 128) rep(j, 128) cell[i][j] = 0; printf("%d\n", ans); } return 0; }
#include <cstdio> #include <iostream> using namespace std; #define reps(i, f, n) for (int i = f; i < int(n); i++) #define rep(i, n) reps(i, 0, n) int h, w; int cell[128][128]; int ans; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int check(int x, int y) { if (x < 0 || y < 0 || y >= h || x >= w) return 0; return 1; } void func(int x, int y, int count) { rep(i, 4) { if (check(x + dx[i], y + dy[i]) && cell[y + dy[i]][x + dx[i]] == 1) { cell[y + dy[i]][x + dx[i]] = 0; func(x + dx[i], y + dy[i], count + 1); cell[y + dy[i]][x + dx[i]] = 1; } else { ans = max(ans, count); } } } int main(void) { while (scanf("%d%d", &w, &h), w) { rep(i, h) rep(j, w) scanf("%d", &cell[i][j]); rep(i, h) rep(j, w) if (cell[i][j]) func(j, i, 0); rep(i, 128) rep(j, 128) cell[i][j] = 0; printf("%d\n", ans); ans = 0; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
364
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef complex<double> P; static const double EPS = 1e-8; #define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) int m, n; int grid[100][100]; bool arv[100][100]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int dfs(int x, int y, int n) { int ret = n; REP(i, 4) { int nx = x + dx[i]; int ny = y + dy[i]; if (0 <= nx && nx < m && 0 <= ny && ny < n && grid[ny][nx] && !arv[ny][nx]) { arv[ny][nx] = true; ret = max(ret, dfs(nx, ny, n + 1)); arv[ny][nx] = false; } } return ret; } int main(void) { while (cin >> m >> n, m) { REP(y, n) REP(x, m) cin >> grid[y][x]; memset(arv, 0, sizeof(arv)); int ans = 0; REP(y, n) REP(x, m) { if (grid[y][x]) { arv[y][x] = true; ans = max(ans, dfs(x, y, 1)); arv[y][x] = false; } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef complex<double> P; static const double EPS = 1e-8; #define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) int m, n; int grid[100][100]; bool arv[100][100]; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int dfs(int x, int y, int time) { int ret = time; REP(i, 4) { int nx = x + dx[i]; int ny = y + dy[i]; if (0 <= nx && nx < m && 0 <= ny && ny < n && grid[ny][nx] && !arv[ny][nx]) { arv[ny][nx] = true; ret = max(ret, dfs(nx, ny, time + 1)); arv[ny][nx] = false; } } return ret; } int main(void) { while (cin >> m >> n, m) { REP(y, n) REP(x, m) cin >> grid[y][x]; memset(arv, 0, sizeof(arv)); int ans = 0; REP(y, n) REP(x, m) { if (grid[y][x]) { arv[y][x] = true; ans = max(ans, dfs(x, y, 1)); arv[y][x] = false; } } cout << ans << endl; } return 0; }
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 49, 22], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 49, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22]]
1
391
#include <algorithm> #include <iostream> using namespace std; int n, m; bool map[90][90]; int backtrack(int h, int w) { int res = 1, tmp = 1; map[h][w] = false; if (h > 0 && map[h - 1][w]) tmp = backtrack(h - 1, w) + 1; res = max(res, tmp); if (h < n - 1 && map[h + 1][w]) res = backtrack(h + 1, w) + 1; res = max(res, tmp); if (w > 0 && map[h][w - 1]) res = backtrack(h, w - 1) + 1; res = max(res, tmp); if (w < m - 1 && map[h][w + 1]) res = backtrack(h, w + 1) + 1; res = max(res, tmp); map[h][w] = true; return res; } int main() { int maxim; while (1) { cin >> m; cin >> n; if (!m && !n) break; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> map[i][j]; } maxim = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (map[i][j]) maxim = max(maxim, backtrack(i, j)); } } cout << maxim << endl; } }
#include <algorithm> #include <iostream> using namespace std; int n, m; bool map[90][90]; int backtrack(int h, int w) { int res = 1, tmp = 1; map[h][w] = false; if (h > 0 && map[h - 1][w]) tmp = backtrack(h - 1, w) + 1; res = max(res, tmp); if (h < n - 1 && map[h + 1][w]) tmp = backtrack(h + 1, w) + 1; res = max(res, tmp); if (w > 0 && map[h][w - 1]) tmp = backtrack(h, w - 1) + 1; res = max(res, tmp); if (w < m - 1 && map[h][w + 1]) tmp = backtrack(h, w + 1) + 1; res = max(res, tmp); map[h][w] = true; return res; } int main() { int maxim; while (1) { cin >> m; cin >> n; if (!m && !n) break; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> map[i][j]; } maxim = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (map[i][j]) maxim = max(maxim, backtrack(i, j)); } } cout << maxim << endl; } }
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22]]
1
360
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int w, h, ans = 0; int mas[100][100]; int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; void dfs(int x, int y, int sum) { for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx >= 0 && nx < w && ny >= 0 && ny < h && mas[ny][nx]) { mas[ny][nx] = 0; dfs(nx, ny, sum + 1); mas[ny][nx] = 1; } } ans = max(ans, sum); } int main() { while (cin >> w >> h, w || h) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) cin >> mas[i][j]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (mas[i][j]) dfs(j, i, 0); } } cout << ans << endl; } }
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int w, h, ans = 0; int mas[100][100]; int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; void dfs(int x, int y, int sum) { for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx >= 0 && nx < w && ny >= 0 && ny < h && mas[ny][nx]) { mas[ny][nx] = 0; dfs(nx, ny, sum + 1); mas[ny][nx] = 1; } } ans = max(ans, sum); } int main() { while (cin >> w >> h, w || h) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) cin >> mas[i][j]; } ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (mas[i][j]) dfs(j, i, 0); } } cout << ans << endl; } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
292
#include <iostream> using namespace std; void dfs(int, int, int); int cnt, big, mas[93][93], d[] = {0, 1, 0, -1}, h, w; int main() { while (cin >> w >> h && w || h) { for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> mas[i][j]; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (mas[i][j] == 1) { mas[i][j] = 0; dfs(i, j, 1); mas[i][j] = 1; } } } cout << big << endl; } } void dfs(int x, int y, int cnt) { if (cnt > big) big = cnt; for (int i = 0; i < 4; i++) { int nx = d[i] + x, ny = d[3 - i] + y; if (nx >= 0 && nx < h && ny >= 0 && ny < w && mas[nx][ny] == 1) { mas[nx][ny] = 0; dfs(nx, ny, cnt + 1); mas[nx][ny] = 1; } } }
#include <iostream> using namespace std; void dfs(int, int, int); int cnt, big, mas[93][93], d[] = {0, 1, 0, -1}, h, w; int main() { while (cin >> w >> h && w || h) { big = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> mas[i][j]; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (mas[i][j] == 1) { mas[i][j] = 0; dfs(i, j, 1); mas[i][j] = 1; } } } cout << big << endl; } } void dfs(int x, int y, int cnt) { if (cnt > big) big = cnt; for (int i = 0; i < 4; i++) { int nx = d[i] + x, ny = d[3 - i] + y; if (nx >= 0 && nx < h && ny >= 0 && ny < w && mas[nx][ny] == 1) { mas[nx][ny] = 0; dfs(nx, ny, cnt + 1); mas[nx][ny] = 1; } } }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
312
### subroutines def dist_rec(k) max_d = 1 for k0 in $nbrs[k] if ! $visited[k0] $visited[k0] = true max_d = [1 + dist_rec(k0), max_d].max $visited[k0] = false end end max_d end ### main loop do m = gets.strip.to_i n = gets.strip.to_i mn = m * n break if mn == 0 $brd = [] n.times do $brd += gets.strip.split(' ').map{|s| s.to_i} end $nbrs = [] id = 0 for y in (0...n) for x in (0...m) $nbrs[id] = [] if $brd[id] == 1 $nbrs[id] << (id - 1) if x > 0 && $brd[id - 1] == 1 $nbrs[id] << (id + 1) if x < m - 1 && $brd[id + 1] == 1 $nbrs[id] << (id - m) if y > 0 && $brd[id - m] == 1 $nbrs[id] << (id + m) if y < n - 1 && $brd[id + m] == 1 end id += 1 end end #p $nbrs $visited = (0...n).map{false} max_dist = 0 for st in (0...n) if $brd[st] == 1 $visited[st] = true max_dist = [dist_rec(st), max_dist].max $visited[st] = false end end puts max_dist end
## subroutines def dist_rec(k) max_d = 1 for k0 in $nbrs[k] if ! $visited[k0] $visited[k0] = true max_d = [1 + dist_rec(k0), max_d].max $visited[k0] = false end end max_d end ### main loop do m = gets.strip.to_i n = gets.strip.to_i mn = m * n break if mn == 0 $brd = [] n.times do $brd += gets.strip.split(' ').map{|s| s.to_i} end $nbrs = [] id = 0 for y in (0...n) for x in (0...m) $nbrs[id] = [] if $brd[id] == 1 $nbrs[id] << (id - 1) if x > 0 && $brd[id - 1] == 1 $nbrs[id] << (id + 1) if x < m - 1 && $brd[id + 1] == 1 $nbrs[id] << (id - m) if y > 0 && $brd[id - m] == 1 $nbrs[id] << (id + m) if y < n - 1 && $brd[id + m] == 1 end id += 1 end end #p $nbrs $visited = (0...mn).map{false} max_dist = 0 for st in (0...mn) if $brd[st] == 1 $visited[st] = true max_dist = [dist_rec(st), max_dist].max $visited[st] = false end end puts max_dist end
[["-", 0, 662, 12, 652, 486, 739, 0, 475, 444, 22], ["+", 0, 662, 12, 652, 486, 739, 0, 475, 444, 22], ["-", 0, 88, 51, 267, 0, 739, 0, 475, 444, 22], ["+", 0, 88, 51, 267, 0, 739, 0, 475, 444, 22]]
4
309
def s(): def b(M,x,y,n=1): M[x][y]=0;a=n if M[x-1][y]: t=b(M,x-1,y,n+1) if a<t:a=t if M[x][y-1]: t=b(M,x,y-1,n+1) if a<t:a=t if M[x+1][y]: t=b(M,x+1,y1,n+1) if a<t:a=t if M[x][y+1]: t=b(M,x,y+1,n+1) if a<t:a=t M[x][y]=1 return a for e in iter(input,'0'): n,m=int(e),int(input()) P=[[0]*(n+2)for _ in[0]*(m+2)] for i in range(m):P[i+1][1:-1]=map(int,input().split()) print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j])) if'__main__'==__name__:s()
def s(): def b(M,x,y,n=1): M[x][y]=0;a=n if M[x-1][y]: t=b(M,x-1,y,n+1) if a<t:a=t if M[x][y-1]: t=b(M,x,y-1,n+1) if a<t:a=t if M[x+1][y]: t=b(M,x+1,y,n+1) if a<t:a=t if M[x][y+1]: t=b(M,x,y+1,n+1) if a<t:a=t M[x][y]=1 return a for e in iter(input,'0'): n,m=int(e),int(input()) P=[[0]*(n+2)for _ in[0]*(m+2)] for i in range(m):P[i+1][1:-1]=map(int,input().split()) print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j])) if'__main__'==__name__:s()
[["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22]]
5
322
while 1: M = int(input()) N = int(input()) if M == N == 0: break S = [list(map(int, input().split())) for i in range(N)] used=[[0]*M for i in range(N)] def dfs(x, y, dd=((-1,0),(0,-1),(1,0),(0,1))): r = 0 for dx, dy in dd: nx = x + dx; ny = y + dy if 0 <= nx < M and 0 <= ny < N and S[ny][nx] and not used[ny][nx]: used[ny][nx] = 1 r = max(r, dfs(nx, ny)+1) used[ny][nx] = 0 return r ans = 0 for i in range(N): for j in range(M): if S[i][j]: used[i][j] = 1 ans = max(ans, dfs(i, j)+1) used[i][j] = 0 print(ans)
while 1: M = int(input()) N = int(input()) if M == N == 0: break S = [list(map(int, input().split())) for i in range(N)] used=[[0]*M for i in range(N)] def dfs(x, y, dd=((-1,0),(0,-1),(1,0),(0,1))): r = 0 for dx, dy in dd: nx = x + dx; ny = y + dy if 0 <= nx < M and 0 <= ny < N and S[ny][nx] and not used[ny][nx]: used[ny][nx] = 1 r = max(r, dfs(nx, ny)+1) used[ny][nx] = 0 return r ans = 0 for i in range(N): for j in range(M): if S[i][j]: used[i][j] = 1 ans = max(ans, dfs(j, i)+1) used[i][j] = 0 print(ans)
[["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 22], ["-", 3, 4, 0, 657, 31, 652, 3, 4, 0, 21], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 21], ["+", 3, 4, 0, 657, 31, 652, 3, 4, 0, 22]]
5
258
#include <iostream> #include <vector> using namespace std; class range { private: struct Iterator { int val; int operator*() { return val; } bool operator!=(Iterator &itr) { return val < itr.val; } void operator++() { ++val; } }; Iterator i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i}), n({n}) {} Iterator &begin() { return i; } Iterator &end() { return n; } }; template <class T> T at(vector<T> v, int i) { return v[(i % (int)v.size() + v.size()) % v.size()]; } int main() { while (true) { int n, m, p, q, r; cin >> n; if (n == 0) break; cin >> m >> p >> q >> r; ; --p; vector<pair<int, int>> dp[2]; dp[0].emplace_back(1, n); for (int i : range(m)) { int x, y, sum = 0; cin >> x >> y; --x; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, y); int yy = min(nsum, n); if (xx < yy) dp[1].emplace_back(i.first + max(0, y - sum), i.second - max(0, nsum - n)); sum = nsum; } sum = 0; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, x); int yy = min(nsum, y); if (xx < yy) dp[1].emplace_back(i.first + max(0, x - sum), i.second - max(0, nsum - y)); sum = nsum; } sum = 0; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, 0); int yy = min(nsum, x); if (xx < yy) dp[1].emplace_back(i.first + max(0, 0 - sum), i.second - max(0, nsum - x)); sum = nsum; } dp[0] = dp[1]; dp[1].clear(); } int sum = 0; int res = 0; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, p); int yy = min(nsum, q); if (xx < yy) { int s = i.first + max(0, p - sum); int t = min(i.second - max(0, nsum - q), r); if (s <= r) res += t - s + 1; } sum = nsum; } cout << res << endl; } }
#include <iostream> #include <vector> using namespace std; class range { private: struct Iterator { int val; int operator*() { return val; } bool operator!=(Iterator &itr) { return val < itr.val; } void operator++() { ++val; } }; Iterator i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i}), n({n}) {} Iterator &begin() { return i; } Iterator &end() { return n; } }; template <class T> T at(vector<T> v, int i) { return v[(i % (int)v.size() + v.size()) % v.size()]; } int main() { while (true) { int n, m, p, q, r; cin >> n; if (n == 0) break; cin >> m >> p >> q >> r; ; --p; vector<pair<int, int>> dp[2]; dp[0].emplace_back(1, n); for (int i : range(m)) { int x, y, sum = 0; cin >> x >> y; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, y); int yy = min(nsum, n); if (xx < yy) dp[1].emplace_back(i.first + max(0, y - sum), i.second - max(0, nsum - n)); sum = nsum; } sum = 0; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, x); int yy = min(nsum, y); if (xx < yy) dp[1].emplace_back(i.first + max(0, x - sum), i.second - max(0, nsum - y)); sum = nsum; } sum = 0; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, 0); int yy = min(nsum, x); if (xx < yy) dp[1].emplace_back(i.first + max(0, 0 - sum), i.second - max(0, nsum - x)); sum = nsum; } dp[0] = dp[1]; dp[1].clear(); } int sum = 0; int res = 0; for (const auto &i : dp[0]) { int nsum = sum + i.second - i.first + 1; int xx = max(sum, p); int yy = min(nsum, q); if (xx < yy) { int s = i.first + max(0, p - sum); int t = min(i.second - max(0, nsum - q), r); if (s <= r) res += t - s + 1; } sum = nsum; } cout << res << endl; } }
[["-", 0, 338, 8, 9, 0, 1, 0, 27, 17, 68], ["-", 0, 338, 8, 9, 0, 1, 0, 27, 28, 22], ["-", 8, 9, 0, 338, 8, 9, 0, 1, 0, 35]]
1
719
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; pair<int, int> a[11000], b[11000]; int sm, l; int fi(int i, int p) { for (; sm < p; ++i) sm += a[i].second; if (sm > p) { copy_backward(a + i, a + l, a + l + 1); ++l; a[i - 1].second -= sm - p; a[i] = make_pair(a[i - 1].first + a[i - 1].second, sm - p); sm = p; } return i; } int main() { int i, j, k; int n; while (cin >> n) { int m, p, q, r; cin >> m >> p >> q >> r; if (r == n) { for (i = 0; i < m; ++i) { int x, y; cin >> x >> y; } cout << q - p + 1 << endl; continue; } else { a[0] = make_pair(1, r); a[1] = make_pair(r + 1, n - r); l = 2; } for (i = 0; i < m; ++i) { int x, y; cin >> x >> y; sm = 0; j = fi(0, x); k = fi(j, y); copy(a + k, a + l, b); copy(a + j, a + k, b + l - k); copy(a, a + j, b + l - j); copy(b, b + l, a); } sm = 0; j = fi(0, p - 1); k = fi(j, q); int ct = 0; for (i = j; i < k; ++i) { if (a[i].first <= r) ct += a[i].second; } cout << ct << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; pair<int, int> a[11000], b[11000]; int sm, l; int fi(int i, int p) { for (; sm < p; ++i) sm += a[i].second; if (sm > p) { copy_backward(a + i, a + l, a + l + 1); ++l; a[i - 1].second -= sm - p; a[i] = make_pair(a[i - 1].first + a[i - 1].second, sm - p); sm = p; } return i; } int main() { int i, j, k; int n; while (cin >> n, n) { int m, p, q, r; cin >> m >> p >> q >> r; if (r == n) { for (i = 0; i < m; ++i) { int x, y; cin >> x >> y; } cout << q - p + 1 << endl; continue; } else { a[0] = make_pair(1, r); a[1] = make_pair(r + 1, n - r); l = 2; } for (i = 0; i < m; ++i) { int x, y; cin >> x >> y; sm = 0; j = fi(0, x); k = fi(j, y); copy(a + k, a + l, b); copy(a + j, a + k, b + l - k); copy(a, a + j, b + l - j); copy(b, b + l, a); } sm = 0; j = fi(0, p - 1); k = fi(j, q); int ct = 0; for (i = j; i < k; ++i) { if (a[i].first <= r) ct += a[i].second; } cout << ct << endl; } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
460
#include <algorithm> #include <iostream> #include <vector> using namespace std; main() { int n, m, p, q, r, x, y; vector<int>::iterator v, w, z; for (; cin >> n >> m >> p >> q >> r; cout << x << endl) { vector<int> t(1), u; for (t.push_back(r); m--; u.clear()) { cin >> x >> y; v = upper_bound(t.begin(), t.end(), x); w = upper_bound(t.begin(), t.end(), y); u.insert(u.end(), w - t.begin() & 1 ? 1 : 2, 0); for (z = w; z < t.end(); ++z) u.push_back(*z - y); if (t.end() - v & 1) u.push_back(n - y); for (z = v; z < w; ++z) u.push_back(*z - x + n - y); z = t.begin(); if (w - t.begin() & 1) ++z; if (!z[1]) z += 2; if (*z + n - x == u.back()) ++z, u.pop_back(); for (; z < v; ++z) u.push_back(*z + n - x); t.swap(u); } t.insert(upper_bound(t.begin(), t.end(), p - 1), 2, p - 1); t.insert(lower_bound(t.begin(), t.end(), q), q); t.push_back(n); z = upper_bound(t.begin(), t.end(), p - 1); if (z - t.begin() & 1) --z; for (x = 0; *z < q; x += *z - m, ++z) m = *++z; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; main() { int n, m, p, q, r, x, y; vector<int>::iterator v, w, z; for (; cin >> n >> m >> p >> q >> r; cout << x << endl) { vector<int> t(1), u; for (t.push_back(r); m--; u.clear()) { cin >> x >> y; v = upper_bound(t.begin(), t.end(), x); w = upper_bound(t.begin(), t.end(), y); u.insert(u.end(), w - t.begin() & 1 ? 1 : 2, 0); for (z = w; z < t.end(); ++z) u.push_back(*z - y); if (t.end() - v & 1) u.push_back(n - y); for (z = v; z < w; ++z) u.push_back(*z - x + n - y); z = t.begin(); if (w - t.begin() & 1) ++z; if (!z[1]) z += 2; if (*z + n - x == u.back()) ++z, u.pop_back(); for (; z < v; ++z) u.push_back(*z + n - x); t.swap(u); } t.insert(upper_bound(t.begin(), t.end(), p - 1), 2, p - 1); t.insert(lower_bound(t.begin(), t.end(), q), q); t.push_back(n); z = upper_bound(t.begin(), t.end(), p - 1); if (z - t.begin() & 1) --z; for (x = 0; *z < q; x += *++z - m, ++z) m = *z; } }
[["+", 31, 11, 12, 16, 31, 66, 28, 27, 17, 29], ["-", 8, 1, 0, 11, 12, 66, 28, 27, 17, 29]]
1
454
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, s, e) for (int i = int(s); i <= int(e); i++) #define rep(i, n) for (int i = 0; i < int(n); i++) vector<int> u1, v1, u2, v2; void f(int x, int y, vector<int> &u1, vector<int> &v1, vector<int> &u2, vector<int> &v2) { int c = 0; int a, b, c1, c2; rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= x) { a = i; c1 = c; break; } } c = 0; rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= y) { b = i; c2 = c; break; } } if (c2 != y) { u2.push_back(v1[b] - (c2 - y) + 1); v2.push_back(v1[b]); REP(i, b + 1, u1.size() - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } } else { REP(i, b + 1, u1.size() - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } } if (a != b) { if (c1 != x) { u2.push_back(v1[a] - (c1 - x) + 1); v2.push_back(v1[a]); REP(i, a + 1, b - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } u2.push_back(u1[b]); v2.push_back(v1[b] - (c2 - y)); } else { REP(i, a + 1, b - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } u2.push_back(u1[b]); v2.push_back(v1[b] - (c2 - y)); } } else { u2.push_back(v1[a] - (c1 - x) + 1); u2.push_back(v1[b] - (c2 - y)); } REP(i, 0, a - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } u2.push_back(u1[a]); v2.push_back(v1[a] - (c1 - x)); } int main() { int m, n, p, q, r, x, y; while (1) { cin >> n; if (n == 0) break; cin >> m >> p >> q >> r; REP(i, 1, m) { cin >> x >> y; if (i == 1) { u1.push_back(y + 1); v1.push_back(n); u1.push_back(x + 1); v1.push_back(y); u1.push_back(1); v1.push_back(x); } else if (i % 2 == 0) { u2.clear(); v2.clear(); f(x, y, u1, v1, u2, v2); } else if (i % 2 == 1) { u1.clear(); v1.clear(); f(x, y, u2, v2, u1, v1); } } int s = 0; int c = 0; int a, b, c1, c2; if (m % 2 == 0) { rep(i, u2.size()) { c += v2[i] - u2[i] + 1; if (c >= p) { a = i; c1 = c; break; } } c = 0; rep(i, u2.size()) { c += v2[i] - u2[i] + 1; if (c >= q) { b = i; c2 = c; break; } } if (a != b) { REP(i, v2[a] - (c1 - p), v2[a]) if (i <= r) s++; REP(i, a + 1, b - 1) { REP(j, u2[i], v2[i]) { if (j <= r) s++; } } REP(i, u2[b], v2[b] - (c2 - q)) if (i <= r) s++; } else { REP(i, v2[a] - (c1 - p), v2[a] - (c2 - q)) if (i <= r) s++; } cout << s << endl; } else { rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= p) { a = i; c1 = c; break; } } c = 0; rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= q) { b = i; c2 = c; break; } } if (a != b) { REP(i, v1[a] - (c1 - p), v1[a]) if (i <= r) s++; REP(i, a + 1, b - 1) { REP(j, u1[i], v1[i]) { if (j <= r) s++; } } REP(i, u1[b], v1[b] - (c2 - q)) if (i <= r) s++; } else { REP(i, v1[a] - (c1 - p), v1[a] - (c2 - q)) if (i <= r) s++; } cout << s << endl; } u1.clear(); v1.clear(); u2.clear(); v2.clear(); } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, s, e) for (int i = int(s); i <= int(e); i++) #define rep(i, n) for (int i = 0; i < int(n); i++) vector<int> u1, v1, u2, v2; void f(int x, int y, vector<int> &u1, vector<int> &v1, vector<int> &u2, vector<int> &v2) { int c = 0; int a, b, c1, c2; rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= x) { a = i; c1 = c; break; } } c = 0; rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= y) { b = i; c2 = c; break; } } if (c2 != y) { u2.push_back(v1[b] - (c2 - y) + 1); v2.push_back(v1[b]); REP(i, b + 1, u1.size() - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } } else { REP(i, b + 1, u1.size() - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } } if (a != b) { if (c1 != x) { u2.push_back(v1[a] - (c1 - x) + 1); v2.push_back(v1[a]); REP(i, a + 1, b - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } u2.push_back(u1[b]); v2.push_back(v1[b] - (c2 - y)); } else { REP(i, a + 1, b - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } u2.push_back(u1[b]); v2.push_back(v1[b] - (c2 - y)); } } else { u2.push_back(v1[a] - (c1 - x) + 1); v2.push_back(v1[b] - (c2 - y)); } REP(i, 0, a - 1) { u2.push_back(u1[i]); v2.push_back(v1[i]); } u2.push_back(u1[a]); v2.push_back(v1[a] - (c1 - x)); } int main() { int m, n, p, q, r, x, y; while (1) { cin >> n; if (n == 0) break; cin >> m >> p >> q >> r; REP(i, 1, m) { cin >> x >> y; if (i == 1) { u1.push_back(y + 1); v1.push_back(n); u1.push_back(x + 1); v1.push_back(y); u1.push_back(1); v1.push_back(x); } else if (i % 2 == 0) { u2.clear(); v2.clear(); f(x, y, u1, v1, u2, v2); } else if (i % 2 == 1) { u1.clear(); v1.clear(); f(x, y, u2, v2, u1, v1); } } int s = 0; int c = 0; int a, b, c1, c2; if (m % 2 == 0) { rep(i, u2.size()) { c += v2[i] - u2[i] + 1; if (c >= p) { a = i; c1 = c; break; } } c = 0; rep(i, u2.size()) { c += v2[i] - u2[i] + 1; if (c >= q) { b = i; c2 = c; break; } } if (a != b) { REP(i, v2[a] - (c1 - p), v2[a]) if (i <= r) s++; REP(i, a + 1, b - 1) { REP(j, u2[i], v2[i]) { if (j <= r) s++; } } REP(i, u2[b], v2[b] - (c2 - q)) if (i <= r) s++; } else { REP(i, v2[a] - (c1 - p), v2[a] - (c2 - q)) if (i <= r) s++; } cout << s << endl; } else { rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= p) { a = i; c1 = c; break; } } c = 0; rep(i, u1.size()) { c += v1[i] - u1[i] + 1; if (c >= q) { b = i; c2 = c; break; } } if (a != b) { REP(i, v1[a] - (c1 - p), v1[a]) if (i <= r) s++; REP(i, a + 1, b - 1) { REP(j, u1[i], v1[i]) { if (j <= r) s++; } } REP(i, u1[b], v1[b] - (c2 - q)) if (i <= r) s++; } else { REP(i, v1[a] - (c1 - p), v1[a] - (c2 - q)) if (i <= r) s++; } cout << s << endl; } u1.clear(); v1.clear(); u2.clear(); v2.clear(); } return 0; }
[["-", 0, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 0, 9, 0, 1, 0, 2, 63, 118, 28, 22]]
1
1,346
#include <array> #include <stdio.h> #include <string.h> using namespace std; int n, m, s; array<array<array<int, 3001>, 2001>, 2> memo; int main() { for (;;) { scanf("%d %d %d", &n, &m, &s); if (n == 0) break; for (int i = 0; i <= n * n; ++i) { for (int j = 0; j <= m; ++j) { for (int k = 0; k <= s; ++k) { int ans = 0; if (i == 0) { if (j == 0 && k == 0) ans = 1; else ans = 0; } else { if (j <= 0 || k < j) { ans = 0; } else { ans = memo[(i - 1) % 2][j - 1][k - j] + memo[i % 2][j - 1][k - 1]; } } memo[i % 2][j][k] = ans % 100000; } } } int ans = 0; for (int i = 0; i <= m; ++i) { ans += memo[(n * n) % 2][i][s] % 100000; } printf("%d\n", ans); } return 0; }
#include <array> #include <stdio.h> #include <string.h> using namespace std; int n, m, s; array<array<array<int, 3001>, 2001>, 2> memo; int main() { for (;;) { scanf("%d %d %d", &n, &m, &s); if (n == 0) break; for (int i = 0; i <= n * n; ++i) { for (int j = 0; j <= m; ++j) { for (int k = 0; k <= s; ++k) { int ans = 0; if (i == 0) { if (j == 0 && k == 0) ans = 1; else ans = 0; } else { if (j <= 0 || k < j) { ans = 0; } else { ans = memo[(i - 1) % 2][j - 1][k - j] + memo[i % 2][j - 1][k - 1]; } } memo[i % 2][j][k] = ans % 100000; } } } int ans = 0; for (int i = 0; i <= m; ++i) { ans += memo[(n * n) % 2][i][s]; ans %= 100000; } printf("%d\n", ans); } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 132]]
1
288
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int n, m, h, k; typedef pair<int, int> P; vector<P> ber; long long int x[1001], ax[1001]; long long int sc[1001], scn[1001]; long long int yk[100001][2], ys[100001][2]; int resn; long long int res; long long int ans; int main(void) { while (1) { cin >> n >> m >> h >> k; if (n == 0 && m == 0 && h == 0 && k == 0) break; memset(x, 0, sizeof(x)); memset(ax, 0, sizeof(ax)); memset(sc, 0, sizeof(sc)); memset(scn, 0, sizeof(scn)); memset(yk, 0, sizeof(yk)); memset(ys, 0, sizeof(ys)); res = 0; resn = 0; ans = 0; for (int i = 1; i <= n; i++) { cin >> sc[i]; scn[i] = sc[i]; x[i] = i; ax[i] = i; } for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); ber.push_back(P(b, a)); } sort(ber.begin(), ber.end()); for (int i = 0; i < m; i++) { swap(x[ber[i].second], x[ber[i].second + 1]); } resn = -1; for (int i = m - 1; i >= 0; i--) { ys[i][0] = scn[ber[i].second], ys[i][1] = scn[ber[i].second + 1]; swap(x[ber[i].second], x[ber[i].second + 1]); swap(scn[ber[i].second], scn[ber[i].second + 1]); yk[i][0] = x[ber[i].second], yk[i][1] = x[ber[i].second + 1]; if (yk[i][0] <= k && yk[i][1] > k) { long long int sa = ys[i][1] - ys[i][0]; if (sa >= res) resn = i, res = sa; } if (yk[i][1] <= k && yk[i][0] > k) { long long int sa = ys[i][0] - ys[i][1]; if (sa >= res) resn = i, res = sa; } } for (int i = 0; i < m; i++) { if (i != resn) swap(ax[ber[i].second], ax[ber[i].second + 1]); } for (int i = 1; i <= n; i++) { if (ax[i] <= k) ans += sc[i]; } cout << ans << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int n, m, h, k; typedef pair<int, int> P; vector<P> ber; long long int x[1001], ax[1001]; long long int sc[1001], scn[1001]; long long int yk[100001][2], ys[100001][2]; int resn; long long int res; long long int ans; int main(void) { while (1) { cin >> n >> m >> h >> k; if (n == 0 && m == 0 && h == 0 && k == 0) break; memset(x, 0, sizeof(x)); memset(ax, 0, sizeof(ax)); memset(sc, 0, sizeof(sc)); memset(scn, 0, sizeof(scn)); memset(yk, 0, sizeof(yk)); memset(ys, 0, sizeof(ys)); ber.clear(); res = 0; resn = 0; ans = 0; for (int i = 1; i <= n; i++) { cin >> sc[i]; scn[i] = sc[i]; x[i] = i; ax[i] = i; } for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); ber.push_back(P(b, a)); } sort(ber.begin(), ber.end()); for (int i = 0; i < m; i++) { swap(x[ber[i].second], x[ber[i].second + 1]); } resn = -1; for (int i = m - 1; i >= 0; i--) { ys[i][0] = scn[ber[i].second], ys[i][1] = scn[ber[i].second + 1]; swap(x[ber[i].second], x[ber[i].second + 1]); swap(scn[ber[i].second], scn[ber[i].second + 1]); yk[i][0] = x[ber[i].second], yk[i][1] = x[ber[i].second + 1]; if (yk[i][0] <= k && yk[i][1] > k) { long long int sa = ys[i][1] - ys[i][0]; if (sa >= res) resn = i, res = sa; } if (yk[i][1] <= k && yk[i][0] > k) { long long int sa = ys[i][0] - ys[i][1]; if (sa >= res) resn = i, res = sa; } } for (int i = 0; i < m; i++) { if (i != resn) swap(ax[ber[i].second], ax[ber[i].second + 1]); } for (int i = 1; i <= n; i++) { if (ax[i] <= k) ans += sc[i]; } cout << ans << endl; } return 0; }
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
732
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int n, m, h, k; typedef pair<int, int> P; vector<P> ber; long long int x[1001], ax[1001]; long long int sc[1001], scn[1001]; long long int yk[100001][2], ys[100001][2]; int resn; long long int res; long long int ans; int main(void) { while (1) { scanf("%d%d%d%d", &n, &m, &h, &k); if (n == 0 && m == 0 && h == 0 && k == 0) break; memset(x, 0, sizeof(x)); memset(ax, 0, sizeof(ax)); memset(sc, 0, sizeof(sc)); memset(scn, 0, sizeof(scn)); memset(yk, 0, sizeof(yk)); memset(ys, 0, sizeof(ys)); ber.clear(); res = 0; ans = 0; for (int i = 1; i <= n; i++) { scanf("%lld", sc[i]); scn[i] = sc[i]; x[i] = i; ax[i] = i; } for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); ber.push_back(P(b, a)); } sort(ber.begin(), ber.end()); for (int i = 0; i < m; i++) { swap(x[ber[i].second], x[ber[i].second + 1]); } resn = -1; for (int i = m - 1; i >= 0; i--) { ys[i][0] = scn[ber[i].second], ys[i][1] = scn[ber[i].second + 1]; swap(x[ber[i].second], x[ber[i].second + 1]); swap(scn[ber[i].second], scn[ber[i].second + 1]); yk[i][0] = x[ber[i].second], yk[i][1] = x[ber[i].second + 1]; if (yk[i][0] <= k && yk[i][1] > k) { long long int sa = ys[i][1] - ys[i][0]; if (sa >= res) resn = i, res = sa; } if (yk[i][1] <= k && yk[i][0] > k) { long long int sa = ys[i][0] - ys[i][1]; if (sa >= res) resn = i, res = sa; } } for (int i = 0; i < m; i++) { if (i != resn) swap(ax[ber[i].second], ax[ber[i].second + 1]); } for (int i = 1; i <= n; i++) { if (ax[i] <= k) ans += sc[i]; } printf("%lld\n", ans); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; int n, m, h, k; typedef pair<int, int> P; vector<P> ber; long long int x[1001], ax[1001]; long long int sc[1001], scn[1001]; long long int yk[100001][2], ys[100001][2]; int resn; long long int res; long long int ans; int main(void) { while (1) { scanf("%d%d%d%d", &n, &m, &h, &k); if (n == 0 && m == 0 && h == 0 && k == 0) break; memset(x, 0, sizeof(x)); memset(ax, 0, sizeof(ax)); memset(sc, 0, sizeof(sc)); memset(scn, 0, sizeof(scn)); memset(yk, 0, sizeof(yk)); memset(ys, 0, sizeof(ys)); ber.clear(); res = 0; ans = 0; for (int i = 1; i <= n; i++) { scanf("%lld", &sc[i]); scn[i] = sc[i]; x[i] = i; ax[i] = i; } for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); ber.push_back(P(b, a)); } sort(ber.begin(), ber.end()); for (int i = 0; i < m; i++) { swap(x[ber[i].second], x[ber[i].second + 1]); } resn = -1; for (int i = m - 1; i >= 0; i--) { ys[i][0] = scn[ber[i].second], ys[i][1] = scn[ber[i].second + 1]; swap(x[ber[i].second], x[ber[i].second + 1]); swap(scn[ber[i].second], scn[ber[i].second + 1]); yk[i][0] = x[ber[i].second], yk[i][1] = x[ber[i].second + 1]; if (yk[i][0] <= k && yk[i][1] > k) { long long int sa = ys[i][1] - ys[i][0]; if (sa >= res) resn = i, res = sa; } if (yk[i][1] <= k && yk[i][0] > k) { long long int sa = ys[i][0] - ys[i][1]; if (sa >= res) resn = i, res = sa; } } for (int i = 0; i < m; i++) { if (i != resn) swap(ax[ber[i].second], ax[ber[i].second + 1]); } for (int i = 1; i <= n; i++) { if (ax[i] <= k) ans += sc[i]; } printf("%lld\n", ans); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
1
752
#include "stdio.h" #include "stdlib.h" int s[1000]; typedef struct { int a; int b; int w1; int w2; } yoko; yoko w[100000]; int z[1000]; int ten[1000]; int sortw(const void *a, const void *b) { if (((yoko *)a)[0].a < ((yoko *)b)[0].a) { return -1; } else if (((yoko *)a)[0].a == ((yoko *)b)[0].a) { return 0; } else { return 1; } } int ans[1000]; int main() { int nww = 0; while (1) { int n, m, h, k; scanf("%d %d %d %d", &n, &m, &h, &k); if (n == 0 && m == 0 && h == 0 && k == 0) { break; } for (int i = 0; i < n; i++) { scanf("%d", &(s[i])); } for (int i = 0; i < m; i++) { scanf("%d %d", &(w[i].a), &(w[i].b)); } qsort(w, m, sizeof(yoko), sortw); for (int i = 0; i < n; i++) { z[i] = i; } int d; for (int i = 0; i < m; i++) { w[i].w1 = z[w[i].b]; w[i].w2 = z[w[i].b - 1]; d = z[w[i].b]; z[w[i].b] = z[w[i].b - 1]; z[w[i].b - 1] = d; } for (int i = 0; i < n; i++) { ten[z[i]] = s[i]; } int min; int www = 0; for (int i = 0; i < k; i++) { www = www + ten[i]; } min = www; for (int i = 0; i < m; i++) { d = ten[w[i].w1]; ten[w[i].w1] = ten[w[i].w2]; ten[w[i].w2] = d; www = 0; for (int i = 0; i < k; i++) { www = www + ten[i]; } if (www < min) { min = www; } d = ten[w[i].w1]; ten[w[i].w1] = ten[w[i].w2]; ten[w[i].w2] = d; } ans[nww] = min; nww++; } for (int i = 0; i < nww; i++) { printf("%d\n", ans[i]); } return 0; }
#include "stdio.h" #include "stdlib.h" int s[1000]; typedef struct { int a; int b; int w1; int w2; } yoko; yoko w[100000]; int z[1000]; int ten[1000]; int sortw(const void *a, const void *b) { if (((yoko *)a)[0].a < ((yoko *)b)[0].a) { return -1; } else if (((yoko *)a)[0].a == ((yoko *)b)[0].a) { return 0; } else { return 1; } } int ans[1000]; int main() { int nww = 0; while (1) { int n, m, h, k; scanf("%d %d %d %d", &n, &m, &h, &k); if (n == 0 && m == 0 && h == 0 && k == 0) { break; } for (int i = 0; i < n; i++) { scanf("%d", &(s[i])); } for (int i = 0; i < m; i++) { scanf("%d %d", &(w[i].b), &(w[i].a)); } qsort(w, m, sizeof(yoko), sortw); for (int i = 0; i < n; i++) { z[i] = i; } int d; for (int i = 0; i < m; i++) { w[i].w1 = z[w[i].b]; w[i].w2 = z[w[i].b - 1]; d = z[w[i].b]; z[w[i].b] = z[w[i].b - 1]; z[w[i].b - 1] = d; } for (int i = 0; i < n; i++) { ten[z[i]] = s[i]; } int min; int www = 0; for (int i = 0; i < k; i++) { www = www + ten[i]; } min = www; for (int i = 0; i < m; i++) { d = ten[w[i].w1]; ten[w[i].w1] = ten[w[i].w2]; ten[w[i].w2] = d; www = 0; for (int i = 0; i < k; i++) { www = www + ten[i]; } if (www < min) { min = www; } d = ten[w[i].w1]; ten[w[i].w1] = ten[w[i].w2]; ten[w[i].w2] = d; } ans[nww] = min; nww++; } for (int i = 0; i < nww; i++) { printf("%d\n", ans[i]); } return 0; }
[["-", 3, 4, 0, 66, 28, 23, 0, 118, 119, 120], ["+", 3, 4, 0, 66, 28, 23, 0, 118, 119, 120]]
1
678
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { while (true) { int H = sc.nextInt(); int W = sc.nextInt(); int N = sc.nextInt(); if (N == 0) break; boolean[][] dir = new boolean[H][W]; sc.nextLine(); for (int i = 0; i < H; ++i) { String line = sc.nextLine(); for (int j = 0; j < W; ++j) { dir[i][j] = line.charAt(j * 2) == '1'; } } int[][] count = new int[H + 1][W + 1]; count[0][0] = N - 1; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { count[i + 1][j] = count[i][j] / 2; count[i][j + 1] = count[i][j] / 2; if (count[i][j] % 2 == 1) { if (dir[i][j]) { count[i][j + 1] += 1; } else { count[i + 1][j] += 1; } dir[i][j] = !dir[i][j]; } } } int r = 0; int c = 0; while (r < H && c < W) { if (dir[r][c]) { ++c; } else { ++r; } } System.out.println((r + 1) + " " + (c + 1)); } } }
import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { while (true) { int H = sc.nextInt(); int W = sc.nextInt(); int N = sc.nextInt(); if (N == 0) break; boolean[][] dir = new boolean[H][W]; sc.nextLine(); for (int i = 0; i < H; ++i) { String line = sc.nextLine(); for (int j = 0; j < W; ++j) { dir[i][j] = line.charAt(j * 2) == '1'; } } int[][] count = new int[H + 1][W + 1]; count[0][0] = N - 1; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { count[i + 1][j] += count[i][j] / 2; count[i][j + 1] += count[i][j] / 2; if (count[i][j] % 2 == 1) { if (dir[i][j]) { count[i][j + 1] += 1; } else { count[i + 1][j] += 1; } dir[i][j] = !dir[i][j]; } } } int r = 0; int c = 0; while (r < H && c < W) { if (dir[r][c]) { ++c; } else { ++r; } } System.out.println((r + 1) + " " + (c + 1)); } } }
[["-", 0, 7, 8, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 17, 107]]
3
401
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { StringTokenizer tok = new StringTokenizer(br.readLine()); final int h = Integer.parseInt(tok.nextToken()); final int w = Integer.parseInt(tok.nextToken()); final int n = Integer.parseInt(tok.nextToken()); if (h == 0 && w == 0 && n == 0) { break; } boolean[][] map = new boolean[h][w]; for (int i = 0; i < h; i++) { StringTokenizer tok2 = new StringTokenizer(br.readLine()); for (int j = 0; j < w; j++) { map[i][j] = tok2.nextToken().equals("1"); } } int[][] dp = new int[h][w]; dp[0][0] = n - 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (dp[i][j] % 2 == 0) { if (i != h - 1) { dp[i + 1][j] = dp[i][j] / 2; } if (j != w - 1) { dp[i][j + 1] = dp[i][j] / 2; } } else { if (i != h - 1) { dp[i + 1][j] = dp[i][j] / 2 + (map[i][j] ? 0 : 1); } if (j != w - 1) { dp[i][j + 1] = dp[i][j] / 2 + (map[i][j] ? 1 : 0); } } } } int cur_x = 0; int cur_y = 0; while (cur_x != w && cur_y != h) { if (dp[cur_y][cur_x] % 2 == 0) { int n_x, n_y; n_x = cur_x + (map[cur_y][cur_x] ? 1 : 0); n_y = cur_y + (map[cur_y][cur_x] ? 0 : 1); cur_x = n_x; cur_y = n_y; } else { int n_x, n_y; n_x = cur_x + (map[cur_y][cur_x] ? 0 : 1); n_y = cur_y + (map[cur_y][cur_x] ? 1 : 0); cur_x = n_x; cur_y = n_y; } } System.out.println((cur_y + 1) + " " + (cur_x + 1)); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (true) { StringTokenizer tok = new StringTokenizer(br.readLine()); final int h = Integer.parseInt(tok.nextToken()); final int w = Integer.parseInt(tok.nextToken()); final int n = Integer.parseInt(tok.nextToken()); if (h == 0 && w == 0 && n == 0) { break; } boolean[][] map = new boolean[h][w]; for (int i = 0; i < h; i++) { StringTokenizer tok2 = new StringTokenizer(br.readLine()); for (int j = 0; j < w; j++) { map[i][j] = tok2.nextToken().equals("1"); } } int[][] dp = new int[h][w]; dp[0][0] = n - 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (dp[i][j] % 2 == 0) { if (i != h - 1) { dp[i + 1][j] += dp[i][j] / 2; } if (j != w - 1) { dp[i][j + 1] += dp[i][j] / 2; } } else { if (i != h - 1) { dp[i + 1][j] += dp[i][j] / 2 + (map[i][j] ? 0 : 1); } if (j != w - 1) { dp[i][j + 1] += dp[i][j] / 2 + (map[i][j] ? 1 : 0); } } } } /* for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ System.out.print(dp[i][j] + " "); } System.out.println(); } for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ System.out.print((dp[i][j] % 2 == 0 ? map[i][j] : !map[i][j]) + " "); } System.out.println(); } */ int cur_x = 0; int cur_y = 0; while (cur_x != w && cur_y != h) { if (dp[cur_y][cur_x] % 2 == 0) { int n_x, n_y; n_x = cur_x + (map[cur_y][cur_x] ? 1 : 0); n_y = cur_y + (map[cur_y][cur_x] ? 0 : 1); cur_x = n_x; cur_y = n_y; } else { int n_x, n_y; n_x = cur_x + (map[cur_y][cur_x] ? 0 : 1); n_y = cur_y + (map[cur_y][cur_x] ? 1 : 0); cur_x = n_x; cur_y = n_y; } } System.out.println((cur_y + 1) + " " + (cur_x + 1)); } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 17, 107]]
3
629
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < ((int)b); ++i) #define RFOR(i, a) for (int i = (a); i >= 0; --i) #define FOE(i, a) for (auto i : a) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define DUMP(x) cerr << #x << " = " << (x) << endl; #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) #define BIT(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); typedef long long LL; template <typename T> using V = std::vector<T>; template <typename T> using VV = std::vector<std::vector<T>>; template <typename T> using VVV = std::vector<std::vector<std::vector<T>>>; template <class T> inline T ceil(T a, T b) { return (a + b - 1) / b; } template <class T> inline void print(T x) { std::cout << x << std::endl; } template <class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) { if (i != 0) { std::cout << " "; } std::cout << v[i]; } std::cout << "\n"; } template <class T> inline bool inside(T y, T x, T H, T W) { return 0 <= y and y < H and 0 <= x and x < W; } template <class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); } const int INF = 1L << 30; const double EPS = 1e-9; const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No"; const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0}; // 4近傍(右, 下, 左, 上) const std::vector<int> dy8 = {0, -1, 0, 1, 1, -1, -1, 1}, dx8 = {1, 0, -1, 0, 1, 1, -1, -1}; using namespace std; pair<int, int> solve(int H, int W, int N, vector<vector<int>> f) { vector<vector<int>> dp(H + 1, vector<int>(W + 1, 0)); dp[0][0] = N - 1; FOR(y, 0, H) { FOR(x, 0, W) { int num = dp[y][x]; if (num % 2 == 0) { dp[y + 1][x] += num / 2; dp[y][x + 1] += num / 2; } else { if (f[y][x] == 0) { dp[y + 1][x] += num - (num / 2); dp[y][x + 1] += num / 2; } if (f[y][x] == 1) { dp[y + 1][x] += num / 2; dp[y][x + 1] += num - (num / 2); } } } } FOR(y, 0, H) { FOR(x, 0, W) { if (dp[y][x] % 2 != 0) { f[y][x] = 1 - f[y][x]; } } } int y = 0, x = 0; while (true) { int p = f[y][x]; if (p == 0) { y += 1; } else { x += 1; } if (y == H or x == W) { break; } } return make_pair(y, x); } int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { int H, W, N; cin >> H >> W >> N; if (H == 0 and W == 0 and N == 0) { break; } vector<vector<int>> f(H + 1, vector<int>(W + 1)); FOR(y, 0, H) { FOR(x, 0, W) { cin >> f[y][x]; } } auto ans1 = solve(H, W, N, f); cout << ans1.first + 1 << "" << ans1.second + 1 << endl; } return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < ((int)b); ++i) #define RFOR(i, a) for (int i = (a); i >= 0; --i) #define FOE(i, a) for (auto i : a) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define DUMP(x) cerr << #x << " = " << (x) << endl; #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) #define BIT(n) (1LL << (n)) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); typedef long long LL; template <typename T> using V = std::vector<T>; template <typename T> using VV = std::vector<std::vector<T>>; template <typename T> using VVV = std::vector<std::vector<std::vector<T>>>; template <class T> inline T ceil(T a, T b) { return (a + b - 1) / b; } template <class T> inline void print(T x) { std::cout << x << std::endl; } template <class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) { if (i != 0) { std::cout << " "; } std::cout << v[i]; } std::cout << "\n"; } template <class T> inline bool inside(T y, T x, T H, T W) { return 0 <= y and y < H and 0 <= x and x < W; } template <class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); } const int INF = 1L << 30; const double EPS = 1e-9; const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No"; const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0}; // 4近傍(右, 下, 左, 上) const std::vector<int> dy8 = {0, -1, 0, 1, 1, -1, -1, 1}, dx8 = {1, 0, -1, 0, 1, 1, -1, -1}; using namespace std; pair<int, int> solve(int H, int W, int N, vector<vector<int>> f) { vector<vector<int>> dp(H + 1, vector<int>(W + 1, 0)); dp[0][0] = N - 1; FOR(y, 0, H) { FOR(x, 0, W) { int num = dp[y][x]; if (num % 2 == 0) { dp[y + 1][x] += num / 2; dp[y][x + 1] += num / 2; } else { if (f[y][x] == 0) { dp[y + 1][x] += num - (num / 2); dp[y][x + 1] += num / 2; } if (f[y][x] == 1) { dp[y + 1][x] += num / 2; dp[y][x + 1] += num - (num / 2); } } } } FOR(y, 0, H) { FOR(x, 0, W) { if (dp[y][x] % 2 != 0) { f[y][x] = 1 - f[y][x]; } } } int y = 0, x = 0; while (true) { int p = f[y][x]; if (p == 0) { y += 1; } else { x += 1; } if (y == H or x == W) { break; } } return make_pair(y, x); } int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { int H, W, N; cin >> H >> W >> N; if (H == 0 and W == 0 and N == 0) { break; } vector<vector<int>> f(H + 1, vector<int>(W + 1)); FOR(y, 0, H) { FOR(x, 0, W) { cin >> f[y][x]; } } auto ans1 = solve(H, W, N, f); cout << ans1.first + 1 << " " << ans1.second + 1 << endl; } return 0; }
[["+", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6]]
1
1,035
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int d[1024][1024]; int dp[1024][1024]; int H, W, N; int main() { while (scanf("%d%d%d", &H, &W, &N) && H || W || N) { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) scanf("%d", &d[i][j]); memset(dp, 0, sizeof dp); dp[0][0] = N - 1; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { dp[i + 1][j] += (dp[i][j] + d[i][j] ^ 1) / 2; dp[i][j + 1] += (dp[i][j] + d[i][j]) / 2; } } for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) d[i][j] = (d[i][j] + dp[i][j]) % 2; int y = 0, x = 0; while (y < H && x < W) { if (d[y][x]) x++; else y++; } printf("%d %d\n", y + 1, x + 1); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; int d[1024][1024]; int dp[1024][1024]; int H, W, N; int main() { while (scanf("%d%d%d", &H, &W, &N) && H || W || N) { for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) scanf("%d", &d[i][j]); memset(dp, 0, sizeof dp); dp[0][0] = N - 1; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { dp[i + 1][j] += (dp[i][j] + (d[i][j] ^ 1)) / 2; dp[i][j + 1] += (dp[i][j] + d[i][j]) / 2; } } for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) d[i][j] = (d[i][j] + dp[i][j]) % 2; int y = 0, x = 0; while (y < H && x < W) { if (d[y][x]) x++; else y++; } printf("%d %d\n", y + 1, x + 1); } return 0; }
[["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 12, 16, 31, 23, 0, 16, 12, 23, 0, 25]]
1
340
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define MAX_N 2000 long long x[MAX_N][MAX_N]; long long dp[MAX_N][MAX_N]; int h, w, n, cx, cy; int main() { while (true) { memset(dp, 0, sizeof(dp)); cin >> h >> w >> n; if (h == 0 && w == 0 && n == 0) { break; } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { scanf("%d", x[i][j]); } } dp[1][1] = n - 1; for (int i = 2; i <= h + w; i++) { for (int j = 1; j <= w; j++) { int k = i - j; if (j <= h && k <= w) { if (x[j][k] == 0) { dp[j][k + 1] += dp[j][k] / 2; dp[j + 1][k] += (dp[j][k] + 1) / 2; } else { dp[j][k + 1] += (dp[j][k] + 1) / 2; dp[j + 1][k] += dp[j][k] / 2; } } } } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { x[i][j] += dp[i][j]; x[i][j] %= 2; } } cx = 1; cy = 1; while (cx <= w && cy <= h) { if (x[cy][cx] == 0) { cy++; } else { cx++; } } cout << cy << ' ' << cx << endl; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; #define MAX_N 2000 long long x[MAX_N][MAX_N]; long long dp[MAX_N][MAX_N]; int h, w, n, cx, cy; int main() { while (true) { memset(dp, 0, sizeof(dp)); cin >> h >> w >> n; if (h == 0 && w == 0 && n == 0) { break; } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { scanf("%d", &x[i][j]); } } dp[1][1] = n - 1; for (int i = 2; i <= h + w; i++) { for (int j = 1; j <= h; j++) { int k = i - j; if (k >= 1 && k <= w) { if (x[j][k] == 0) { dp[j][k + 1] += dp[j][k] / 2; dp[j + 1][k] += (dp[j][k] + 1) / 2; } else { dp[j][k + 1] += (dp[j][k] + 1) / 2; dp[j + 1][k] += dp[j][k] / 2; } } } } for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { x[i][j] += dp[i][j]; x[i][j] %= 2; } } cx = 1; cy = 1; while (cx <= w && cy <= h) { if (x[cy][cx] == 0) { cy++; } else { cx++; } } cout << cy << ' ' << cx << endl; } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 13]]
1
427
#include <algorithm> #include <bits/stdc++.h> #include <queue> #include <vector> using namespace std; typedef long long ll; int h, w, n, c[1000][1000]; int dp[1001][1001]; int d[1000][1000]; int main() { while (scanf("%d%d%d", &h, &w, &n), h) { for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &c[i][j]); for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) dp[i][j] = 0; dp[1][1] = n - 1; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { if (i != 1) { if (c[i - 2][j - 1] == 0) dp[i][j] += (dp[i - 1][j] + 1) / 2; else dp[i][j] += dp[i - 1][j] / 2; } if (j != 1) { if (c[i - 1][j - 2] == 1) dp[i][j] += (dp[i][j - 1] + 1) / 2; else dp[i][j] += dp[i][j] / 2; } } for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) d[i][j] = (c[i][j] + dp[i + 1][j + 1]) % 2; int i = 1, j = 1; while (i <= h && j <= w) { if (d[i - 1][j - 1]) j++; else i++; } printf("%d %d\n", i, j); } }
#include <algorithm> #include <bits/stdc++.h> #include <queue> #include <vector> using namespace std; typedef long long ll; int h, w, n, c[1000][1000]; int dp[1001][1001]; int d[1000][1000]; int main() { while (scanf("%d%d%d", &h, &w, &n), h) { for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &c[i][j]); for (int i = 0; i <= 1000; i++) for (int j = 0; j <= 1000; j++) dp[i][j] = 0; dp[1][1] = n - 1; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) { if (i != 1) { if (c[i - 2][j - 1] == 0) dp[i][j] += (dp[i - 1][j] + 1) / 2; else dp[i][j] += dp[i - 1][j] / 2; } if (j != 1) { if (c[i - 1][j - 2] == 1) dp[i][j] += (dp[i][j - 1] + 1) / 2; else dp[i][j] += dp[i][j - 1] / 2; } } for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) d[i][j] = (c[i][j] + dp[i + 1][j + 1]) % 2; int i = 1, j = 1; while (i <= h && j <= w) { if (d[i - 1][j - 1]) j++; else i++; } printf("%d %d\n", i, j); } }
[["+", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
452
class in { struct It { int it; const bool rev; explicit constexpr It(int it_, bool rev = false) : it(it_), rev(rev) {} int operator*() { return it; } bool operator!=(It &r) { return it != r.it; } void operator++() { rev ? --it : ++it; } }; const It i, n; public: explicit constexpr in(int n) : i(0), n(n < 0 ? 0 : n) {} explicit constexpr in(int i, int n) : i(i, n < i), n(n) {} const It &begin() { return i; } const It &end() { return n; } }; #include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w, n; while (cin >> h >> w >> n && h) { vector<vector<int>> fld(h + 1, vector<int>(w + 1, -1)); for (int i : in(h)) for (int j : in(w)) cin >> fld[i][j]; vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0)); dp[0][0] = n - 1; for (int i : in(h)) for (int j : in(w)) { dp[i + 1][j] += (dp[i][j] + fld[i][j]) >> 1; dp[i][j + 1] += (dp[i][j] + !fld[i][j]) >> 1; } int x = 0, y = 0; while (true) { if (fld[y][x] == -1) { cout << y + 1 << ' ' << x + 1 << endl; break; } int num = fld[y][x]; if (dp[y][x] & 1) num ^= 1; if (num) ++x; else ++y; } } return 0; }
class in { struct It { int it; const bool rev; explicit constexpr It(int it_, bool rev = false) : it(it_), rev(rev) {} int operator*() { return it; } bool operator!=(It &r) { return it != r.it; } void operator++() { rev ? --it : ++it; } }; const It i, n; public: explicit constexpr in(int n) : i(0), n(n < 0 ? 0 : n) {} explicit constexpr in(int i, int n) : i(i, n < i), n(n) {} const It &begin() { return i; } const It &end() { return n; } }; #include <bits/stdc++.h> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w, n; while (cin >> h >> w >> n && h) { vector<vector<int>> fld(h + 1, vector<int>(w + 1, -1)); for (int i : in(h)) for (int j : in(w)) cin >> fld[i][j]; vector<vector<int>> dp(h + 1, vector<int>(w + 1, 0)); dp[0][0] = n - 1; for (int i : in(h)) for (int j : in(w)) { dp[i + 1][j] += (dp[i][j] + !fld[i][j]) >> 1; dp[i][j + 1] += (dp[i][j] + fld[i][j]) >> 1; } int x = 0, y = 0; while (true) { if (fld[y][x] == -1) { cout << y + 1 << ' ' << x + 1 << endl; break; } int num = fld[y][x]; if (dp[y][x] & 1) num ^= 1; if (num) ++x; else ++y; } } return 0; }
[["+", 12, 16, 31, 23, 0, 16, 12, 91, 17, 111], ["-", 12, 16, 31, 23, 0, 16, 12, 91, 17, 111]]
1
476
#include <bits/stdc++.h> using namespace std; #define int long long #define PB push_back #define ALL(V) V.begin(), V.end() typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef pair<pii, int> ppiii; constexpr int INF = 1LL << 60; constexpr int MOD = 1000000007; // constexpr int MAX_N = 1005; constexpr int MAX_H = 1005; constexpr int dx[] = {0, 1}; constexpr int dy[] = {1, 0}; int h, w, n, fld[MAX_H][MAX_H], dp[MAX_H][MAX_H]; bool Solve() { cin >> h >> w >> n; if (!h) return false; memset(fld, -1, sizeof(fld)); memset(dp, 0, sizeof(dp)); for (int y = 1; y <= h; ++y) { for (int x = 1; x <= w; ++x) { cin >> fld[x][y]; } } dp[1][1] = n - 1; for (int y = 1; y <= h; ++y) { for (int x = (y == 1 ? 2 : 1); x <= w; ++x) { for (int i = 0; i < 2; ++i) { int tx = x - dx[i], ty = y - dy[i]; dp[x][y] += dp[tx][ty] / 2 + (dp[tx][ty] % 2 && fld[tx][ty] == i) ? 1 : 0; } } } for (int y = 1; y <= h; ++y) { for (int x = 1; x <= w; ++x) { fld[x][y] += dp[x][y]; fld[x][y] %= 2; } } { int x = 1, y = 1; while (fld[x][y] != -1) { int nx = x + dx[fld[x][y]]; y += dy[fld[x][y]]; x = nx; } cout << y << " " << x << endl; } return true; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); while (Solve()) ; }
#include <bits/stdc++.h> using namespace std; #define int long long #define PB push_back #define ALL(V) V.begin(), V.end() typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef pair<pii, int> ppiii; constexpr int INF = 1LL << 60; constexpr int MOD = 1000000007; // constexpr int MAX_N = 1005; constexpr int MAX_H = 1005; constexpr int dx[] = {0, 1}; constexpr int dy[] = {1, 0}; int h, w, n, fld[MAX_H][MAX_H], dp[MAX_H][MAX_H]; bool Solve() { cin >> h >> w >> n; if (!h) return false; memset(fld, -1, sizeof(fld)); memset(dp, 0, sizeof(dp)); for (int y = 1; y <= h; ++y) { for (int x = 1; x <= w; ++x) { cin >> fld[x][y]; } } dp[1][1] = n - 1; for (int y = 1; y <= h; ++y) { for (int x = (y == 1 ? 2 : 1); x <= w; ++x) { for (int i = 0; i < 2; ++i) { int tx = x - dx[i], ty = y - dy[i]; dp[x][y] += dp[tx][ty] / 2 + (dp[tx][ty] % 2 && fld[tx][ty] == i ? 1 : 0); } } } for (int y = 1; y <= h; ++y) { for (int x = 1; x <= w; ++x) { fld[x][y] += dp[x][y]; fld[x][y] %= 2; } } { int x = 1, y = 1; while (fld[x][y] != -1) { int nx = x + dx[fld[x][y]]; y += dy[fld[x][y]]; x = nx; } cout << y << " " << x << endl; } return true; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); while (Solve()) ; }
[["-", 0, 11, 12, 41, 15, 16, 12, 23, 0, 25], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
1
490
#include <cstdio> using namespace std; bool grid[1000][1000]; int num[1001][1001]; int h, w, n, tmp; int main() { while (scanf("%d %d %d", &h, &w, &n) && (h || w || n)) { for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { scanf("%d", &tmp); grid[i][j] = (tmp) ? true : false; num[i][j] = 0; } num[0][0] = n - 1; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { int N = num[i][j]; if (grid[i][j]) { num[i + 1][j] += N / 2; num[i][j + 1] += N - N / 2; } else { num[i][j + 1] += N / 2; num[i + 1][j] += N - N / 2; } if (N & 1) grid[i][j] = ~grid[i][j]; } int y = 0, x = 0; while (y < h && x < w) { if (grid[y][x]) x++; else y++; } printf("%d %d\n", y + 1, x + 1); } }
#include <cstdio> using namespace std; bool grid[1000][1000]; int num[1001][1001]; int h, w, n, tmp; int main() { while (scanf("%d %d %d", &h, &w, &n) && (h || w || n)) { for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { scanf("%d", &tmp); grid[i][j] = (tmp) ? true : false; num[i][j] = 0; } num[0][0] = n - 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int N = num[i][j]; if (grid[i][j]) { num[i + 1][j] += N / 2; num[i][j + 1] += N - N / 2; } else { num[i][j + 1] += N / 2; num[i + 1][j] += N - N / 2; } if (N & 1) grid[i][j] = !grid[i][j]; } } int y = 0, x = 0; while (y < h && x < w) { if (grid[y][x]) x++; else y++; } printf("%d %d\n", y + 1, x + 1); } }
[["+", 0, 52, 8, 9, 0, 7, 8, 9, 0, 45], ["-", 0, 57, 64, 1, 0, 11, 12, 91, 17, 92], ["+", 0, 57, 64, 1, 0, 11, 12, 91, 17, 111], ["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46]]
1
338
#include <cstdio> #include <vector> int **getarray(int w, int h) { int **a = new int *[w]; for (int i = 0; i < w; i++) { a[i] = new int[h]; } return a; } int remarray(int **a, int w, int h) { for (int i = 0; i < w; i++) { delete[] a[i]; } delete[] a; } int main() { int h, w, n; int self; int **d; int **m; while (1) { scanf("%d %d %d", &h, &w, &n); if (!h && !w && !n) { break; } d = getarray(w + 1, h + 1); m = getarray(w + 1, h + 1); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { scanf("%d", &self); m[j][i] = self; } } d[0][0] = n - 1; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { if (i == 0 && j == 0) { continue; } d[i][j] = 0; if (i != 0 && d[i - 1][j] > 0) { d[i][j] += (d[i - 1][j]) / 2; if (m[i - 1][j] == 1) { d[i][j] += (d[i - 1][j]) % 2; } } if (j != 0 && d[i][j - 1] > 0) { d[i][j] += (d[i][j - 1]) / 2; if (m[i][j - 1] == 0) { d[i][j] += (d[i][j - 1]) % 2; } } } } for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { m[i][j] = (m[i][j] + d[i][j]) % 2; // printf("%d ",m[i][j]); } // printf("\n"); } int x, y; x = y = 0; while (x < w && y < h) { if (m[x][y] == 1) { // printf("ツ督圭n"); x += 1; } else { // printf("ツ禿ャ\n"); y += 1; } } printf("%d %d\n", x + 1, y + 1); remarray(m, w + 1, h + 1); remarray(d, w + 1, h + 1); } }
#include <cstdio> #include <vector> int **getarray(int w, int h) { int **a = new int *[w]; for (int i = 0; i < w; i++) { a[i] = new int[h]; } return a; } int remarray(int **a, int w, int h) { for (int i = 0; i < w; i++) { delete[] a[i]; } delete[] a; } int main() { int h, w, n; int self; int **d; int **m; while (1) { scanf("%d %d %d", &h, &w, &n); if (!h && !w && !n) { break; } d = getarray(w + 1, h + 1); m = getarray(w + 1, h + 1); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { scanf("%d", &self); m[j][i] = self; } } d[0][0] = n - 1; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { if (i == 0 && j == 0) { continue; } d[i][j] = 0; if (i != 0 && d[i - 1][j] > 0) { d[i][j] += (d[i - 1][j]) / 2; if (m[i - 1][j] == 1) { d[i][j] += (d[i - 1][j]) % 2; } } if (j != 0 && d[i][j - 1] > 0) { d[i][j] += (d[i][j - 1]) / 2; if (m[i][j - 1] == 0) { d[i][j] += (d[i][j - 1]) % 2; } } } } for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { m[i][j] = (m[i][j] + d[i][j]) % 2; // printf("%d ",m[i][j]); } // printf("\n"); } int x, y; x = y = 0; while (x < w && y < h) { if (m[x][y] == 1) { // printf("ツ督圭n"); x += 1; } else { // printf("ツ禿ャ\n"); y += 1; } } printf("%d %d\n", y + 1, x + 1); remarray(m, w + 1, h + 1); remarray(d, w + 1, h + 1); } }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22]]
1
627
#include <cstring> #include <iostream> using namespace std; int map[1002][1002]; long long int dp[1002][1002]; long long int x, y; int h, w; long int n; void root(int xx, int yy) { x = xx, y = yy; if (xx <= w && yy <= h) { if (map[xx][yy] == 1) { root(xx + 1, yy); } else { root(xx, yy + 1); } } } int main(void) { int a, b, c; while (1) { memset(map, 0, sizeof(map)); memset(dp, 0, sizeof(dp)); scanf("%d%d%d", &h, &w, &n); if (h == 0 && w == 0 && n == 0) break; for (a = 1; a <= h; a++) { for (b = 1; b <= w; b++) { scanf("%d", &map[b][a]); } } dp[1][1] = n - 1; for (a = 1; a <= h; a++) { for (b = 1; b <= w; b++) { if (dp[b][a] % 2 == 0) dp[b + 1][a] = dp[b][a] / 2; else { if (map[b][a] == 1) dp[b + 1][a] = (dp[b][a] + 1) / 2; if (map[b][a] == 0) dp[b + 1][a] = (dp[b][a] - 1) / 2; } if (dp[b][a] % 2 == 0) dp[b][a + 1] = dp[b][a] / 2; else { if (map[b][a] == 1) dp[b][a + 1] = (dp[b][a] - 1) / 2; if (map[b][a] == 0) dp[b][a + 1] = (dp[b][a] + 1) / 2; } } } for (a = 1; a <= h; a++) { for (b = 1; b <= w; b++) { map[b][a] = (map[b][a] + dp[b][a]) % 2; } } root(1, 1); cout << y << " " << x << endl; } return 0; }
#include <cstring> #include <iostream> using namespace std; int map[1002][1002]; long long int dp[1002][1002]; long long int x, y; int h, w; long int n; void root(int xx, int yy) { x = xx, y = yy; if (xx <= w && yy <= h) { if (map[xx][yy] == 1) { root(xx + 1, yy); } else { root(xx, yy + 1); } } } int main(void) { int a, b, c; while (1) { memset(map, 0, sizeof(map)); memset(dp, 0, sizeof(dp)); scanf("%d%d%d", &h, &w, &n); if (h == 0 && w == 0 && n == 0) break; for (a = 1; a <= h; a++) { for (b = 1; b <= w; b++) { scanf("%d", &map[b][a]); } } dp[1][1] = n - 1; for (a = 1; a <= h; a++) { for (b = 1; b <= w; b++) { if (dp[b][a] % 2 == 0) dp[b + 1][a] += dp[b][a] / 2; else { if (map[b][a] == 1) dp[b + 1][a] += (dp[b][a] + 1) / 2; if (map[b][a] == 0) dp[b + 1][a] += (dp[b][a] - 1) / 2; } if (dp[b][a] % 2 == 0) dp[b][a + 1] += dp[b][a] / 2; else { if (map[b][a] == 1) dp[b][a + 1] += (dp[b][a] - 1) / 2; if (map[b][a] == 0) dp[b][a + 1] += (dp[b][a] + 1) / 2; } } } for (a = 1; a <= h; a++) { for (b = 1; b <= w; b++) { map[b][a] = (map[b][a] + dp[b][a]) % 2; } } root(1, 1); cout << y << " " << x << endl; } return 0; }
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 17, 107], ["-", 0, 9, 0, 57, 64, 1, 0, 11, 17, 32], ["+", 0, 9, 0, 57, 64, 1, 0, 11, 17, 107]]
1
572
#include <stdio.h> int h, w, n; bool d[1000][1000]; int t[1000][1000]; int i, j; int main() { while (1) { scanf("%d %d %d", &h, &w, &n); if (h == 0) return 0; for (i = 0; i < h; i++) for (j = 0; j < w; j++) { int x; scanf("%d", &x); if (x == 1) d[i][j] = true; if (x == 0) d[i][j] = false; t[i][j] = 0; } t[0][0] = n - 1; for (i = 0; i < h; i++) for (j = 0; j < w; j++) { if (t[i][j] % 2 == 0) { if (i + 1 < h) t[i + 1][j] += t[i][j] / 2; if (j + 1 < w) t[i][j + 1] += t[i][j] / 2; } else { if (d[i][j]) { if (i + 1 < h) t[i + 1][j] += t[i][j] / 2; if (j + 1 < w) t[i][j + 1] += t[i][j] / 2 + 1; } else { if (i + 1 < h) t[i + 1][j] += t[i][j] / 2 + 1; if (j + 1 < w) t[i][j + 1] += t[i][j] / 2; } d[i][j] = !d[i][j]; } } int x, y; x = 0; y = 0; while (x != w && y != h) { if (d[y][x]) x++; else y++; } printf("%d %d\n", x + 1, y + 1); } }
#include <stdio.h> int h, w, n; bool d[1000][1000]; int t[1000][1000]; int i, j; int main() { while (1) { scanf("%d %d %d", &h, &w, &n); if (h == 0) return 0; for (i = 0; i < h; i++) for (j = 0; j < w; j++) { int x; scanf("%d", &x); if (x == 1) d[i][j] = true; if (x == 0) d[i][j] = false; t[i][j] = 0; } t[0][0] = n - 1; for (i = 0; i < h; i++) for (j = 0; j < w; j++) { if (t[i][j] % 2 == 0) { if (i + 1 < h) t[i + 1][j] += t[i][j] / 2; if (j + 1 < w) t[i][j + 1] += t[i][j] / 2; } else { if (d[i][j]) { if (i + 1 < h) t[i + 1][j] += t[i][j] / 2; if (j + 1 < w) t[i][j + 1] += t[i][j] / 2 + 1; } else { if (i + 1 < h) t[i + 1][j] += t[i][j] / 2 + 1; if (j + 1 < w) t[i][j + 1] += t[i][j] / 2; } d[i][j] = !d[i][j]; } } int x, y; x = 0; y = 0; while (x != w && y != h) { if (d[y][x]) x++; else y++; } printf("%d %d\n", y + 1, x + 1); } }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22]]
1
473
#include <cstdio> #include <cstring> int h, w, n; int maps[1001][1001]; int home[1001][1001]; int main(void) { scanf("%d%d%d", &h, &w, &n); while (h != 0) { memset(maps, 0, sizeof(maps)); memset(home, 0, sizeof(home)); int i, j; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { scanf("%d", &(maps[i][j])); } } home[0][0] = n - 1; int a; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (home[i][j] % 2 == 1) { a = (home[i][j] - 1) / 2; home[i + 1][j] = a; home[i][j + 1] = a; if (maps[i][j] == 1) { maps[i][j] = 0; home[i][j + 1]++; } else { maps[i][j] = 1; home[i + 1][j]++; } } else { a = home[i][j] / 2; home[i + 1][j] = a; home[i][j + 1] = a; } } } int ansi = 0, ansj = 0; while (ansi < h && ansj < w) { if (maps[ansi][ansj] == 1) { ansj++; } else { ansi++; } } printf("%d\x0020%d\n", ansi + 1, ansj + 1); scanf("%d%d%d", &h, &w, &n); } return 0; }
#include <cstdio> #include <cstring> int h, w, n; int maps[1001][1001]; int home[1001][1001]; int main(void) { scanf("%d%d%d", &h, &w, &n); while (h != 0) { memset(maps, 0, sizeof(maps)); memset(home, 0, sizeof(home)); int i, j; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { scanf("%d", &(maps[i][j])); } } home[0][0] = n - 1; int a; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (home[i][j] % 2 == 1) { a = (home[i][j] - 1) / 2; home[i + 1][j] += a; home[i][j + 1] += a; if (maps[i][j] == 1) { maps[i][j] = 0; home[i][j + 1]++; } else { maps[i][j] = 1; home[i + 1][j]++; } } else { a = home[i][j] / 2; home[i + 1][j] += a; home[i][j + 1] += a; } } } int ansi = 0, ansj = 0; while (ansi < h && ansj < w) { if (maps[ansi][ansj] == 1) { ansj++; } else { ansi++; } // printf("%d\x0020%d\n",ansi+1,ansj+1); } printf("%d\x0020%d\n", ansi + 1, ansj + 1); scanf("%d%d%d", &h, &w, &n); } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107], ["-", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 107]]
1
417
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; #define INF 1e+9 #define EPS 1e-9 #define rep(i, j) for (int i = 0; i < (j); i++) #define reps(i, j, k) for (int i = j; i < (k); i++) typedef long long ll; int stage[1024][1004]; int dp[1024][1024]; int main() { int h, w, n; while (scanf("%d%d%d", &h, &w, &n), (h | w) | n) { rep(i, h) rep(j, w) scanf("%d", &stage[i][j]); memset(dp, 0, sizeof(dp)); dp[0][0] = --n; rep(i, h) { rep(j, w) { if (dp[i][j] % 2 == 0) { dp[i][j + 1] = dp[i][j] / 2; dp[i + 1][j] = dp[i][j] / 2; } else { if (stage[i][j] == 0) { dp[i + 1][j] += dp[i][j] / 2 + 1; dp[i][j + 1] += dp[i][j] / 2; } else if (stage[i][j] == 1) { dp[i + 1][j] += dp[i][j] / 2; dp[i][j + 1] += dp[i][j] / 2 + 1; } } } } int x = 0, y = 0; while (x < w && y < h) { if (dp[y][x] % 2 == 1) { if (stage[y][x] == 0) { x++; } else { y++; } } else { if (stage[y][x] == 0) { y++; } else { x++; } } } printf("%d %d\n", ++y, ++x); } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; #define INF 1e+9 #define EPS 1e-9 #define rep(i, j) for (int i = 0; i < (j); i++) #define reps(i, j, k) for (int i = j; i < (k); i++) typedef long long ll; int stage[1024][1004]; int dp[1024][1024]; int main() { int h, w, n; while (scanf("%d%d%d", &h, &w, &n), (h | w) | n) { rep(i, h) rep(j, w) scanf("%d", &stage[i][j]); memset(dp, 0, sizeof(dp)); dp[0][0] = --n; rep(i, h) { rep(j, w) { if (dp[i][j] % 2 == 0) { dp[i][j + 1] += dp[i][j] / 2; dp[i + 1][j] += dp[i][j] / 2; } else { if (stage[i][j] == 0) { dp[i + 1][j] += dp[i][j] / 2 + 1; dp[i][j + 1] += dp[i][j] / 2; } else if (stage[i][j] == 1) { dp[i + 1][j] += dp[i][j] / 2; dp[i][j + 1] += dp[i][j] / 2 + 1; } } } } int x = 0, y = 0; while (x < w && y < h) { if (dp[y][x] % 2 == 1) { if (stage[y][x] == 0) { x++; } else { y++; } } else { if (stage[y][x] == 0) { y++; } else { x++; } } } printf("%d %d\n", ++y, ++x); } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107]]
1
498
while True: h, w, n = list(map(int, input().split())) if h == 0: break l = [list(map(int, input().split())) for i in range(h)] dp = [[0]*w for i in range(h)] dp[0][0] = n - 1 for i in range(h): for j in range(w): if i + 1 < h: dp[i+1][j] += (dp[i][j] + l[i][j] ^ 1) >> 1 if j + 1 < w: dp[i][j+1] += (dp[i][j] + l[i][j]) >> 1 dx = dy = 0 while dx < w and dy < h: if (dp[dy][dx] + l[dy][dx]) % 2 == 0: dy += 1 else: dx += 1 print(dy + 1, dx + 1)
while True: h, w, n = list(map(int, input().split())) if h == 0: break l = [list(map(int, input().split())) for i in range(h)] dp = [[0]*w for i in range(h)] dp[0][0] = n - 1 for i in range(h): for j in range(w): if i + 1 < h: dp[i+1][j] += (dp[i][j] + (l[i][j] ^ 1)) >> 1 if j + 1 < w: dp[i][j+1] += (dp[i][j] + l[i][j]) >> 1 dx = dy = 0 while dx < w and dy < h: if (dp[dy][dx] + l[dy][dx]) % 2 == 0: dy += 1 else: dx += 1 print(dy + 1, dx + 1)
[["+", 12, 657, 31, 23, 0, 657, 12, 23, 0, 24], ["+", 12, 657, 31, 23, 0, 657, 12, 23, 0, 25]]
5
228
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = m; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define rp(i, c) rep(i, (int)c.size()) #define fr(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define mp make_pair #define pb push_back #define all(c) (c).begin(), (c).end() #define rall(u) (u).rbegin(), (u).rend() #define dbg(x) cerr << #x << " = " << (x) << endl #define v_delete(a, b) (a).erase(remove((a).begin(), (a).end(), b), (a).end()) #define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end()) #define VV(T) vector<vector<T>> #define init(a, b) memset((a), (b), sizeof((a))) using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = 1 << 28; const double EPS = 1e-9; const long long INF = 100001000010000100ll; template <class T> int SIZE(T a) { return a.size(); } template <class T> string IntToString(T num) { string res; stringstream ss; ss << num; return ss.str(); } template <class T> T StringToInt(string str) { T res = 0; for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] - '0'); return res; } template <class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> void input(T &a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } template <class T> void input(T *a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } typedef pair<int, int> pii; int R; int W[2], H[2], X[2], Y[2]; int m[4][500 + 10][500 + 10]; int visited[2][500 + 10][500 + 10]; int wa[2][500 * 500 + 10]; vi ls; map<int, int> cnt[2]; bool exists(const map<int, int> &mapp, int key) { return mapp.find(key) != mapp.end(); } int dx[] = {1, 0, 0, -1}; int dy[] = {0, 1, -1, 0}; class BIT { private: vi bit; int n; public: BIT(int _n) { n = _n; bit.assign(n + 1, 0); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += (i & -i); } } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= (i & -i); } return s; } }; int main() { while (cin >> R) { memset(visited, 0, sizeof(visited)); memset(wa, 0, sizeof(wa)); ls.clear(); fill_n(**m, 4 * (500 + 10) * (500 + 10), inf); rep(c, 2) { cin >> W[c] >> H[c] >> X[c] >> Y[c]; rep(i, H[c]) { rep(j, W[c]) { cin >> m[c][i + 1][j + 1]; ls.pb(m[c][i + 1][j + 1]); } } } ls.pb(0); ls.pb(inf); sort(all(ls)); ls.erase(unique(all(ls)), ls.end()); rep(c, 2) { priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> Q; Q.push(mp(1, mp(X[c], Y[c]))); while (!Q.empty()) { int x, y, level; x = Q.top().second.first; y = Q.top().second.second; level = Q.top().first; Q.pop(); if (visited[c][y][x]) { continue; } visited[c][y][x] = 1; if (level > m[c][y][x]) { m[c][y][x] = level; } else { level = m[c][y][x]; } // printf("%d %d %d %d\n",c, x, y, level); rep(k, 4) { if (m[c][y + dy[k]][x + dx[k]] != inf) { if (!visited[c][y + dy[k]][x + dx[k]]) { Q.push(mp(max(m[c][y + dy[k]][x + dx[k]], level), mp(x + dx[k], y + dy[k]))); } } } } } /* rep(c, 2){ rep(i, H[c]){ rep(j, W[c]){ cout << m[c][i+1][j+1] << " "; } cout << endl; } cout << endl; cout << endl; cout << endl; }*/ rep(c, 2) { rep(i, H[c]) { rep(j, W[c]) { int ma = -1; int tmp = inf; /* rep(k, 4){ tmp=min(tmp, m[c][i + 1 + dx[k]][j + 1 + dy[k]]); } if(i + 1 == Y[c] && j + 1 == X[c]){ ma=m[c][i + 1][j + 1]; }else{ ma = max(m[c][i + 1][j + 1], tmp); }*/ ma = m[c][i + 1][j + 1]; int l = lower_bound(all(ls), ma) - ls.begin(); wa[c][l]++; } } rp(i, ls) { if (i - 1 >= 0) wa[c][i] = wa[c][i - 1] + wa[c][i]; } } /* rep(c, 2){ rp(i, ls){ cout << ls[i] << " " << wa[c][i] << endl; } cout << endl; cout << endl; }*/ int ans = inf; rp(i, ls) { int l = lower_bound(wa[1], (wa[1] + (int)ls.size()), R - wa[0][i]) - wa[1]; if (l < ls.size()) if (wa[0][i] + wa[1][l] >= R) { // cout << ls[i] << " " << ls[l] << endl; ans = min(ans, ls[i] + ls[l]); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = m; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define rp(i, c) rep(i, (int)c.size()) #define fr(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define mp make_pair #define pb push_back #define all(c) (c).begin(), (c).end() #define rall(u) (u).rbegin(), (u).rend() #define dbg(x) cerr << #x << " = " << (x) << endl #define v_delete(a, b) (a).erase(remove((a).begin(), (a).end(), b), (a).end()) #define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end()) #define VV(T) vector<vector<T>> #define init(a, b) memset((a), (b), sizeof((a))) using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = 1 << 28; const double EPS = 1e-9; const long long INF = 100001000010000100ll; template <class T> int SIZE(T a) { return a.size(); } template <class T> string IntToString(T num) { string res; stringstream ss; ss << num; return ss.str(); } template <class T> T StringToInt(string str) { T res = 0; for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] - '0'); return res; } template <class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> void input(T &a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } template <class T> void input(T *a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; } typedef pair<int, int> pii; int R; int W[2], H[2], X[2], Y[2]; int m[4][500 + 10][500 + 10]; int visited[2][500 + 10][500 + 10]; int wa[2][500 * 500 * 2 + 10]; vi ls; map<int, int> cnt[2]; bool exists(const map<int, int> &mapp, int key) { return mapp.find(key) != mapp.end(); } int dx[] = {1, 0, 0, -1}; int dy[] = {0, 1, -1, 0}; class BIT { private: vi bit; int n; public: BIT(int _n) { n = _n; bit.assign(n + 1, 0); } void add(int i, int x) { while (i <= n) { bit[i] += x; i += (i & -i); } } int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= (i & -i); } return s; } }; int main() { while (cin >> R, R) { memset(visited, 0, sizeof(visited)); memset(wa, 0, sizeof(wa)); ls.clear(); fill_n(**m, 4 * (500 + 10) * (500 + 10), inf); rep(c, 2) { cin >> W[c] >> H[c] >> X[c] >> Y[c]; rep(i, H[c]) { rep(j, W[c]) { cin >> m[c][i + 1][j + 1]; ls.pb(m[c][i + 1][j + 1]); } } } ls.pb(0); ls.pb(inf); sort(all(ls)); ls.erase(unique(all(ls)), ls.end()); rep(c, 2) { priority_queue<pair<int, pii>, vector<pair<int, pii>>, greater<pair<int, pii>>> Q; Q.push(mp(1, mp(X[c], Y[c]))); while (!Q.empty()) { int x, y, level; x = Q.top().second.first; y = Q.top().second.second; level = Q.top().first; Q.pop(); if (visited[c][y][x]) { continue; } visited[c][y][x] = 1; if (level > m[c][y][x]) { m[c][y][x] = level; } else { level = m[c][y][x]; } // printf("%d %d %d %d\n",c, x, y, level); rep(k, 4) { if (m[c][y + dy[k]][x + dx[k]] != inf) { if (!visited[c][y + dy[k]][x + dx[k]]) { Q.push(mp(max(m[c][y + dy[k]][x + dx[k]], level), mp(x + dx[k], y + dy[k]))); } } } } } /* rep(c, 2){ rep(i, H[c]){ rep(j, W[c]){ cout << m[c][i+1][j+1] << " "; } cout << endl; } cout << endl; cout << endl; cout << endl; }*/ rep(c, 2) { rep(i, H[c]) { rep(j, W[c]) { int ma = -1; int tmp = inf; /* rep(k, 4){ tmp=min(tmp, m[c][i + 1 + dx[k]][j + 1 + dy[k]]); } if(i + 1 == Y[c] && j + 1 == X[c]){ ma=m[c][i + 1][j + 1]; }else{ ma = max(m[c][i + 1][j + 1], tmp); }*/ ma = m[c][i + 1][j + 1]; int l = lower_bound(all(ls), ma) - ls.begin(); wa[c][l]++; } } rp(i, ls) { if (i - 1 >= 0) wa[c][i] = wa[c][i - 1] + wa[c][i]; } } /* rep(c, 2){ rp(i, ls){ cout << ls[i] << " " << wa[c][i] << endl; } cout << endl; cout << endl; }*/ int ans = inf; rp(i, ls) { int l = lower_bound(wa[1], (wa[1] + (int)ls.size()), R - wa[0][i]) - wa[1]; if (l < ls.size()) if (wa[0][i] + wa[1][l] >= R) { // cout << ls[i] << " " << ls[l] << endl; ans = min(ans, ls[i] + ls[l]); } } cout << ans << endl; } return 0; }
[["+", 0, 43, 49, 80, 81, 16, 31, 16, 17, 48], ["+", 0, 43, 49, 80, 81, 16, 31, 16, 12, 13], ["+", 0, 52, 15, 339, 51, 34, 31, 16, 12, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21]]
1
1,441
#include <bits/stdc++.h> #define FOR(i, n) for (int i = 0; i < (int)(n); i++) #define FORR(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define pb push_back #define mp make_pair #define ALL(a) a.begin(), a.end() #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, -1, sizeof(a)) #define len(a) sizeof(a) #define ll long long #define pint pair<int, int> #define INF 1 << 29 #define MAX 501 using namespace std; int R, W[2], H[2], X[2], Y[2], L[2][MAX][MAX], d[2][MAX][MAX], dd[4] = {0, -1, 0, 1}; map<int, int> m[2]; map<int, int>::iterator ite; vector<int> lev[2], sum[2]; void solve() { for (;;) { cin >> R; if (!R) return; FOR(i, 2) { cin >> W[i] >> H[i] >> X[i] >> Y[i]; X[i]--; Y[i]--; FOR(j, H[i]) FOR(k, W[i]) cin >> L[i][j][k]; FOR(j, H[i]) FOR(k, W[i]) d[i][j][k] = INT_MAX / 3; d[i][X[i]][Y[i]] = 1; priority_queue<pint, vector<pint>, greater<pint>> pque; pque.push(mp(1, X[i] * W[i] + Y[i])); while (!pque.empty()) { pint p = pque.top(); pque.pop(); int x = p.second / W[i], y = p.second % W[i]; if (d[i][x][y] < p.first) continue; FOR(j, 4) { int nx = x + dd[j], ny = y + dd[j ^ 1]; if (nx < 0 || ny < 0 || nx >= H[i] || ny >= W[i]) continue; if (d[i][nx][ny] > max(d[i][x][y], L[i][nx][ny])) { d[i][nx][ny] = max(d[i][x][y], L[i][nx][ny]); pque.push(mp(d[i][nx][ny], nx * W[i] + ny)); } } } FOR(j, H[i]) FOR(k, W[i]) m[i][d[i][j][k]]++; int tot = 0; lev[i].pb(0); sum[i].pb(0); for (ite = m[i].begin(); ite != m[i].end(); ite++) { lev[i].pb(ite->first); tot += ite->second; sum[i].pb(tot); } } sum[1].pb(INT_MAX); int mi = 1 << 30; FOR(i, lev[0].size()) { int ind = lower_bound(ALL(sum[1]), R - sum[0][i]) - sum[1].begin(); if (sum[1][ind] == INT_MAX) continue; mi = min(mi, lev[1][ind] + lev[0][i]); } cout << mi << endl; FOR(i, 2) { m[i].clear(); lev[i].clear(); sum[i].clear(); } } } int main() { solve(); return 0; }
#include <bits/stdc++.h> #define FOR(i, n) for (int i = 0; i < (int)(n); i++) #define FORR(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define pb push_back #define mp make_pair #define ALL(a) a.begin(), a.end() #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, -1, sizeof(a)) #define len(a) sizeof(a) #define ll long long #define pint pair<int, int> #define INF 1 << 29 #define MAX 501 using namespace std; int R, W[2], H[2], X[2], Y[2], L[2][MAX][MAX], d[2][MAX][MAX], dd[4] = {0, -1, 0, 1}; map<int, int> m[2]; map<int, int>::iterator ite; vector<int> lev[2], sum[2]; void solve() { for (;;) { cin >> R; if (!R) return; FOR(i, 2) { cin >> W[i] >> H[i] >> X[i] >> Y[i]; X[i]--; Y[i]--; FOR(j, H[i]) FOR(k, W[i]) cin >> L[i][j][k]; FOR(j, H[i]) FOR(k, W[i]) d[i][j][k] = INT_MAX / 3; d[i][Y[i]][X[i]] = 1; priority_queue<pint, vector<pint>, greater<pint>> pque; pque.push(mp(1, Y[i] * W[i] + X[i])); while (!pque.empty()) { pint p = pque.top(); pque.pop(); int x = p.second / W[i], y = p.second % W[i]; if (d[i][x][y] < p.first) continue; FOR(j, 4) { int nx = x + dd[j], ny = y + dd[j ^ 1]; if (nx < 0 || ny < 0 || nx >= H[i] || ny >= W[i]) continue; if (d[i][nx][ny] > max(d[i][x][y], L[i][nx][ny])) { d[i][nx][ny] = max(d[i][x][y], L[i][nx][ny]); pque.push(mp(d[i][nx][ny], nx * W[i] + ny)); } } } FOR(j, H[i]) FOR(k, W[i]) m[i][d[i][j][k]]++; int tot = 0; lev[i].pb(0); sum[i].pb(0); for (ite = m[i].begin(); ite != m[i].end(); ite++) { lev[i].pb(ite->first); tot += ite->second; sum[i].pb(tot); } } sum[1].pb(INT_MAX); int mi = 1 << 30; FOR(i, lev[0].size()) { int ind = lower_bound(ALL(sum[1]), R - sum[0][i]) - sum[1].begin(); if (sum[1][ind] == INT_MAX) continue; mi = min(mi, lev[1][ind] + lev[0][i]); } cout << mi << endl; FOR(i, 2) { m[i].clear(); lev[i].clear(); sum[i].clear(); } } } int main() { solve(); return 0; }
[["-", 31, 69, 28, 69, 341, 342, 0, 69, 28, 22], ["+", 31, 69, 28, 69, 341, 342, 0, 69, 28, 22], ["-", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22], ["+", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22], ["-", 3, 4, 0, 16, 31, 16, 31, 69, 28, 22], ["+", 3, 4, 0, 16, 31, 16, 31, 69, 28, 22], ["-", 0, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["+", 0, 2, 3, 4, 0, 16, 12, 69, 28, 22]]
1
860
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var Arr = (input.trim()).split("\n"); for (var I = 0; I < Arr.length; I++) { var Sum = Arr[I] - 0; if (Sum == 0) break; var sum = 0; for (var i = 0; i < 10; i++) sum += (Arr[I + i] - 0); console.log(Sum - sum); I += 10; }
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var Arr = (input.trim()).split("\n"); for (var I = 0; I < Arr.length; I++) { var Sum = Arr[I] - 0; if (Sum == 0) break; var sum = 0; for (var i = 0; i < 9; i++) sum += (Arr[I + i + 1] - 0); console.log(Sum - sum); I += 9; }
[["-", 8, 556, 0, 7, 15, 1, 0, 16, 12, 555], ["+", 8, 556, 0, 7, 15, 1, 0, 16, 12, 555], ["+", 12, 23, 0, 16, 31, 69, 71, 16, 17, 72], ["+", 12, 23, 0, 16, 31, 69, 71, 16, 12, 555], ["-", 0, 7, 8, 556, 0, 1, 0, 564, 12, 555], ["+", 0, 7, 8, 556, 0, 1, 0, 564, 12, 555]]
2
120
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define INF 1.1e9 #define LINF 1.1e18 #define FOR(i, a, b) for (long long i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define fi first #define se second typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; int n, m; int mas[1000], x[1000]; int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { cin >> n >> m; if (n == 0 && m == 0) break; REP(i, 1000) mas[i] = x[i] = 0; REP(i, n) { cin >> mas[i]; } int pos = 0; REP(i, m) { cin >> x[i]; } REP(i, m) { pos += x[i] + mas[pos + x[i]]; if (pos >= n - 1) { cout << i + 1 << endl; return 0; } } } return 0; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define INF 1.1e9 #define LINF 1.1e18 #define FOR(i, a, b) for (long long i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define fi first #define se second typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; int n, m; int mas[1000], x[1000]; int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { cin >> n >> m; if (n == 0 && m == 0) break; REP(i, 1000) mas[i] = x[i] = 0; REP(i, n) { cin >> mas[i]; } int pos = 0; REP(i, m) { cin >> x[i]; } REP(i, m) { pos += x[i] + mas[pos + x[i]]; if (pos >= n - 1) { cout << i + 1 << endl; break; } } } return 0; }
[["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94]]
1
232
#include <iostream> using namespace std; int main() { int a, i, n, m, p[3000] = {0}; for (;;) { cin >> n >> m; if (n == 0 && m == 0) break; int w = 0, s = 0; for (i = 0; i < n; i++) cin >> p[i]; for (i = 0; i < m; i++) { cin >> a; w += a; if (p[w] != 0 && s == 0) w += p[w]; if (w >= n - 1 && s == 0) s = i + 1; } cout << s; } }
#include <iostream> using namespace std; int main() { int a, i, n, m, p[3000] = {0}; for (;;) { cin >> n >> m; if (n == 0 && m == 0) break; int w = 0, s = 0; for (i = 0; i < n; i++) cin >> p[i]; for (i = 0; i < m; i++) { cin >> a; w += a; if (p[w] != 0 && s == 0) w += p[w]; if (w >= n - 1 && s == 0) s = i + 1; } cout << s << endl; } }
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
149
#include <stdio.h> int main() { int n[1006] = {0}, m[1006] = {0}; int k = 0, i, N, M; for (;;) { scanf("%d%d", &N, &M); if (M == 0 && M == 0) break; for (i = 0; i < N; i++) { scanf("%d", &n[i]); } for (i = 0; i < M; i++) { scanf("%d", &m[i]); } for (i = 0;; i++) { k += m[i]; k += n[k]; if (k >= N - 1) break; } printf("%d\n", i + 1); } return 0; }
#include <stdio.h> int main() { int n[1006] = {0}, m[1006] = {0}; int k = 0, i, N, M; for (;; k = 0) { scanf("%d%d", &N, &M); if (M == 0 && M == 0) break; for (i = 0; i < N; i++) { scanf("%d", &n[i]); } for (i = 0; i < M; i++) { scanf("%d", &m[i]); } for (i = 0;; i++) { k += m[i]; k += n[k]; if (k >= N - 1) break; } printf("%d\n", i + 1); } return 0; }
[["+", 0, 14, 8, 9, 0, 7, 26, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 12, 13]]
1
177
#include <iostream> #include <vector> using namespace std; int main() { while (true) { int N, M; cin >> N >> M; if (!N && !M) break; vector<int> v(N); int pos = 0; for (int i = 0; i < N; ++i) { cin >> v[i]; } vector<int> m(M); for (int i = 0; i < M; ++i) { cin >> m[i]; } for (int i = 0; i < M; ++i) { pos += m[i]; if (pos >= N) { cout << (i + 1) << endl; break; } pos += v[pos]; if (pos >= N) { cout << (i + 1) << endl; break; } } } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { while (true) { int N, M; cin >> N >> M; if (!N && !M) break; vector<int> v(N); int pos = 0; for (int i = 0; i < N; ++i) { cin >> v[i]; } vector<int> m(M); for (int i = 0; i < M; ++i) { cin >> m[i]; } for (int i = 0; i < M; ++i) { pos += m[i]; if (pos >= N - 1) { cout << (i + 1) << endl; break; } pos += v[pos]; if (pos >= N - 1) { cout << (i + 1) << endl; break; } } } return 0; }
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
183
#include <cstdio> int main() { int n, m, a, p, i, x; for (; scanf("%d%d", &n, &m), n | m; printf("%d\n", a)) { int a[2001] = {}, b[2001] = {}; for (x = p = i = 0; i < n; ++i) scanf("%d", a + i); for (i = 0; i < m; ++i) scanf("%d", b + i); for (; p < n - 1; p += a[p]) p += b[x++]; } }
#include <cstdio> int main() { int n, m, a, p, i, x; for (; scanf("%d%d", &n, &m), n | m; printf("%d\n", x)) { int a[2001] = {}, b[2001] = {}; for (x = p = i = 0; i < n; ++i) scanf("%d", a + i); for (i = 0; i < m; ++i) scanf("%d", b + i); for (; p < n - 1; p += a[p]) p += b[x++]; } }
[["-", 8, 9, 0, 7, 26, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 7, 26, 2, 3, 4, 0, 22]]
1
146
#include <iostream> using namespace std; int field[1000]; int main() { int n, m; while (cin >> n >> m) { if (!n && !m) break; for (int i = 0; i < n; i++) { cin >> field[i]; } int count = 1000000000; int pos = 0; int cnt = 0; for (int i = 0; i < m; i++) { cnt++; int a; cin >> a; pos += a; if (pos < n) pos = pos + field[pos]; if (pos >= n && count > cnt) count = cnt; } cout << count << endl; } return 0; }
#include <iostream> using namespace std; int field[1000]; int main() { int n, m; while (cin >> n >> m) { if (!n && !m) break; for (int i = 0; i < n; i++) { cin >> field[i]; } int count = 1000000000; int pos = 0; int cnt = 0; for (int i = 0; i < m; i++) { cnt++; int a; cin >> a; pos += a; if (pos < n) pos = pos + field[pos]; if (pos >= n - 1 && count > cnt) count = cnt; } cout << count << endl; } return 0; }
[["+", 15, 339, 51, 16, 31, 16, 12, 16, 17, 33], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13]]
1
149
#include <iostream> using namespace std; #define MAX 1000 int main() { int n, m; int ms[MAX + 1]; while (true) { cin >> n >> m; if (!n && !m) break; for (int i = 0; i < n; i++) cin >> ms[i]; int go, t = 0, cnt = 0; bool flg = false; for (int i = 0; i < m; i++) { cin >> go; if (!flg) { t += go; t += ms[t]; cnt++; if (t >= 9) flg = true; } } cout << cnt << endl; } return 0; }
#include <iostream> using namespace std; #define MAX 2000 int main() { int n, m; int ms[MAX + 1]; while (true) { cin >> n >> m; if (!n && !m) break; for (int i = 0; i < n; i++) cin >> ms[i]; int go, t = 0, cnt = 0; bool flg = false; for (int i = 0; i < m; i++) { cin >> go; if (!flg) { t += go; t += ms[t]; cnt++; if (t >= n - 1) flg = true; } } cout << cnt << endl; } return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
147
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // common typedef int i32; typedef long long i64, ll; typedef long double ld; #define BR "\n" #define ALL(c) (c).begin(), (c).end() #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, l, r) for (int i = (int)l; i < (int)(r); ++i) #define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it) #define IN(l, v, r) ((l) <= (v) && (v) < (r)) // config //#define NDEBUG //#define INF 1<<30 //#define EPS 1e-8 // const ll MOD =100000007; // debug #ifdef NDEBUG #define DUMP(x) #define DUMPLN(x) #define DEBUG(x) #define DEBUGLN(x) #define LINE() #define LINELN() #define CHECK(exp, act) #define STOP(e) #else #define DUMP(x) cerr << #x << " = " << (x) #define DUMPLN(x) DUMP(x) << endl #define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__ #define DEBUGLN(x) DEBUG(x) << endl #define LINE() cerr << " (L" << __LINE__ << ")" #define LINELN() LINE() << endl #define CHECK(exp, act) \ if (exp != act) { \ DUMPLN(exp); \ DEBUGLN(act); \ } #define STOP(e) \ CHECK(e, true); \ if (!(e)) \ exit(1); #endif template <class T> inline string toString(const vector<T> &x) { stringstream ss; REP(i, x.size()) { if (i != 0) ss << " "; ss << x[i]; } return ss.str(); } template <class T> inline string toString(const vector<vector<T>> &map) { stringstream ss; REP(i, map.size()) { if (i != 0) ss << BR; ss << toString(map[i]); } return ss.str(); } template <class K, class V> string toString(map<K, V> &x) { string res; stringstream ss; for (auto &p : x) ss << p.first << ":" << p.second << " "; return ss.str(); } string BITtoString(int bit) { stringstream ss; while (bit != 0) { ss << (bit % 2); bit /= 2; } string res = ss.str(); reverse(ALL(res)); return res; } template <typename T, typename V> inline T pmod(T v, V MOD) { return (v % MOD + MOD) % MOD; } #define nextInt(n) scanf("%d", &n) #define defInt(n) \ int n; \ nextInt(n) #define nextLong(n) scanf("%lld", &n) #define defLong(n) \ ll n; \ nextLong(n) #define nextDouble(n) scanf("%lf", &n) struct UnionFind { vector<int> par; // 親 vector<int> rank; // 木の深さ vector<int> ss; // xの属する集合のサイズ:option int size; //集合の個数:option UnionFind(int n) { REP(i, n) par.push_back(i); rank = vector<int>(n); ss = vector<int>(n, 1); size = n; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; ss[y] += ss[x]; } else { par[y] = x; ss[x] += ss[y]; } if (rank[x] == rank[y]) rank[x]++; size--; } }; namespace SpanningTree { typedef double Cost; struct Edge { int from, to; Cost cost; Edge(int from, int to, Cost cost) : from(from), to(to), cost(cost){}; bool operator<(Edge r) const { return cost < r.cost; } bool operator>(Edge r) const { return cost > r.cost; } }; typedef vector<vector<Edge>> Graph; // O(E*log(V)) // verified by ACAC002 B // http://judge.u-aizu.ac.jp/onlinejudge/creview.jsp?rid=899132&cid=ACAC002 Cost kruskal(Graph g) { const int V = g.size(); UnionFind uf = UnionFind(V); priority_queue<Edge, vector<Edge>, greater<Edge>> que; REP(u, V) for (Edge e : g[u]) que.push(e); Cost res = 0; while (!que.empty()) { Edge e = que.top(); que.pop(); if (!uf.same(e.from, e.to)) { uf.unite(e.from, e.to); res += e.cost; } } return res; } } // namespace SpanningTree using namespace SpanningTree; class Main { public: void run() { // ifstream cin("in"); // ofstream cout( "out" ); while (true) { int N, M; nextInt(N); nextInt(M); if (N == 0 && M == 0) break; vector<ll> as(N); REP(i, N) nextInt(as[i]); vector<ll> bs(M); REP(i, M) nextInt(bs[i]); int pos = 0; REP(j, M) { pos += bs[j]; if (pos >= N - 1) { cout << (j + 1) << endl; break; } pos += bs[pos]; if (pos >= N - 1) { cout << (j + 1) << endl; break; } } } } }; int main() { cout << fixed << setprecision(13); ios::sync_with_stdio(false); Main().run(); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // common typedef int i32; typedef long long i64, ll; typedef long double ld; #define BR "\n" #define ALL(c) (c).begin(), (c).end() #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, l, r) for (int i = (int)l; i < (int)(r); ++i) #define EACH(it, o) for (auto it = (o).begin(); it != (o).end(); ++it) #define IN(l, v, r) ((l) <= (v) && (v) < (r)) // config //#define NDEBUG //#define INF 1<<30 //#define EPS 1e-8 // const ll MOD =100000007; // debug #ifdef NDEBUG #define DUMP(x) #define DUMPLN(x) #define DEBUG(x) #define DEBUGLN(x) #define LINE() #define LINELN() #define CHECK(exp, act) #define STOP(e) #else #define DUMP(x) cerr << #x << " = " << (x) #define DUMPLN(x) DUMP(x) << endl #define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__ #define DEBUGLN(x) DEBUG(x) << endl #define LINE() cerr << " (L" << __LINE__ << ")" #define LINELN() LINE() << endl #define CHECK(exp, act) \ if (exp != act) { \ DUMPLN(exp); \ DEBUGLN(act); \ } #define STOP(e) \ CHECK(e, true); \ if (!(e)) \ exit(1); #endif template <class T> inline string toString(const vector<T> &x) { stringstream ss; REP(i, x.size()) { if (i != 0) ss << " "; ss << x[i]; } return ss.str(); } template <class T> inline string toString(const vector<vector<T>> &map) { stringstream ss; REP(i, map.size()) { if (i != 0) ss << BR; ss << toString(map[i]); } return ss.str(); } template <class K, class V> string toString(map<K, V> &x) { string res; stringstream ss; for (auto &p : x) ss << p.first << ":" << p.second << " "; return ss.str(); } string BITtoString(int bit) { stringstream ss; while (bit != 0) { ss << (bit % 2); bit /= 2; } string res = ss.str(); reverse(ALL(res)); return res; } template <typename T, typename V> inline T pmod(T v, V MOD) { return (v % MOD + MOD) % MOD; } #define nextInt(n) scanf("%d", &n) #define defInt(n) \ int n; \ nextInt(n) #define nextLong(n) scanf("%lld", &n) #define defLong(n) \ ll n; \ nextLong(n) #define nextDouble(n) scanf("%lf", &n) struct UnionFind { vector<int> par; // 親 vector<int> rank; // 木の深さ vector<int> ss; // xの属する集合のサイズ:option int size; //集合の個数:option UnionFind(int n) { REP(i, n) par.push_back(i); rank = vector<int>(n); ss = vector<int>(n, 1); size = n; } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (rank[x] < rank[y]) { par[x] = y; ss[y] += ss[x]; } else { par[y] = x; ss[x] += ss[y]; } if (rank[x] == rank[y]) rank[x]++; size--; } }; namespace SpanningTree { typedef double Cost; struct Edge { int from, to; Cost cost; Edge(int from, int to, Cost cost) : from(from), to(to), cost(cost){}; bool operator<(Edge r) const { return cost < r.cost; } bool operator>(Edge r) const { return cost > r.cost; } }; typedef vector<vector<Edge>> Graph; // O(E*log(V)) // verified by ACAC002 B // http://judge.u-aizu.ac.jp/onlinejudge/creview.jsp?rid=899132&cid=ACAC002 Cost kruskal(Graph g) { const int V = g.size(); UnionFind uf = UnionFind(V); priority_queue<Edge, vector<Edge>, greater<Edge>> que; REP(u, V) for (Edge e : g[u]) que.push(e); Cost res = 0; while (!que.empty()) { Edge e = que.top(); que.pop(); if (!uf.same(e.from, e.to)) { uf.unite(e.from, e.to); res += e.cost; } } return res; } } // namespace SpanningTree using namespace SpanningTree; class Main { public: void run() { // ifstream cin("in"); // ofstream cout( "out" ); while (true) { int N, M; nextInt(N); nextInt(M); if (N == 0 && M == 0) break; vector<int> as(N); REP(i, N) nextInt(as[i]); vector<int> bs(M); REP(i, M) nextInt(bs[i]); int pos = 0; REP(j, M) { pos += bs[j]; if (pos >= N - 1) { cout << (j + 1) << endl; break; } pos += as[pos]; if (pos >= N - 1) { cout << (j + 1) << endl; break; } } } } }; int main() { cout << fixed << setprecision(13); ios::sync_with_stdio(false); Main().run(); return 0; }
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["-", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22]]
1
1,181
#include <iostream> using namespace std; int main() { int n, m; int fi[1001]; int dice[1001]; int s; int cnt = 1; while (1) { cin >> n >> m; if (n == 0 && m == 0) break; for (int i = 1; i <= n; i++) { cin >> fi[i]; } for (int i = 1; i <= m; i++) { cin >> dice[i]; } s = 1; while (1) { s += dice[cnt]; if (s >= n) { cout << cnt << endl; break; } s += fi[s]; if (s >= n) { cout << cnt << endl; break; } cnt++; } } return 0; }
#include <iostream> using namespace std; int main() { int n, m; int fi[1001]; int dice[1001]; int s; int cnt = 1; while (1) { cin >> n >> m; if (n == 0 && m == 0) break; for (int i = 1; i <= n; i++) { cin >> fi[i]; } for (int i = 1; i <= m; i++) { cin >> dice[i]; } s = 1; cnt = 1; while (1) { s += dice[cnt]; if (s >= n) { cout << cnt << endl; break; } s += fi[s]; if (s >= n) { cout << cnt << endl; break; } cnt++; } } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
169
for e in iter(input,'0 0'): N,M=map(int,e.split()) k,p=1,0 S=[int(input()) for _ in[0]*N] for d in[int(input())for _ in[0]*M]: p+=d if N<p+d else d+S[p+d] if N<=p+1:break k+=1 print(k)
for e in iter(input,'0 0'): N,M=map(int,e.split()) k,p=1,0 S=[int(input()) for _ in[0]*N] for d in[int(input())for _ in[0]*M]: p+=d if N<=p+d else d+S[p+d] if N<=p+1:break k+=1 print(k)
[["-", 0, 1, 0, 677, 12, 41, 0, 666, 667, 18], ["+", 0, 1, 0, 677, 12, 41, 0, 666, 667, 19]]
5
104
import sys r=sys.stdin.readline for e in iter(r,'0 0\n'): N,M=map(int,e.split()) k,p=1,0 S=[int(r()) for _ in[0]*N] for d in[int(r())for _ in[0]*M]: p+=d; if N<=p:p+=S[p] if N<=p+1:break k+=1 print(k)
import sys r=sys.stdin.readline for e in iter(r,'0 0\n'): N,M=map(int,e.split()) k,p=1,0 S=[int(r()) for _ in[0]*N] for d in[int(r())for _ in[0]*M]: p+=d; if p<N:p+=S[p] if N<=p+1:break k+=1 print(k)
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22]]
5
111
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n; while ((n = in.nextInt()) > 0) { boolean[][] map = new boolean[n][n]; int m = in.nextInt(); for (int i = 0; i < m; i++) { int a = in.nextInt() - 1; int b = in.nextInt() - 1; map[a][b] = true; map[b][a] = true; } for (int i = 1; i < n; i++) { if (map[i][0]) { for (int j = i; j < n; j++) { if (map[i][j]) { map[0][j] = true; } } } } int count = 0; for (int i = 1; i < n; i++) { if (map[0][i]) { count++; } } System.out.println(count); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n; while ((n = in.nextInt()) > 0) { boolean[][] map = new boolean[n][n]; int m = in.nextInt(); for (int i = 0; i < m; i++) { int a = in.nextInt() - 1; int b = in.nextInt() - 1; map[a][b] = true; map[b][a] = true; } for (int i = 1; i < n; i++) { if (map[i][0]) { for (int j = 1; j < n; j++) { if (map[i][j]) { map[0][j] = true; } } } } int count = 0; for (int i = 1; i < n; i++) { if (map[0][i]) { count++; } } System.out.println(count); } } }
[["-", 64, 196, 0, 7, 502, 503, 49, 200, 51, 22], ["+", 64, 196, 0, 7, 502, 503, 49, 200, 51, 499]]
3
248
#include <stdio.h> #include <string.h> char kan[501][501], gou[501]; int main(void) { int n, m, i, j, sas, a, b; while (1) { scanf("%d%d", &n, &m); if (!n && !m) break; memset(kan, 0, sizeof(kan)); memset(gou, 0, sizeof(gou)); for (i = 0; i < m; i++) { scanf("%d%d", &a, &b); kan[a][b] = kan[b][a] = 1; } for (i = 2; i <= n; i++) { if (kan[1][i] == 1) { gou[i] = 1; for (j = 1; j <= n; j++) { if (kan[i][j] == 1) gou[j] = 1; } } } sas = 0; for (i = 0; i < n; i++) { if (gou[i] == 1) sas++; } printf("%d\n", sas); } return 0; }
#include <stdio.h> #include <string.h> char kan[501][501], gou[501]; int main(void) { int n, m, i, j, sas, a, b; while (1) { scanf("%d%d", &n, &m); if (!n && !m) break; memset(kan, 0, sizeof(kan)); memset(gou, 0, sizeof(gou)); for (i = 0; i < m; i++) { scanf("%d%d", &a, &b); kan[a][b] = kan[b][a] = 1; } for (i = 2; i <= n; i++) { if (kan[1][i] == 1) { gou[i] = 1; for (j = 1; j <= n; j++) { if (kan[i][j] == 1) gou[j] = 1; } } } sas = 0; for (i = 2; i <= n; i++) { if (gou[i] == 1) sas++; } printf("%d\n", sas); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
253
#include <stdio.h> int main() { int data[501][501]; int n, m; int a, b; int i, j, count; int f[501]; while (1) { count = 0; for (i = 0; i < 501; i++) { for (j = 0; j < 501; j++) { data[i][j] = 0; f[j] = 0; } } scanf("%d %d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < m; i++) { scanf("%d %d", &a, &b); data[a][b] = 1; data[b][a] = 1; } for (i = 1; i <= n; i++) { if (data[1][i] == 1) { f[i] = 1; for (j = 2; j <= n; j++) { if (data[i][j] == 1 && data[1][j] != 1) f[j] = 1; } } } for (i = 2; i < n; i++) { count += f[i]; } printf("%d\n", count); } return 0; }
#include <stdio.h> int main() { int data[501][501]; int n, m; int a, b; int i, j, count; int f[501]; while (1) { count = 0; for (i = 0; i < 501; i++) { for (j = 0; j < 501; j++) { data[i][j] = 0; f[j] = 0; } } scanf("%d %d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < m; i++) { scanf("%d %d", &a, &b); data[a][b] = 1; data[b][a] = 1; } for (i = 1; i <= n; i++) { if (data[1][i] == 1) { f[i] = 1; for (j = 2; j <= n; j++) { if (data[i][j] == 1 && data[1][j] != 1) f[j] = 1; } } } /*for(i = 1; i <= n; i++) { f[i] += data[1][i]; if(f[i] >= 1) { for(j = 2; j <= n; j++) { f[j] += data[i][j]; } } }*/ for (i = 2; i <= n; i++) { count += f[i]; } printf("%d\n", count); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
285
#include <stdio.h> #include <string.h> int friend[502][502], ans[502]; void dfs(int x, int y) { if (y < 0) return; int i; ans[x] = 1; for (i = 1; i < 501; i++) { if (friend[x][i]) { dfs(i, y - 1); } } } int main() { while (1) { int n, m, res = 0, i, j; scanf("%d%d", &n, &m); if (n == 0 && m == 0) return 0; memset(friend, 0, sizeof(friend)); memset(ans, 0, sizeof(ans)); for (i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); friend[a][b] = 1; friend[b][a] = 1; } dfs(1, 2); for (i = 2; i < m; i++) { res += ans[i]; } printf("%d\n", res); } }
#include <stdio.h> #include <string.h> int friend[502][502], ans[502]; void dfs(int x, int y) { if (y < 0) return; int i; ans[x] = 1; for (i = 1; i < 501; i++) { if (friend[x][i]) { dfs(i, y - 1); } } } int main() { while (1) { int n, m, res = 0, i, j; scanf("%d%d", &n, &m); if (n == 0 && m == 0) return 0; memset(friend, 0, sizeof(friend)); memset(ans, 0, sizeof(ans)); for (i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); friend[a][b] = 1; friend[b][a] = 1; } dfs(1, 2); for (i = 2; i <= n; i++) { res += ans[i]; } printf("%d\n", res); } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
0
250
#include <stdio.h> #include <string.h> int main(void) { int flag[500]; int list[2][10000]; int i, j; int n, m; int count; while (1) { scanf("%d %d", &n, &m); if (!n && !m) { break; } memset(flag, 0, sizeof(flag)); for (i = 0; i < m; i++) { scanf("%d %d", &list[0][i], &list[1][i]); if (list[0][i] == 1 || list[1][i] == 1) { flag[list[0][i]] = flag[list[1][i]] = 100000; } } for (i = 0; i < m; i++) { if (flag[list[0][i]] >= 100000 || flag[list[1][i]] >= 100000) { flag[list[0][i]]++; flag[list[1][i]]++; } } count = 0; for (i = 1; i <= n; i++) { if (flag[i]) { count++; } } printf("%d\n", count - 1); } return (0); }
#include <stdio.h> #include <string.h> int main(void) { int flag[501]; int list[2][10000]; int i, j; int n, m; int count; while (1) { scanf("%d %d", &n, &m); if (!n && !m) { break; } memset(flag, 0, sizeof(flag)); for (i = 0; i < m; i++) { scanf("%d %d", &list[0][i], &list[1][i]); if (list[0][i] == 1 || list[1][i] == 1) { flag[list[0][i]] = flag[list[1][i]] = 100000; } } for (i = 0; i < m; i++) { if (flag[list[0][i]] >= 100000 || flag[list[1][i]] >= 100000) { flag[list[0][i]]++; flag[list[1][i]]++; } } count = 0; for (i = 2; i <= n; i++) { if (flag[i]) { count++; } } printf("%d\n", count); } return (0); }
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 33], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
0
287
#include <stdio.h> #include <string.h> int main(void) { int b[512]; int friends[512][512]; int i, j; int n, m; int from, to; int ans; while (1) { memset(b, 0, sizeof(b)); memset(friends, 0, sizeof(friends)); scanf("%d %d", &n, &m); if (n == 0) break; for (i = 0; i < m; i++) { scanf("%d %d", &from, &to); friends[from][to] = 1; friends[to][from] = 1; } for (i = 2; i <= n; i++) { if (friends[1][i] == 1) { b[i] = 1; for (j = 2; j <= n; j++) { if (friends[i][j] == 1) b[j] = 1; } } } ans = 0; for (i = 0; i < n; i++) { ans += b[i]; } printf("%d\n", ans); } return (0); }
#include <stdio.h> #include <string.h> int main(void) { int b[512]; int friends[512][512]; int i, j; int n, m; int from, to; int ans; while (1) { memset(b, 0, sizeof(b)); memset(friends, 0, sizeof(friends)); scanf("%d %d", &n, &m); if (n == 0) break; for (i = 0; i < m; i++) { scanf("%d %d", &from, &to); friends[from][to] = 1; friends[to][from] = 1; } for (i = 1; i <= n; i++) { if (friends[1][i] == 1) { b[i] = 1; for (j = 1; j <= n; j++) { if (friends[i][j] == 1) { b[j] = 1; } } } } ans = 0; for (i = 2; i <= n; i++) { ans += b[i]; } printf("%d\n", ans); } return (0); }
[["-", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 57, 64, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
0
254
#include <stdio.h> int main() { int a[501][501], c[501], h = 0; int i, i2, n, m, x, y; while (1) { for (i = 0; i < 501; i++) { for (i2 = 0; i2 < 501; i2++) { a[i][i2] = 0; } c[i] = 0; } scanf("%d %d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < m; i++) { scanf("%d %d", &x, &y); a[x][y] = 1; a[y][x] = 1; } c[0] = 1; c[1] = 1; for (i = 1; i <= n; i++) { if (a[1][i] == 1) { if (c[i] == 0) { h++; } c[i] = 1; for (i2 = 1; i2 <= n; i2++) { if (a[i][i2] == 1 && c[i2] == 0) { c[i2] = 1; h++; } } } } printf("%d\n", h); } return 0; }
#include <stdio.h> int main() { int a[501][501], c[501], h = 0; int i, i2, n, m, x, y; while (1) { for (i = 0; i < 501; i++) { for (i2 = 0; i2 < 501; i2++) { a[i][i2] = 0; } c[i] = 0; } h = 0; scanf("%d %d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < m; i++) { scanf("%d %d", &x, &y); a[x][y] = 1; a[y][x] = 1; } c[0] = 1; c[1] = 1; for (i = 1; i <= n; i++) { if (a[1][i] == 1) { if (c[i] == 0) { h++; } c[i] = 1; for (i2 = 1; i2 <= n; i2++) { if (a[i][i2] == 1 && c[i2] == 0) { c[i2] = 1; h++; } } } } printf("%d\n", h); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
288
#include <stdio.h> int main() { int list[2][10000]; int friend[500]; int friendoffriend[500]; int n, m, x, y, i, j, count; while (1) { scanf("%d", &n); scanf("%d", &m); if (n == 0 && m == 0) return 0; for (i = 0; i < 500; i++) { friend[i] = 0; friendoffriend[i] = 0; } count = 0; for (i = 0; i < m; i++) { scanf("%d %d", &list[0][i], &list[1][i]); if (list[0][i] == 1) friend[list[1][i] - 1] = 1; if (list[1][i] == 1) friend[list[0][i] - 1] = 1; } for (i = 1; i < n; i++) { if (friend[i] > 0) { for (j = 0; j < m; j++) { if (list[0][j] == i + 1) friendoffriend[list[1][j] - 1] = 1; if (list[1][j] == i + 1) friendoffriend[list[0][j] - 1] = 1; } } } for (i = 1; i < m; i++) if (friend[i] > 0 || friendoffriend[i] > 0) { count++; } printf("%d\n", count); } }
#include <stdio.h> int main() { int list[2][10000]; int friend[500]; int friendoffriend[500]; int n, m, i, j, count; while (1) { scanf("%d", &n); scanf("%d", &m); if (n == 0 && m == 0) return 0; for (i = 0; i < 500; i++) { friend[i] = 0; friendoffriend[i] = 0; } count = 0; for (i = 0; i < m; i++) { scanf("%d %d", &list[0][i], &list[1][i]); if (list[0][i] == 1) friend[list[1][i] - 1] = 1; if (list[1][i] == 1) friend[list[0][i] - 1] = 1; } for (i = 1; i < n; i++) { if (friend[i] > 0) { for (j = 0; j < m; j++) { if (list[0][j] == i + 1) friendoffriend[list[1][j] - 1] = 1; if (list[1][j] == i + 1) friendoffriend[list[0][j] - 1] = 1; } } } for (i = 1; i < n; i++) if (friend[i] > 0 || friendoffriend[i] > 0) { count++; } printf("%d\n", count); } }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
0
353
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; int n, m; const int INF = 1 << 29; class edge { public: vector<int> E; }; vector<edge> seito; set<int> fris; int main(void) { while (cin >> n >> m && n && m) { fris.clear(); seito.resize(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; seito[a].E.push_back(b); seito[b].E.push_back(a); } fris.insert(0); for (int i = 0; i < seito[0].E.size(); i++) { fris.insert(seito[0].E[i]); for (int j = 0; j < seito[seito[0].E[i]].E.size(); j++) { fris.insert(seito[seito[0].E[i]].E[j]); } } cout << fris.size() - 1 << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> using namespace std; int n, m; const int INF = 1 << 29; class edge { public: vector<int> E; }; vector<edge> seito; set<int> fris; int main(void) { while (cin >> n >> m && n && m) { fris.clear(); seito.clear(); seito.resize(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; seito[a].E.push_back(b); seito[b].E.push_back(a); } fris.insert(0); for (int i = 0; i < seito[0].E.size(); i++) { fris.insert(seito[0].E[i]); for (int j = 0; j < seito[seito[0].E[i]].E.size(); j++) { fris.insert(seito[seito[0].E[i]].E[j]); } } cout << fris.size() - 1 << endl; } return 0; }
[["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 28, 22], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 17, 131]]
1
275
#include <cstdio> #include <cstring> using namespace std; int main() { int list[20000][2]; bool f[20000]; bool ff[20000]; int n, m; while (scanf("%d %d", &n, &m), n + m) { memset(f, 0, sizeof(f)); memset(ff, 0, sizeof(ff)); for (int i = 0; i < m; i++) { scanf("%d %d", &list[i][0], &list[i][1]); if (list[i][0] == 1) { f[list[i][1]] = true; } else if (list[i][1] == 1) { f[list[i][0]] = true; } } for (int i = 0; i < m; i++) { if (f[list[i][0]]) { ff[list[i][1]] = true; } else if (f[list[i][1]]) { ff[list[i][0]] = true; } } int cnt = 0; for (int i = 1; i <= n; i++) { if (ff[i]) { cnt++; } } printf("%d\n", cnt); } return 0; }
#include <cstdio> #include <cstring> using namespace std; int main() { int list[20000][2]; bool f[20000]; bool ff[20000]; int n, m; while (scanf("%d %d", &n, &m), n + m) { memset(f, 0, sizeof(f)); memset(ff, 0, sizeof(ff)); for (int i = 0; i < m; i++) { scanf("%d %d", &list[i][0], &list[i][1]); if (list[i][0] == 1) { f[list[i][1]] = true; } else if (list[i][1] == 1) { f[list[i][0]] = true; } } for (int i = 0; i < m; i++) { if (f[list[i][0]]) { ff[list[i][1]] = true; } else if (f[list[i][1]]) { ff[list[i][0]] = true; } } int cnt = 0; for (int i = 2; i <= n; i++) { if (ff[i] || f[i]) { cnt++; } } printf("%d\n", cnt); } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22]]
1
300
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int n, m; while (scanf("%d%d", &n, &m), n != 0 && m != 0) { bool fr[501][501] = {false}; bool mem[501] = {false}; for (int i = 0; i < m; i++) { int m_a, m_b; scanf("%d%d", &m_a, &m_b); // friend check fr[m_a][m_b] = true; fr[m_b][m_a] = true; } for (int i = 2; i <= m; i++) { if (fr[1][i] == false) { continue; } mem[i] = true; for (int j = 2; j <= m; j++) { if (fr[i][j] == true) { mem[j] = true; } } } int cnt = 0; for (int i = 2; i <= m; i++) { if (mem[i] == true) { cnt++; } } cout << cnt << endl; } return (0); }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int n, m; while (scanf("%d%d", &n, &m), n != 0 && m != 0) { bool fr[501][501] = {false}; bool mem[501] = {false}; for (int i = 0; i < m; i++) { int m_a, m_b; scanf("%d%d", &m_a, &m_b); // friend check fr[m_a][m_b] = true; fr[m_b][m_a] = true; } for (int i = 2; i <= n; i++) { if (fr[1][i] == false) { continue; } mem[i] = true; for (int j = 2; j <= n; j++) { if (fr[i][j] == true) { mem[j] = true; } } } int cnt = 0; for (int i = 2; i <= n; i++) { if (mem[i] == true) { cnt++; } } cout << cnt << endl; } return (0); }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
246
#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; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual ///Studio 2015\Projects\programing_contest_c++\Debug\b.answer" int main() { while (1) { int N, M; cin >> N >> M; if (!N) break; vector<vector<int>> edges(N); for (int i = 0; i < N; ++i) { int a, b; cin >> a >> b; a--; b--; edges[a].push_back(b); edges[b].push_back(a); } vector<int> comes(N); for (auto e : edges[0]) { comes[e] = true; } vector<int> friends(N); for (int i = 1; i < N; ++i) { if (comes[i]) { friends[i] = true; for (auto e : edges[i]) friends[e] = true; } } int ans = count(friends.begin() + 1, friends.end(), 1); 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; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual ///Studio 2015\Projects\programing_contest_c++\Debug\b.answer" int main() { while (1) { int N, M; cin >> N >> M; if (!N) break; vector<vector<int>> edges(N); for (int i = 0; i < M; ++i) { int a, b; cin >> a >> b; a--; b--; edges[a].push_back(b); edges[b].push_back(a); } vector<int> comes(N); for (auto e : edges[0]) { comes[e] = true; } vector<int> friends(N); for (int i = 1; i < N; ++i) { if (comes[i]) { friends[i] = true; for (auto e : edges[i]) friends[e] = true; } } int ans = count(friends.begin() + 1, friends.end(), 1); cout << ans << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
1
257
#include <iostream> #include <vector> using namespace std; int main() { int n, m; while (cin >> n >> m, n, m) { int g[500][500] = {}; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a - 1][b - 1] = 1; g[b - 1][a - 1] = 1; } bool fri[500]; for (int i = 0; i < 500; i++) { fri[i] = false; if (g[0][i] == 1) fri[i] = true; } vector<int> v; for (int i = 0; i < n; i++) { for (int j = i; j < n; j++) { if (fri[i] == true && g[i][j] == 1) { v.push_back(j); } } } int a = v.size(); for (int i = 0; i < a; i++) { if (v[i] != 0) { fri[v[i]] = true; } } int ans = 0; for (int i = 0; i < 500; i++) { if (fri[i] == true) ans++; } cout << ans << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n, m; while (cin >> n >> m, n, m) { int g[500][500] = {}; for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; g[a - 1][b - 1] = 1; g[b - 1][a - 1] = 1; } bool fri[500]; for (int i = 0; i < 500; i++) { fri[i] = false; if (g[0][i] == 1) fri[i] = true; } vector<int> v; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (fri[i] == true && g[i][j] == 1) { v.push_back(j); } } } int a = v.size(); for (int i = 0; i < a; i++) { if (v[i] != 0) { fri[v[i]] = true; } } int ans = 0; for (int i = 0; i < 500; i++) { if (fri[i] == true) { ans++; } } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 22], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
302
#include <cstdio> constexpr int MAX_N = 500; constexpr int MAX_M = 10000; int N, M; int e[MAX_N][MAX_N]; bool flag[MAX_N] = {false}; int dfs(int n = 0, int depth = 0) { if (depth == 2) { if (flag[n]) { return 0; } else { flag[n] = true; return 1; } } int res = 0; if (!flag[n]) { ++res; flag[n] = true; } for (int i = 0; i < N; ++i) { if (e[n][i]) { res += dfs(i, depth + 1); } } return res; } int main() { while (true) { scanf("%d%d", &N, &M); if (N == 0 && M == 0) { break; } for (int i = 0; i < N; ++i) { flag[i] = false; for (int j = 0; j < M; ++j) { e[i][j] = false; } } flag[0] = true; for (int i = 0; i < M; ++i) { int a, b; scanf("%d%d", &a, &b); --a, --b; e[a][b] = e[b][a] = true; } printf("%d\n", dfs()); } return 0; }
#include <cstdio> constexpr int MAX_N = 500; constexpr int MAX_M = 10000; int N, M; int e[MAX_N][MAX_N]; bool flag[MAX_N] = {false}; int dfs(int n = 0, int depth = 0) { if (depth == 2) { if (flag[n]) { return 0; } else { flag[n] = true; return 1; } } int res = 0; if (!flag[n]) { ++res; flag[n] = true; } for (int i = 0; i < N; ++i) { if (e[n][i]) { res += dfs(i, depth + 1); } } return res; } int main() { while (true) { scanf("%d%d", &N, &M); if (N == 0 && M == 0) { break; } for (int i = 0; i < N; ++i) { flag[i] = false; for (int j = 0; j < N; ++j) { e[i][j] = false; } } flag[0] = true; for (int i = 0; i < M; ++i) { int a, b; scanf("%d%d", &a, &b); --a, --b; e[a][b] = e[b][a] = true; } printf("%d\n", dfs()); } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
321
#include <cstdio> #include <deque> #include <iostream> #include <map> using namespace std; long long d[100000]; long long h[100000]; long long s[100000]; int main() { long long N, H, mx; cin >> N >> H; mx = H; for (int i = 0; i < N - 1; i++) { cin >> d[i] >> h[i]; s[i + 1] = s[i] + d[i]; } int ans = 0; deque<int> Q; for (int i = 0; i < N - 1; i++) { // if( i > 10 ) return 0; // cout << "s" << i << " " << H << " " << ans << endl; while (Q.size() && h[Q.back()] <= h[i]) Q.pop_back(); Q.push_back(i); while (Q.size() && s[i] - s[Q.front()] > mx) Q.pop_front(); // for(int j = 0 ; j < Q.size() ; j++) cout << h[Q[j]] << " (" << Q[j] << // "," << mx - (s[i]-s[Q[j]]) << ") ";cout << endl; if (H < d[i]) { for (int j = 0; j < Q.size(); j++) { long long heal_max = max(0ll, mx - (s[i] - s[Q[j]]) - H); // cout << i << " " << Q[j] << " " << s[i] << " " << s[Q[j]] << " " << H // << " " << heal_max << endl; long long need = d[i] - H + 1; long long use = min(need, heal_max) / h[Q[j]]; // cout << Q[j] << " : " << need << " <========== " << " " << heal_max // << endl; if( use == 0 ) continue; H += use * h[Q[j]]; // H = min(H,mx - (s[i] - s[Q[j]])); ans += use; if (H > d[i]) break; if (j + 1 >= Q.size() || mx - (s[i] - s[Q[j]]) - H >= h[Q[j + 1]]) { // cout << H << " " << heal_max << endl; ans++; H = min(H + h[Q[j]], mx - (s[i] - s[Q[j]])); } if (H > d[i]) break; } } H -= d[i]; if (H <= 0) { cout << -1 << endl; return 0; } } cout << ans << endl; }
#include <cstdio> #include <deque> #include <iostream> #include <map> using namespace std; long long d[100000]; long long h[100000]; long long s[100000]; int main() { long long N, H, mx; cin >> N >> H; mx = H; for (int i = 0; i < N - 1; i++) { cin >> d[i] >> h[i]; s[i + 1] = s[i] + d[i]; } int ans = 0; deque<int> Q; for (int i = 0; i < N - 1; i++) { // if( i > 10 ) return 0; // cout << "s" << i << " " << H << " " << ans << endl; while (Q.size() && h[Q.back()] <= h[i]) Q.pop_back(); Q.push_back(i); while (Q.size() && s[i] - s[Q.front()] > mx) Q.pop_front(); // for(int j = 0 ; j < Q.size() ; j++) cout << h[Q[j]] << " (" << Q[j] << // "," << mx - (s[i]-s[Q[j]]) << ") ";cout << endl; if (H <= d[i]) { for (int j = 0; j < Q.size(); j++) { long long heal_max = max(0ll, mx - (s[i] - s[Q[j]]) - H); // cout << i << " " << Q[j] << " " << s[i] << " " << s[Q[j]] << " " << H // << " " << heal_max << endl; long long need = d[i] - H + 1; long long use = min(need, heal_max) / h[Q[j]]; // cout << Q[j] << " : " << need << " <========== " << " " << heal_max // << endl; if( use == 0 ) continue; H += use * h[Q[j]]; // H = min(H,mx - (s[i] - s[Q[j]])); ans += use; if (H > d[i]) break; if (j + 1 >= Q.size() || mx - (s[i] - s[Q[j]]) - H >= h[Q[j + 1]]) { // cout << H << " " << heal_max << endl; ans++; H = min(H + h[Q[j]], mx - (s[i] - s[Q[j]])); } if (H > d[i]) break; } } H -= d[i]; if (H <= 0) { cout << -1 << endl; return 0; } } cout << ans << endl; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
445
#include <algorithm> #include <cstdio> #include <deque> #include <utility> using namespace std; int main() { long long int n, total_h, max_h, total_d = 0, ans = 0; scanf("%lld %lld", &n, &total_h); max_h = total_h; deque<pair<long long int, long long int>> Q; for (int i = 0; i < n - 1; i++) { long long int d, h; scanf("%lld %lld", &d, &h); while (!Q.empty() && Q.front().first <= h) Q.pop_front(); Q.push_back(make_pair(h, total_d)); total_d += d; while (total_h <= total_d) { long long int tmp_h = total_h; while (!Q.empty() && tmp_h + Q.front().first - Q.front().second > max_h) { total_h = max(total_h, Q.front().second + max_h); Q.pop_front(); } if (!Q.empty()) { total_h = max(total_h, tmp_h + Q.front().first); long long int tmp = max( 0LL, min((total_d - total_h) / Q.front().first, (Q.front().second + max_h - total_h) / Q.front().first)); ans += tmp; total_h += tmp * Q.front().first; } ans++; } } printf("%lld\n", ans); }
#include <algorithm> #include <cstdio> #include <deque> #include <utility> using namespace std; int main() { long long int n, total_h, max_h, total_d = 0, ans = 0; scanf("%lld %lld", &n, &total_h); max_h = total_h; deque<pair<long long int, long long int>> Q; for (int i = 0; i < n - 1; i++) { long long int d, h; scanf("%lld %lld", &d, &h); while (!Q.empty() && Q.back().first <= h) Q.pop_back(); Q.push_back(make_pair(h, total_d)); total_d += d; while (total_h <= total_d) { long long int tmp_h = total_h; while (!Q.empty() && tmp_h + Q.front().first - Q.front().second > max_h) { total_h = max(total_h, Q.front().second + max_h); Q.pop_front(); } if (!Q.empty()) { total_h = max(total_h, tmp_h + Q.front().first); long long int tmp = max( 0LL, min((total_d - total_h) / Q.front().first, (Q.front().second + max_h - total_h) / Q.front().first)); ans += tmp; total_h += tmp * Q.front().first; } ans++; } } printf("%lld\n", ans); }
[["-", 12, 16, 31, 118, 28, 2, 63, 118, 119, 120], ["+", 12, 16, 31, 118, 28, 2, 63, 118, 119, 120], ["-", 0, 52, 8, 1, 0, 2, 63, 118, 119, 120], ["+", 0, 52, 8, 1, 0, 2, 63, 118, 119, 120]]
1
321
import java.util.Scanner; class Main { public static void main(String args[]) { Scanner scan = new Scanner(System.in); Main app = new Main(); while (scan.hasNext()) { int second = app.input(scan); int minute = app.getMinute(second); System.out.println(minute); System.out.println(second - minute * 60); } } public int input(Scanner scan) { int time = 0; for (int i = 0; i < 4; i++) { time += scan.nextInt(); } return time; } public int getMinute(int second) { int minute = 0; while (second > 60) { minute++; second -= 60; } return minute; } }
import java.util.Scanner; class Main { public static void main(String args[]) { Scanner scan = new Scanner(System.in); Main app = new Main(); while (scan.hasNext()) { int second = app.input(scan); int minute = app.getMinute(second); System.out.println(minute); System.out.println(second - minute * 60); } } public int input(Scanner scan) { int time = 0; for (int i = 0; i < 4; i++) { time += scan.nextInt(); } return time; } public int getMinute(int second) { int minute = 0; while (second >= 60) { minute++; second -= 60; } return minute; } }
[["-", 8, 196, 0, 52, 15, 15, 0, 16, 17, 47], ["+", 8, 196, 0, 52, 15, 15, 0, 16, 17, 20]]
3
167
import java.util.*; public class Main { public static void main(String[] args) { new Main().run(); } Scanner kbd = new Scanner(System.in); void run() { int sum = 0; int x = 0; int y = 0; while (kbd.hasNext()) { sum += kbd.nextInt(); } while (sum >= 60) { x++; sum -= 60; } y = sum; System.out.println(x + " " + y); } }
import java.util.*; public class Main { public static void main(String[] args) { new Main().run(); } Scanner kbd = new Scanner(System.in); void run() { int sum = 0; int x = 0; int y = 0; while (kbd.hasNext()) { sum += kbd.nextInt(); } while (sum >= 60) { x++; sum -= 60; } y = sum; System.out.println(x + "\n" + y); } }
[["-", 3, 4, 0, 16, 31, 16, 12, 5, 0, 491], ["+", 3, 4, 0, 16, 31, 16, 12, 5, 0, 44]]
3
117
#include <stdio.h> int main(void) { int time; int sum = 0; int i; for (i = 0; i < 4; i++) { scanf("%d", &time); sum += time; } printf("%d\n", time / 60); printf("%d\n", time % 60); return 0; }
#include <stdio.h> int main(void) { int time; int sum = 0; int i; for (i = 0; i < 4; i++) { scanf("%d", &time); sum += time; } printf("%d\n", sum / 60); printf("%d\n", sum % 60); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22]]
0
76
#include <stdio.h> int main(void) { int a[4]; int i; for (i = 0; i < 4; i++) { scanf("%d", &a[i]); } printf("%d %d", (a[0] + a[1] + a[2] + a[3]) / 60, (a[0] + a[1] + a[2] + a[3]) % 60); return 0; }
#include <stdio.h> int main(void) { int a[4]; int i; for (i = 0; i < 4; i++) { scanf("%d", &a[i]); } printf("%d\n%d\n", (a[0] + a[1] + a[2] + a[3]) / 60, (a[0] + a[1] + a[2] + a[3]) % 60); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
104
#include <stdio.h> int main() { int i, t, s; s = 0; for (i = 0; i < 4; i++) { scanf("%d", &t); s = s + t; } printf("%d\n", s / 60); printf("%d\n", s % (s / 60)); return 0; }
#include <stdio.h> int main() { int i, t, s; s = 0; for (i = 0; i < 4; i++) { scanf("%d", &t); s = s + t; } printf("%d\n", s / 60); printf("%d\n", s % 60); return 0; }
[["-", 0, 2, 3, 4, 0, 16, 12, 23, 0, 24], ["-", 3, 4, 0, 16, 12, 23, 0, 16, 31, 22], ["-", 3, 4, 0, 16, 12, 23, 0, 16, 17, 85], ["-", 0, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
0
81
#include <stdio.h> int main(void) { int a, t, s = 0, j; for (t = 0; t < 4; t++) { scanf("%d", &a); s += a; } j = s; for (t = 0; t < 60; t++) { j = j - 60; if (j <= 0) { break; } } s -= t * 60; printf("%d\n%d\n", t, s); return 0; }
#include <stdio.h> int main(void) { int a, t, s = 0, j; for (t = 0; t < 4; t++) { scanf("%d", &a); s += a; } j = s; for (t = 0; t < 60; t++) { j = j - 60; if (j < 0) { break; } } s -= t * 60; printf("%d\n%d\n", t, s); return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18]]
0
107
#include <math.h> #include <stdio.h> int main(void) { int a, b, c, d, t; scanf("%d %d %d %d", &a, &b, &c, &d); a = a + b + c + d; for (t = 0; a > 60; t++) { a -= 60; } printf("%d\n%d\n", t, a); return 0; }
#include <math.h> #include <stdio.h> int main(void) { int a, b, c, d, t; scanf("%d %d %d %d", &a, &b, &c, &d); a = a + b + c + d; for (t = 0; a >= 60; t++) { a -= 60; } printf("%d\n%d\n", t, a); return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 47], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 20]]
0
87
a; main(b, c, d) { scanf("%d%d%d%d", &a, &b, &c, &d); a += b + c + d; a = !printf("%d\n%d\n", a % 60, a / 60); }
a; main(b, c, d) { scanf("%d%d%d%d", &a, &b, &c, &d); a += b + c + d; a = !printf("%d\n%d\n", a / 60, a % 60); }
[["-", 12, 91, 28, 2, 3, 4, 0, 16, 17, 109], ["+", 12, 91, 28, 2, 3, 4, 0, 16, 17, 85], ["-", 12, 91, 28, 2, 3, 4, 0, 16, 17, 85], ["+", 12, 91, 28, 2, 3, 4, 0, 16, 17, 109]]
0
61
#include <stdio.h> int main(void) { int a, b, c, d, e, f, g; scanf("%d%d%d%d", &a, &b, &c, &d); e = a + b + c + d; f = e / 60; g = e % 60; printf("%d %d\n", f, g); return 0; }
#include <stdio.h> int main(void) { int a, b, c, d, e, f, g; scanf("%d%d%d%d", &a, &b, &c, &d); e = a + b + c + d; f = e / 60; g = e % 60; printf("%d\n%d\n", f, g); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
80
#include <stdio.h> int main(void) { int a, s, d, f; scanf("%d %d %d %d", &a, &s, &d, &f); printf("%d %d\n", (d + s + d + f) / 60, (a + s + d + f) % 60); return 0; }
#include <stdio.h> int main(void) { int a, s, d, f; scanf("%d %d %d %d", &a, &s, &d, &f); printf("%d\n%d\n", (a + s + d + f) / 60, (a + s + d + f) % 60); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 31, 23, 0, 16, 31, 16, 31, 16, 31, 22]]
0
72
#include <stdio.h> int main(void) { int a, b, c, d, x = 0, y; scanf("%d %d %d %d", &a, &b, &c, &d); y = a + b + c + d; while (y > 60) { y -= 60; x++; } printf("%d\n%d", x, y); return 0; }
#include <stdio.h> int main(void) { int a, b, c, d, x = 0, y; scanf("%d %d %d %d", &a, &b, &c, &d); y = a + b + c + d; while (y >= 60) { y -= 60; x++; } printf("%d\n%d\n", x, y); return 0; }
[["-", 8, 9, 0, 52, 15, 23, 0, 16, 17, 47], ["+", 8, 9, 0, 52, 15, 23, 0, 16, 17, 20], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
84
#include <stdio.h> int main(void) { int a = 0, b = 0, c = 0, d = 0, e = 0; int x = 0, y = 0; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); e = a + b + c + d; x = e / 60; y = e % 60; printf("%d%\n%d\n", x, y); return 0; }
#include <stdio.h> int main(void) { int a = 0, b = 0, c = 0, d = 0, e = 0; int x = 0, y = 0; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); e = a + b + c + d; x = e / 60; y = e % 60; printf("%d\n%d\n", x, y); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
118
#include <stdio.h> int main(void) { int f1, t1, sum = 0; for (f1 = 1; f1 <= 4; f1++) { scanf("%d", &t1); sum += t1; } printf("%d\n%d\n", t1 / 60, t1 % 60); return 0; }
#include <stdio.h> int main(void) { int f1, t1, sum = 0; for (f1 = 1; f1 <= 4; f1++) { scanf("%d", &t1); sum += t1; } printf("%d\n%d\n", sum / 60, sum % 60); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22]]
0
68
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) reep((i), 0, (n)) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI = 6 * asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } // v.erase(unique(v.begin(),v.end()),v.end()); int main() { int a[4]; rep(i, 4) { cin >> a[i]; } int s = 0; rep(i, s) { s += a[i]; } int b[] = {60, 1}; int c[2] = {0}; rep(i, 2) { while (s >= b[i]) { s -= b[i]; c[i]++; } } cout << c[0] << endl << c[1] << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define reep(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) reep((i), 0, (n)) #define ALL(v) (v).begin(), (v).end() #define PB push_back #define EPS 1e-8 #define F first #define S second #define mkp make_pair static const double PI = 6 * asin(0.5); typedef long long ll; typedef complex<double> CP; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vint; static const int INF = 1 << 24; template <class T> void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) { v.assign(a, vector<T>(b, t)); } // v.erase(unique(v.begin(),v.end()),v.end()); int main() { int a[4]; rep(i, 4) { cin >> a[i]; // cout<<a[i]<<endl; } int s = 0; rep(i, 4) { s += a[i]; } // cout<<s<<endl; int b[] = {60, 1}; int c[2] = {0}; rep(i, 2) { while (s >= b[i]) { s -= b[i]; c[i]++; } } cout << c[0] << endl << c[1] << endl; return 0; }
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
301
#include <iostream> using namespace std; main() { int a, count = 0; for (int i = 0; i < 4; i++) { cin >> a; count = count + a; } cout << count / 60 << count % 60; }
#include <iostream> using namespace std; main() { int a, count = 0; for (int i = 0; i < 4; i++) { cin >> a; count = count + a; } cout << count / 60 << endl << count % 60 << endl; }
[["+", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
54
#include <cstdio> using namespace std; int main(void) { int s, s1, s2, s3, i, j, x, y, a, b; scanf("%d", &s); scanf("%d", &s1); scanf("%d", &s2); scanf("%d", &s3); a = s + s1 + s2 + s3; if (a > 60) { x = a / 60; y = a % 60; printf("%d\n%d\n", x, y); } else { printf("%d\n", a); } return 0; }
#include <cstdio> using namespace std; int main(void) { int s, s1, s2, s3, i, j, x, y, a, b; scanf("%d", &s); scanf("%d", &s1); scanf("%d", &s2); scanf("%d", &s3); a = s + s1 + s2 + s3; if (a >= 60) { x = a / 60; y = a % 60; printf("%d\n%d\n", x, y); } else { printf("%d\n", a); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
134
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> using namespace std; int main() { int second[5] = {0}, ans[3]; cin >> second[1] >> second[2] >> second[3] >> second[4]; ans[2] = second[1] + second[2] + second[3] + second[4]; ans[1] = ans[3] / 60; ans[2] %= 60; cout << ans[1] << "\n" << ans[2] << endl; return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <string> using namespace std; int main() { int second[5] = {0}, ans[3]; cin >> second[1] >> second[2] >> second[3] >> second[4]; ans[2] = second[1] + second[2] + second[3] + second[4]; ans[1] = ans[2] / 60; ans[2] %= 60; cout << ans[1] << "\n" << ans[2] << endl; return 0; }
[["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 13], ["+", 0, 11, 12, 16, 31, 69, 341, 342, 0, 13]]
1
126
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int n, ansm = 0, anss = 0; for (int i = 0; i < 4; ++i) { cin >> n; anss += n; if (anss > 60) { ansm += anss / 60; anss %= 60; } } cout << ansm << "\n" << anss << endl; return 0; }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int n, ansm = 0, anss = 0; for (int i = 0; i < 4; ++i) { cin >> n; anss += n; if (anss > 59) { ansm += anss / 60; anss %= 60; } } cout << ansm << "\n" << anss << endl; return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
84
#include <bits/stdc++.h> using namespace std; int a, b, c, d; int main() { cin >> a >> b >> c >> d; int z = a + b + c + d; cout << z / 60 << z % 60 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a, b, c, d; int main() { cin >> a >> b >> c >> d; int z = a + b + c + d; cout << z / 60 << endl << z % 60 << endl; return 0; }
[["+", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
1
57