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
f, b, d, e, m; main(a) { for (; d = scanf("%d", &a), a; printf("%d\n", m)) for (m = 9e7; (e = d * d * d - a) < 1; d++) for (b = 0; (f = -e - b * b) >= 0;) m = fmin(d + f + b++, m); }
f, b, d, e, m; main(a) { for (; d = !scanf("%d", &a), m = a; printf("%d\n", m)) for (m = 9e7; (e = d * d * d - a) < 1; d++) for (b = 0; (f = -e - b * b) >= 0;) m = fmin(d + f + b++, m); }
[["+", 0, 7, 15, 34, 31, 11, 12, 91, 17, 111], ["+", 8, 9, 0, 7, 15, 34, 12, 11, 31, 22], ["+", 8, 9, 0, 7, 15, 34, 12, 11, 17, 32]]
0
100
#include <stdio.h> int main(void) { int i, e, ee, x, y, z, min; while (scanf("%d", &e), e) { min = e; for (z = 0; z * z * z <= e; z++) { ee = e - z * z * z; for (y = 0; y * y <= ee; y++) ; x = ee - y * y; if (x + y + z < min) min = x + y + z; } printf("%d\n", min); } return 0; }
#include <stdio.h> int main(void) { int i, e, ee, x, y, z, min; while (scanf("%d", &e), e) { min = e; for (z = 0; z * z * z <= e; z++) { ee = e - z * z * z; for (y = 0; y * y + 2 * y + 1 <= ee; y++) ; x = ee - y * y; if (x + y + z < min) min = x + y + z; } printf("%d\n", min); } return 0; }
[["+", 0, 7, 15, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 31, 13], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 17, 48], ["+", 15, 16, 31, 16, 31, 16, 12, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 12, 13]]
0
128
#include <stdio.h> int main() { int e, x, y, z, r; for (; scanf("%d", &e), e;) { r = 10000000; for (z = 0; z * z * z <= e; z++) for (y = 0; y * y <= e - z * z * z; y++) if (e - y * y - z * z * z < r) r = e - y * y - z * z * z + y + z; printf("%d\n", r); } return 0; }
#include <stdio.h> int main() { int e, x, y, z, r; for (; scanf("%d", &e), e;) { r = 10000000; for (z = 0; z * z * z <= e; z++) for (y = 0; y * y <= e - z * z * z; y++) if (e - y * y - z * z * z + y + z < r) r = e - y * y - z * z * z + y + z; printf("%d\n", r); } return 0; }
[["+", 15, 23, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 15, 23, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 57, 15, 23, 0, 16, 31, 16, 17, 72], ["+", 8, 57, 15, 23, 0, 16, 31, 16, 12, 22]]
0
126
#include <cmath> #include <iostream> using namespace std; int solve(int E) { int ans = 3000000; int x; for (int y = 0; y <= 1000; ++y) for (int z = 0; z <= 100; ++z) { x = E - y * y - z * z * z; if ((x + y + z < ans) && (x > 0)) ans = x + y + z; } return ans; } int main() { int E; while (cin >> E && E > 0) cout << solve(E) << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; int solve(int E) { int ans = 3000000; int x; for (int y = 0; y <= 1000; ++y) for (int z = 0; z <= 100; ++z) { x = E - y * y - z * z * z; if ((x + y + z < ans) && (x >= 0)) ans = x + y + z; } return ans; } int main() { int E; while (cin >> E && E > 0) cout << solve(E) << endl; return 0; }
[["-", 15, 339, 51, 16, 12, 23, 0, 16, 17, 47], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 20]]
1
128
#include <bits/stdc++.h> #define int long long using namespace std; main() { int e; while (cin >> e, e) { int ans = 1e9; for (int z = 0;; z++) { if (z * z * z > e) break; for (int y = 0;; y++) { if (z * z * z + y * y > e) break; int a = e - z * z * z + y * y; ans = min(ans, a + y + z); } } cout << ans << endl; } }
#include <bits/stdc++.h> #define int long long using namespace std; main() { int e; while (cin >> e, e) { int ans = 1e9; for (int z = 0;; z++) { if (z * z * z > e) break; for (int y = 0;; y++) { if (z * z * z + y * y > e) break; int a = e - z * z * z - y * y; ans = min(ans, a + y + z); } } cout << ans << endl; } }
[["-", 8, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 33]]
1
120
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define loop(n) FOR(i, 0, n) #define rrep(i, a, b) for (int i = (a); i >= (b); --i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { while (true) { int e; cin >> e; if (e == 0) return 0; // x+y*y+z*z*z=e; LL ans = INF; for (LL y = 0; y * y <= e; y++) { for (LL z = 0; z * z * z <= e; z++) { LL x = e - y * y - z * z * z; if (x > 0) { ans = min(ans, x + y + z); } } } cout << ans << endl; } return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define loop(n) FOR(i, 0, n) #define rrep(i, a, b) for (int i = (a); i >= (b); --i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 int main() { while (true) { int e; cin >> e; if (e == 0) return 0; // x+y*y+z*z*z=e; LL ans = INF; for (LL y = 0; y * y <= e; y++) { for (LL z = 0; z * z * z <= e; z++) { LL x = e - y * y - z * z * z; if (x >= 0) { ans = min(ans, x + y + z); } } } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
420
#include <algorithm> #include <iostream> using namespace std; int main() { while (true) { int e; int ans = 1e+9; cin >> e; if (e == 0) { break; } for (int z = 100; z >= 0; z--) { for (int y = 1000; y >= 0; y--) { int x; if (e >= z * z * z + y * y) { x = e - z * z * z - y * y; } ans = min(ans, x + y + z); } } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { while (true) { int e; int ans = 1e+9; cin >> e; if (e == 0) { break; } for (int z = 100; z >= 0; z--) { for (int y = 1000; y >= 0; y--) { int x; if (e >= z * z * z + y * y) { x = e - z * z * z - y * y; ans = min(ans, x + y + z); } } } cout << ans << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
129
#include <cmath> #include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ret = 1e6; for (int z = 0; z <= e; ++z) { int y = (int)pow(e - z * z * z, 1.0 / 2.0); int x = e - z * z * z - y * y; ret = min(ret, x + y + z); } cout << ret << endl; } return 0; }
#include <cmath> #include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ret = 1e6; for (int z = 0; z * z * z <= e; ++z) { int y = (int)pow(e - z * z * z, 1.0 / 2.0); int x = e - z * z * z - y * y; ret = min(ret, x + y + z); } cout << ret << endl; } return 0; }
[["+", 0, 7, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 12, 22]]
1
106
#include <algorithm> #include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ans = 1000000000; for (int z = 0; z * z * z <= e; z++) for (int y = 0; y * y + z * z * z <= e; y++) ans = min(ans, (e - y * y * -z * z * z) + y + z); cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int main() { int e; while (cin >> e, e) { int ans = 1000000000; for (int z = 0; z * z * z <= e; z++) for (int y = 0; y * y + z * z * z <= e; y++) ans = min(ans, (e - y * y - z * z * z) + y + z); cout << ans << endl; } }
[["-", 0, 16, 12, 16, 31, 16, 31, 16, 17, 48]]
1
104
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> using namespace std; int Bsearch(int e, int n) { // cout << n << endl; int l = 0, r = e; int i = (l + r) / 2; while (r - l >= 1) { i = (l + r) / 2; // cout << "i:" << i << endl; if (e == pow(i, n)) { // cout << "aaa:" << i << endl; return i; } else if (e > pow(i, n)) { l = i + 1; } else { r = i; } } // cout << "i:" << i << endl; return i; } int a[2000][2000]; int main() { int x, y, z, e; while (cin >> e, e) { memset(a, 0, sizeof(a)); y = Bsearch(e, 2); z = Bsearch(e, 3); int m = 1000000; // cout << "z:" << z << " y:" << y << endl; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 100; j++) { x = e - i * i - j * j * j; if (x >= 0) m = min(x + i + j, m); } } cout << "ans:" << m << endl; } }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> using namespace std; int Bsearch(int e, int n) { // cout << n << endl; int l = 0, r = e; int i = (l + r) / 2; while (r - l >= 1) { i = (l + r) / 2; // cout << "i:" << i << endl; if (e == pow(i, n)) { // cout << "aaa:" << i << endl; return i; } else if (e > pow(i, n)) { l = i + 1; } else { r = i; } } // cout << "i:" << i << endl; return i; } int a[2000][2000]; int main() { int x, y, z, e; while (cin >> e, e) { memset(a, 0, sizeof(a)); y = Bsearch(e, 2); z = Bsearch(e, 3); int m = 1000000; // cout << "z:" << z << " y:" << y << endl; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 100; j++) { x = e - i * i - j * j * j; if (x >= 0) m = min(x + i + j, m); } } cout << m << endl; } }
[["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151]]
1
258
#include <algorithm> #include <iostream> using namespace std; int e; int x, y, z; int main() { while (true) { cin >> e; int ans = 1000000; if (e == 0) break; for (int z = 0; z * z * z < e; z++) { for (int y = 0; y * y + z * z * z < e; y++) { x = e - y * y - z * z * z; ans = min(ans, x + y + z); } } cout << ans << endl; } }
#include <algorithm> #include <iostream> using namespace std; int e; int x, y, z; int main() { while (true) { cin >> e; int ans = 1000000; if (e == 0) break; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y + z * z * z <= e; y++) { x = e - y * y - z * z * z; ans = min(ans, x + y + z); } } cout << ans << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
124
#include <iostream> using namespace std; int main() { int x, y, y2, z, z3, e; while (cin >> e && e != 0) { int min = 1e6; for (y = 0; y <= 1e3; y++) { y2 = y * y; for (z = 0; z <= 1e2; z++) { z3 = z * z * z; x = e - y2 - z3; if (min > x + y + z && x > 0) { min = x + y + z; } } } cout << min << endl; } }
#include <iostream> using namespace std; int main() { int x, y, y2, z, z3, e; while (cin >> e && e != 0) { int min = 1e6; for (y = 0; y <= 1e3; y++) { y2 = y * y; for (z = 0; z <= 1e2; z++) { z3 = z * z * z; x = e - y2 - z3; if (min > x + y + z && x >= 0) { min = x + y + z; } } } cout << min << endl; } }
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20]]
1
124
#include <iostream> using namespace std; int E; int main() { while (cin >> E) { if (E == 0) break; int min = 1000001; for (int z = 0; z * z * z < E; ++z) { for (int y = 0; y * y < E - z * z * z; ++y) { int x = E - z * z * z - y * y; if (x + y + z < min) min = x + y + z; } } cout << min << endl; } return 0; }
#include <iostream> using namespace std; int E; int main() { while (cin >> E) { if (E == 0) break; int min = 100000001; for (int z = 0; z * z * z < E + 1; ++z) { for (int y = 0; y * y < E - z * z * z + 1; ++y) { int x = E - z * z * z - y * y; if (x + y + z < min) min = x + y + z; } } cout << min << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13]]
1
122
#include <iostream> using namespace std; int main() { int e; int minimum = 10000000, n = 0; while (1) { minimum = 10000000; cin >> e; if (e == 0) break; for (int i = 0; i < 100; i++) { for (int j = 0; j < 1000; j++) { n = e - i * i * i - j * j; if (n + i + j < minimum && n > 0) minimum = n + i + j; } } cout << minimum << endl; } return 0; }
#include <iostream> using namespace std; int main() { int e; int minimum = 10000000, n = 0; while (1) { minimum = 10000000; cin >> e; if (e == 0) break; for (int i = 0; i < 101; i++) { for (int j = 0; j < 1001; j++) { n = e - i * i * i - j * j; if (n + i + j < minimum && n >= 0) minimum = n + i + j; } } cout << minimum << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20]]
1
123
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int i, j, k, l; while (1) { int x, y, z; int e; int tmp_ans, ans; scanf("%d", &e); if (e == 0) break; tmp_ans = e; for (z = 0; z * z * z < e; z++) { for (y = 0;; y++) { x = e - z * z * z - y * y; if (0 > x) break; if (tmp_ans > x + y + z) tmp_ans = x + y + z; } } ans = tmp_ans; printf("%d\n", ans); } return 0; }
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { int i, j, k, l; while (1) { int x, y, z; int e; int tmp_ans, ans; scanf("%d", &e); if (e == 0) break; tmp_ans = e; for (z = 0; z * z * z <= e; z++) { for (y = 0;; y++) { x = e - z * z * z - y * y; if (0 > x) break; if (tmp_ans > x + y + z) tmp_ans = x + y + z; } } ans = tmp_ans; printf("%d\n", ans); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
155
#include <iostream> using namespace std; int main() { int x, y, z, e, ans; while (cin >> e && e > 0) { ans = 1000000; for (z = 0; z * z * z <= e; z++) for (y = 0; (x = e - y * y + z * z * z) >= 0; y++) if (x + y + z < ans) ans = x + y + z; cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main() { int x, y, z, e, ans; while (cin >> e && e > 0) { ans = 1000000; for (z = 0; z * z * z <= e; z++) for (y = 0; (x = e - y * y - z * z * z) >= 0; y++) if (x + y + z < ans) ans = x + y + z; cout << ans << endl; } return 0; }
[["-", 8, 7, 15, 16, 31, 23, 0, 16, 17, 72], ["+", 8, 7, 15, 16, 31, 23, 0, 16, 17, 33]]
1
110
#include <iostream> #include <math.h> using namespace std; int E; int solve(int e) { int mi = e; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y <= e; y++) { if (e - y * y - z * z * z > 0) { mi = min(mi, e - y * y - z * z * z + y + z); } } } return mi; } int min(int a, int b) { if (a < b) return a; else return b; } int main() { while (cin >> E && E > 0) { cout << solve(E) << endl; } }
#include <iostream> #include <math.h> using namespace std; int E; int solve(int e) { int mi = e; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y <= e; y++) { if (e - y * y - z * z * z >= 0) { mi = min(mi, e - y * y - z * z * z + y + z); } } } return mi; } int min(int a, int b) { if (a < b) return a; else return b; } int main() { while (cin >> E && E > 0) { cout << solve(E) << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
157
#include <cmath> #include <iostream> using namespace std; int count = 0; // count the number of iterations int solve(int E) { int ans = E; for (int y = 0; y * y <= E; ++y) for (int z = 0; z * z * z <= E; ++z) { ++count; // Minimum number of counts when the looping is minimized; loop y // and z thus. int x = (int)round(E - y * y - z * z * z); if (x + y * y + z * z * z == E && x > 0) ans = min(ans, x + y + z); } return ans; } int main() { int E; while (cin >> E && E > 0) { cout << solve(E) << endl; } }
#include <cmath> #include <iostream> using namespace std; int count = 0; // count the number of iterations int solve(int E) { int ans = E; for (int y = 0; y * y <= E; ++y) for (int z = 0; z * z * z <= E; ++z) { // ++count; // Minimum number of counts when the looping is minimized; // loop y and z thus. int x = (int)round(E - y * y - z * z * z); if (x + y * y + z * z * z == E && x >= 0) ans = min(ans, x + y + z); } return ans; } int main() { int E; while (cin >> E && E > 0) { cout << solve(E) << endl; } }
[["-", 8, 7, 8, 9, 0, 1, 0, 27, 17, 29], ["-", 8, 7, 8, 9, 0, 1, 0, 27, 28, 22], ["-", 0, 7, 8, 7, 8, 9, 0, 1, 0, 35], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20]]
1
155
#include <iostream> using namespace std; int solve(int n) { int e = 1e6; for (int i = 0; i * i * i < e; ++i) { for (int k = 0; k * k < e - i * i * i; ++k) { e = min(e, n - i * i * i - k * k + i + k); } } return e; } int main() { int n; while (true) { cin >> n; if (n == 0) { break; } cout << solve(n) << endl; } }
#include <iostream> using namespace std; int solve(int n) { int e = 1e6; for (int i = 0; i * i * i <= n; ++i) { for (int k = 0; k * k <= n - i * i * i; ++k) { e = min(e, n - i * i * i - k * k + i + k); } } return e; } int main() { int n; while (true) { cin >> n; if (n == 0) { break; } cout << solve(n) << endl; } }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22]]
1
127
#include <iostream> using namespace std; int main() { while (1) { int e, min = 100000000, ans; cin >> e; if (e == 0) break; for (int i = 0; i * i * i < e; i++) { for (int j = 0; j * j <= e; j++) { ans = e - (i * i * i + j * j); if (min > ans + j + i && e >= ans && ans >= 0) min = ans + i + j; } } cout << min << endl; } return 0; }
#include <iostream> using namespace std; int main() { while (1) { int e, min = 100000000, ans; cin >> e; if (e == 0) break; for (int i = 0; i * i * i <= e; i++) { for (int j = 0; j * j <= e; j++) { ans = e - (i * i * i + j * j); if (min > ans + j + i && e >= ans && ans >= 0) min = ans + i + j; } } cout << min << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
128
#include <algorithm> #include <stdio.h> using namespace std; int e; int main() { while (true) { scanf("%d", &e); if (e == 0) break; int ret = 999999999; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y + z * z * z <= e; y++) { ret = min(ret, e - y * y + z * z * z + y + z); } } printf("%d\n", ret); } }
#include <algorithm> #include <stdio.h> using namespace std; int e; int main() { while (true) { scanf("%d", &e); if (e == 0) break; int ret = 999999999; for (int z = 0; z * z * z <= e; z++) { for (int y = 0; y * y + z * z * z <= e; y++) { ret = min(ret, e - y * y - z * z * z + y + z); } } printf("%d\n", ret); } }
[["-", 3, 4, 0, 16, 31, 16, 31, 16, 17, 72], ["+", 3, 4, 0, 16, 31, 16, 31, 16, 17, 33]]
1
123
#include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr, __VA_ARGS__) //#define LOG(...) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SZ(a) ((int)(a).size()) #define BIT(x, i) (((x) >> (i)) & 1) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { int e; while (cin >> e, e) { int m = 1000000; for (int y = 0; y * y < e; y++) for (int z = 0; y * y + z * z * z < e; z++) { int x = e - y * y - z * z * z; if (m > x + y + z) { m = x + y + z; } } cout << m << endl; } }
#include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr, __VA_ARGS__) //#define LOG(...) #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SZ(a) ((int)(a).size()) #define BIT(x, i) (((x) >> (i)) & 1) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { int e; while (cin >> e, e) { int m = 1000000; for (int y = 0; y * y <= e; y++) for (int z = 0; y * y + z * z * z <= e; z++) { int x = e - y * y - z * z * z; if (m > x + y + z) { m = x + y + z; } } cout << m << endl; } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 8, 9, 0, 7, 8, 7, 15, 16, 17, 18], ["+", 8, 9, 0, 7, 8, 7, 15, 16, 17, 19]]
1
253
#include <iostream> using namespace std; const int INF = 10000003; int main() { int e; while (cin >> e) { int ans = INF; for (int i = 0; i * i * i <= e; i++) { int tmp = e - i * i * i; for (int j = 0; j * j <= tmp; j++) ans = min(ans, i + tmp - j * j + j); } cout << ans << endl; } }
#include <iostream> using namespace std; const int INF = 10000003; int main() { int e; while (cin >> e && e) { int ans = INF; for (int i = 0; i * i * i <= e; i++) { int tmp = e - i * i * i; for (int j = 0; j * j <= tmp; j++) ans = min(ans, i + tmp - j * j + j); } cout << ans << endl; } }
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
1
104
#include <iostream> using namespace std; int main() { int e, x = 0, y = 0, z = 0, ans, n, i, j; while (1) { ans = 10000000; cin >> e; if (e == 0) break; i = 1; while (1) { if (i * i * i > e) break; i++; } i--; for (; i >= 0; i--) { n = e; n -= i * i * i; z = i; if (n == 0) { ans = min(ans, z); continue; } for (j = 0; j * j < n; j++) ; j--; n -= j * j; y = j; if (n == 0) { ans = min(ans, z + y); continue; } x = n; ans = min(ans, x + y + z); // cout << x << " " << y << " " << z <<endl; } j = 1; while (1) { if (j * j > e) break; j++; } j--; for (; j >= 0; j--) { n = e; n -= j * j; if (n == 0) { ans = min(ans, j); } else { ans = min(ans, j + n); } // cout << n << " " << j <<endl; } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main() { int e, x = 0, y = 0, z = 0, ans, n, i, j; while (1) { ans = 10000000; cin >> e; if (e == 0) break; i = 1; while (1) { if (i * i * i > e) break; i++; } i--; for (; i >= 0; i--) { n = e; n -= i * i * i; z = i; if (n == 0) { ans = min(ans, z); continue; } for (j = 0; j * j <= n; j++) ; j--; n -= j * j; y = j; if (n == 0) { ans = min(ans, z + y); continue; } x = n; ans = min(ans, x + y + z); // cout << x << " " << y << " " << z <<endl; } j = 1; while (1) { if (j * j > e) break; j++; } j--; for (; j >= 0; j--) { n = e; n -= j * j; if (n == 0) { ans = min(ans, j); } else { ans = min(ans, j + n); } // cout << n << " " << j <<endl; } cout << ans << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
289
#include <algorithm> #include <iostream> int main() { int energy; while (std::cin >> energy, energy) { int sol = 1e+9; for (int z = 0; z * z * z < energy; z++) { for (int y = 0, yMax = energy - z * z * z; y * y < yMax; y++) { sol = std::min(sol, z + y + (energy - z * z * z - y * y)); } } std::cout << sol << std::endl; } return (0); }
#include <algorithm> #include <iostream> int main() { int energy; while (std::cin >> energy, energy) { int sol = 1e+9; for (int z = 0; z * z * z <= energy; z++) { for (int y = 0, yMax = energy - z * z * z; y * y <= yMax; y++) { // int y = ::sqrt(energy - z * z * z); sol = std::min(sol, z + y + (energy - z * z * z - y * y)); } } std::cout << sol << std::endl; } return (0); }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
120
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define pb push_back #define mp(a, b) make_pair(a, b) #define all(a) a.begin(), a.end() #define len(x) ((int)(x).size()) #define tmax(a, b, c) max((a), max((b), (c))) #define tmin(a, b, c) min((a), min((b), (c))) #define debug(x) cerr << #x << " is " << x << endl; typedef pair<int, int> Pii; typedef vector<int> Vi; typedef vector<vector<int>> VVi; typedef long long ll; const int inf = 2e9; const ll ll_inf = 1e17; const int mod = 1e9 + 7; const long double eps = 1e-10; int main() { while (1) { int e; cin >> e; if (!e) break; int ans = inf; rep(i, 0, 1001) { rep(j, 0, 1001) { int l = 0; int r = 1000; int x = i * i * i + j * j; if (x > e) continue; rep(k, 0, 10) { int m = (l + r) / 2; if (x + k == e) { ans = min(ans, i + j + k); } else if (x + k > e) r = m; else l = m; } } } cout << ans << endl; } return 0; }
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996) #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define pb push_back #define mp(a, b) make_pair(a, b) #define all(a) a.begin(), a.end() #define len(x) ((int)(x).size()) #define tmax(a, b, c) max((a), max((b), (c))) #define tmin(a, b, c) min((a), min((b), (c))) #define debug(x) cerr << #x << " is " << x << endl; typedef pair<int, int> Pii; typedef vector<int> Vi; typedef vector<vector<int>> VVi; typedef long long ll; const int inf = 2e9; const ll ll_inf = 1e17; const int mod = 1e9 + 7; const long double eps = 1e-10; int main() { while (1) { int e; cin >> e; if (!e) break; int ans = inf; rep(i, 0, 1001) { rep(j, 0, 1001) { int l = 0; int r = 1000; int x = i * i * i + j * j; if (x > e) continue; rep(k, 0, 12) { int m = (l + r) / 2; if (x + m == e) { // printf("i=%d j=%d m=%d\n",i,j,m); ans = min(ans, i + j + m); } else if (x + m > e) r = m; else l = m; } } } cout << ans << endl; } return 0; }
[["-", 0, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 22]]
1
306
#include <algorithm> #include <cmath> #include <iostream> #include <limits> #include <vector> using namespace std; int count = 0; // ?¨???¬??¨ global ?????° int solve(int E) { ::count = 0; int ans = numeric_limits<int>::max(); // ?????§??? for (int y = 0; y * y <= E; ++y) { for (int z = 0; z * z * z <= E; ++z) { ++::count; int x = (int)round(E - y * y - z * z * z); if (x + y * y + z * z * z == E) ans = min(ans, x + y + z); } } return ans; } int main() { int E; while (cin >> E && E > 0) { cout << solve(E) << endl; // cout << "case: m = " << E << " count: " << ::count << endl; } }
#include <algorithm> #include <cmath> #include <iostream> #include <limits> #include <vector> using namespace std; int count = 0; // ?¨???¬??¨ global ?????° int solve(int E) { ::count = 0; int ans = numeric_limits<int>::max(); // ?????§??? for (int y = 0; y * y <= E; ++y) { for (int z = 0; z * z * z <= E; ++z) { ++::count; int x = (int)round(E - y * y - z * z * z); if (x + y * y + z * z * z == E && x >= 0) ans = min(ans, x + y + z); } } return ans; } int main() { int E; while (cin >> E && E > 0) { cout << solve(E) << endl; // cout << "case: m = " << E << " count: " << ::count << endl; } }
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
172
#include "bits/stdc++.h" #define REP(i, n) for (int i = 0; i < n; ++i) #define RREP(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define RFOR(i, m, n) for (int i = n - 1; i >= m; --i) #define ALL(v) v.begin(), v.end() #define PB(a) push_back(a) #define INF 1000000001 #define MOD 1000000007 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int e, ans = INF; cin >> e; int c = e; if (!e) break; for (int i = 0; i * i * i < e; ++i) { int y = sqrt(e - i * i * i); int x = e - i * i * i - y * y; ans = min(ans, x + y + i); } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" #define REP(i, n) for (int i = 0; i < n; ++i) #define RREP(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define RFOR(i, m, n) for (int i = n - 1; i >= m; --i) #define ALL(v) v.begin(), v.end() #define PB(a) push_back(a) #define INF 1000000001 #define MOD 1000000007 const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { int e, ans = INF; cin >> e; if (!e) break; for (int i = 0; i * i * i <= e; ++i) { int y = sqrt(e - i * i * i); int x = e - i * i * i - y * y; ans = min(ans, x + y + i); } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 43, 0, 35], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
232
#include <algorithm> #include <iostream> #include <vector> using namespace std; vector<int> ans; int main() { while (1) { int e; cin >> e; if (e == 0) break; int m = 1e9; for (int i = 0; i < e; i++) { if (i * i * i > e) break; int iii = i * i * i; for (int j = 0; j < e - iii; j++) { if (j * j > e - iii) break; int jj = j * j; int k = e - jj - iii; m = min(m, i + j + k); } } ans.push_back(m); } for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; vector<int> ans; int main() { while (1) { int e; cin >> e; if (e == 0) break; int m = 1e9; for (int i = 0; i < e; i++) { if (i * i * i > e) break; int iii = i * i * i; for (int j = 0; j <= e - iii; j++) { if (j * j > e - iii) break; int jj = j * j; int k = e - jj - iii; m = min(m, i + j + k); } } ans.push_back(m); } for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl; return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
181
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int e; while (cin >> e && e > 0) { int min_sum = 100000; for (int i = 0; i <= e; i++) { int j = sqrt(e - i * i * i); int k = e - i * i * i - j * j; int temp = i + j + k; min_sum = min(temp, min_sum); } cout << min_sum << endl; } }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int e; while (cin >> e && e > 0) { int min_sum = 100000; for (int i = 0; i * i * i <= e; i++) { int j = sqrt(e - i * i * i); int k = e - i * i * i - j * j; int temp = i + j + k; min_sum = min(temp, min_sum); } cout << min_sum << endl; } }
[["+", 0, 7, 15, 16, 31, 16, 31, 16, 17, 48], ["+", 0, 7, 15, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 48], ["+", 8, 9, 0, 7, 15, 16, 31, 16, 12, 22]]
1
105
#include <iostream> #define FOR(i, l, n) for (int(i) = (l); (i) < (n); (i)++) #define REP(i, n) FOR(i, 0, n) using namespace std; int main() { long int x, y, z, e, m; while (cin >> e, e) { m = e; for (y = 0; y * y <= e; y++) { for (z = 0; z * z * z <= e; z++) { x = e - y * y - z * z * z; m = m < x + y + z ? m : x + y + z; } } cout << m << endl; } return 0; }
#include <iostream> #define FOR(i, l, n) for (int(i) = (l); (i) < (n); (i)++) #define REP(i, n) FOR(i, 0, n) using namespace std; int main() { long int x, y, z, e, m; while (cin >> e, e) { m = e; for (y = 0; y * y <= e; y++) { for (z = 0; z * z * z + y * y <= e; z++) { x = e - y * y - z * z * z; m = m < x + y + z ? m : x + y + z; } } cout << m << endl; } return 0; }
[["+", 8, 9, 0, 7, 15, 16, 31, 16, 17, 72], ["+", 0, 7, 15, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 7, 15, 16, 31, 16, 12, 16, 17, 48], ["+", 0, 7, 15, 16, 31, 16, 12, 16, 12, 22]]
1
133
#include <iostream> using namespace std; int main() { while (1) { int e, x, y, z, m, min = 10000000; cin >> e; if (e == 0) { break; } for (z = 0; z * z * z < e; z++) { for (y = 0; y * y + z * z * z < e; y++) { m = e - (y * y + z * z * z) + y + z; if (m < min) { min = m; } } } cout << min << endl; } }
#include <iostream> using namespace std; int main() { while (1) { int e, x, y, z, m, min = 10000000; cin >> e; if (e == 0) { break; } for (z = 0; z * z * z <= e; z++) { for (y = 0; y * y + z * z * z <= e; y++) { m = e - (y * y + z * z * z) + y + z; if (m < min) { min = m; } } } cout << min << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 35]]
1
127
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) \ for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define popcount __builtin_popcount #define rep(i, n) for (int i = 0; i < n; ++i) template <class T> void max_swap(T &a, const T &b) { a = max(a, b); } template <class T> void min_swap(T &a, const T &b) { a = min(a, b); } const double EPS = 1e-10; typedef long long ll; typedef pair<int, int> pint; int main() { int e; while (scanf("%d", &e), e) { int res = e; int z_max = pow(e, 1.0 / 3) + 1; int y_max = (int)sqrt(e + 0.0) + 1; for (int z = z_max; z >= 0; --z) { for (int y = y_max; y >= 0; --y) { int x = e - (z * z * z + y * y); if (x >= 0) min_swap(res, x + y + z); else break; } } printf("%d\n", res); } }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #ifdef _MSC_VER #define __typeof__ decltype template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; } #endif #define foreach(it, c) \ for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define popcount __builtin_popcount #define rep(i, n) for (int i = 0; i < n; ++i) template <class T> void max_swap(T &a, const T &b) { a = max(a, b); } template <class T> void min_swap(T &a, const T &b) { a = min(a, b); } const double EPS = 1e-10; typedef long long ll; typedef pair<int, int> pint; int main() { int e; while (scanf("%d", &e), e) { int res = e; int z_max = pow(e, 1.0 / 3) + 1; int y_max = (int)sqrt(e + 0.0) + 1; for (int z = z_max; z >= 0; --z) { for (int y = y_max; y >= 0; --y) { int x = e - (z * z * z + y * y); if (x >= 0) min_swap(res, x + y + z); } } printf("%d\n", res); } }
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["-", 8, 9, 0, 57, 75, 76, 0, 93, 0, 94], ["-", 8, 9, 0, 57, 75, 76, 0, 93, 0, 35]]
1
331
#include <stdio.h> #include <vector> using namespace std; int solve(int e) { int minsum = 10000000; for (int z = 0; z * z * z <= e; z++) { for (int y = 0, lim = e - z * z * z; y * y < lim; y++) { int x = e - y * y - z * z * z; if (minsum > x + y + z) { minsum = x + y + z; } } } return minsum; } int main(void) { int e; while (scanf("%d", &e) == 1 && e) { printf("%d\n", solve(e)); } return 0; }
#include <stdio.h> #include <vector> using namespace std; int solve(int e) { int minsum = 10000000; for (int z = 0; z * z * z <= e; z++) { for (int y = 0, lim = e - z * z * z; y * y <= lim; y++) { int x = e - y * y - z * z * z; if (minsum > x + y + z) { minsum = x + y + z; } } } return minsum; } int main(void) { int e; while (scanf("%d", &e) == 1 && e) { printf("%d\n", solve(e)); } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
151
#include <cctype> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> using namespace std; int main(int argc, char const *argv[]) { int e; while (cin >> e, e) { int x, y, z; int m = 1000000; // for (int i = 0; i <= e; i++) //{ // for (int j = 0; j*j <= e; j++) // { // for (int k = 0; k*k*k <= e; k++) // { // //cout << " x y z = " << i << j << k <<endl; // if ( i + j*j + k*k*k == e) // { // m = min( m, i + j + k); // } // } // } //} for (int k = 0; 0 <= k * k * k; k++) { int j = sqrt(e - k * k * k); int i = e - k * k * k - j * j; m = min(m, i + j + k); } cout << m << endl; } return 0; }
#include <cctype> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stdio.h> using namespace std; int main(int argc, char const *argv[]) { int e; while (cin >> e, e) { int x, y, z; int m = 1000000; // for (int i = 0; i <= e; i++) //{ // for (int j = 0; j*j <= e; j++) // { // for (int k = 0; k*k*k <= e; k++) // { // //cout << " x y z = " << i << j << k <<endl; // if ( i + j*j + k*k*k == e) // { // m = min( m, i + j + k); // } // } // } //} for (int k = 0; k * k * k <= e; k++) { int j = sqrt(e - k * k * k); int i = e - k * k * k - j * j; m = min(m, i + j + k); } cout << m << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 31, 13], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
1
141
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int x, y, z, e; while (cin >> e) { int ret = 999999999; for (int y = 0; y * y <= e; y++) { for (int z = 0; z * z * z <= e; z++) { if (e - (y * y + z * z * z) >= 0) x = e - (y * y + z * z * z); ret = min(ret, x + y + z); } } cout << ret << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int x, y, z, e; while (cin >> e, e) { int ret = 999999999; for (int y = 0; y * y <= e; y++) { for (int z = 0; z * z * z <= e; z++) { if (e - (y * y + z * z * z) >= 0) x = e - (y * y + z * z * z); ret = min(ret, x + y + z); } } cout << ret << endl; } return 0; }
[["+", 8, 9, 0, 52, 15, 339, 51, 34, 0, 21], ["+", 8, 9, 0, 52, 15, 339, 51, 34, 12, 22]]
1
132
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // debug #define DUMP(x) cerr << #x << " = " << (x) << endl; #define DEBUG(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; const int MILLION = 1000000; int main() { int result = 1000000; int input; bool flag = true; while (cin >> input && input) { for (int i = 0; i * i * i < input; i++) { for (int j = 0; j * j < input - i * i * i; j++) { // if(i*i*i+j*j+k==input) int k = input - i * i * i - j * j; int temp = i + j + k; result = min(result, temp); } } cout << result << endl; result = 1000000; } return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // debug #define DUMP(x) cerr << #x << " = " << (x) << endl; #define DEBUG(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; const int MILLION = 1000000; int main() { int result = 1000000; int input; bool flag = true; while (cin >> input && input) { for (int i = 0; i * i * i <= input; i++) { for (int j = 0; j * j <= input - i * i * i; j++) { // if(i*i*i+j*j+k==input) int k = input - i * i * i - j * j; int temp = i + j + k; result = min(result, temp); } } cout << result << endl; result = 1000000; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
188
loop do e = gets.to_i break if e == 0 z, ans = 0, e while z**3 <= e y = Math.sqrt((e-z**3)).floor x = e - y**2 - z**3 ans = [ans, x+y+z].min z += 1 end puts m end
loop do e = gets.to_i break if e == 0 z, ans = 0, e while z**3 <= e y = Math.sqrt((e-z**3)).floor x = e - y**2 - z**3 ans = [ans, x+y+z].min z += 1 end puts ans end
[["-", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22], ["+", 196, 737, 8, 736, 0, 652, 3, 4, 0, 22]]
4
72
#!/usr/bin/env python # -*- coding: utf-8 -*- from math import sqrt while True: e = int(input()) if e == 0: break ans = 10**9 for z in range(e): if z > e: break y = int(sqrt(e-z**3)) x = e - y ** 2 - z ** 3 ans = min(ans,x+y+i) print(ans)
#!/usr/bin/env python # -*- coding: utf-8 -*- from math import sqrt while True: e = int(input()) if e == 0: break ans = 10**9 for z in range(e): if z**3 > e: break y = int(sqrt(e-z**3)) x = e - y ** 2 - z ** 3 ans = min(ans,x+y+z) print(ans)
[["+", 8, 196, 0, 57, 15, 666, 0, 657, 17, 578], ["+", 8, 196, 0, 57, 15, 666, 0, 657, 12, 612], ["-", 0, 662, 12, 652, 3, 4, 0, 657, 12, 22], ["+", 0, 662, 12, 652, 3, 4, 0, 657, 12, 22]]
5
82
require 'prime' require 'set' require 'tsort' include Math def max(a,b); a > b ? a : b end def min(a,b); a < b ? a : b end def swap(a,b); a, b = b, a end def gif; gets.to_i end def gff; gets.to_f end def gsf; gets.chomp end def gi; gets.split.map(&:to_i) end def gf; gets.split.map(&:to_f) end def gs; gets.chomp.split.map(&:to_s) end def gc; gets.chomp.split('') end def pr(num); num.prime_division end def digit(num); num.to_s.length end def array(s,ini=nil); Array.new(s){ini} end def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}} end def rep(num); num.times{|i|yield(i)} end def repl(st,en,n=1); st.step(en,n){|i|yield(i)} end N = 86402 ans = [] loop { n = gif break if n == 0 m = array N,0 rep n do s,e = gs stt = s.split(':').map(&:to_i) enn = e.split(':').map(&:to_i) l = stt[0]*60*60 + stt[1]*60 + stt[2] r = enn[0]*60*60 + enn[1]*60 + enn[2] m[l] += 1 m[r+1] -= 1 end repl 1, N-1 do |i| m[i] += m[i-1] end ans << m.max } puts ans
require 'prime' require 'set' require 'tsort' include Math def max(a,b); a > b ? a : b end def min(a,b); a < b ? a : b end def swap(a,b); a, b = b, a end def gif; gets.to_i end def gff; gets.to_f end def gsf; gets.chomp end def gi; gets.split.map(&:to_i) end def gf; gets.split.map(&:to_f) end def gs; gets.chomp.split.map(&:to_s) end def gc; gets.chomp.split('') end def pr(num); num.prime_division end def digit(num); num.to_s.length end def array(s,ini=nil); Array.new(s){ini} end def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}} end def rep(num); num.times{|i|yield(i)} end def repl(st,en,n=1); st.step(en,n){|i|yield(i)} end N = 86402 ans = [] loop { n = gif break if n == 0 m = array N,0 rep n do s,e = gs stt = s.split(':').map(&:to_i) enn = e.split(':').map(&:to_i) l = stt[0]*60*60 + stt[1]*60 + stt[2] r = enn[0]*60*60 + enn[1]*60 + enn[2] m[l] += 1 m[r] -= 1 end repl 1, N-1 do |i| m[i] += m[i-1] end ans << m.max } puts ans
[["-", 8, 736, 0, 755, 31, 742, 0, 738, 17, 72], ["-", 8, 736, 0, 755, 31, 742, 0, 738, 12, 612]]
4
410
while True: n = eval(input()) if not n: break time = [0]*86400 for i in range(n): s, t = input().split() ssec = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8]) tsec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8]) time[ssec] += 1 time[tsec] -= 1 ans = time[0] for i in range(43200-1): time[i+1] += time[i] ans = max(ans, time[i+1]) print(ans)
while True: n = eval(input()) if not n: break time = [0]*86400 for i in range(n): s, t = input().split() ssec = int(s[0:2])*3600 + int(s[3:5])*60 + int(s[6:8]) tsec = int(t[0:2])*3600 + int(t[3:5])*60 + int(t[6:8]) time[ssec] += 1 time[tsec] -= 1 ans = time[0] for i in range(86400-1): time[i+1] += time[i] ans = max(ans, time[i+1]) print(ans)
[["-", 0, 7, 12, 652, 3, 4, 0, 657, 31, 612], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 31, 612]]
5
168
#include <bits/stdc++.h> using namespace std; int w, h; vector<string> feeld; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 1}; int add, id; void rec(int x, int y) { if (feeld[y][x] == 'B') { id |= 1; return; } if (feeld[y][x] == 'W') { id |= 2; return; } feeld[y][x] = '-'; add++; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue; if (feeld[ny][nx] == '-') continue; rec(nx, ny); } } void solve() { int ansb = 0, answ = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (feeld[i][j] == '.') { add = 0; id = 0; rec(j, i); if (id == 1) ansb += add; if (id == 2) answ += add; } } } cout << ansb << " " << answ << endl; } int main() { while (1) { cin >> w >> h; if (w == 0 && h == 0) break; feeld.assign(h, ""); for (int i = 0; i < h; i++) cin >> feeld[i]; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int w, h; vector<string> feeld; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int add, id; void rec(int x, int y) { if (feeld[y][x] == 'B') { id |= 1; return; } if (feeld[y][x] == 'W') { id |= 2; return; } feeld[y][x] = '-'; add++; for (int i = 0; i < 4; i++) { int nx = x + dx[i], ny = y + dy[i]; if (!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue; if (feeld[ny][nx] == '-') continue; rec(nx, ny); } } void solve() { int ansb = 0, answ = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (feeld[i][j] == '.') { add = 0; id = 0; rec(j, i); if (id == 1) ansb += add; if (id == 2) answ += add; } } } cout << ansb << " " << answ << endl; } int main() { while (1) { cin >> w >> h; if (w == 0 && h == 0) break; feeld.assign(h, ""); for (int i = 0; i < h; i++) cin >> feeld[i]; solve(); } return 0; }
[["-", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13], ["+", 0, 30, 0, 43, 49, 50, 51, 83, 0, 13]]
1
383
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int w, h; bool visited[64][64]; vector<string> maze; bool check(int x, int y) { return x >= 0 && x < w && y >= 0 && y < h; } int dfs(int x, int y) { if (maze[y][x] == 'B') return 1; else if (maze[y][x] == 'W') return 2; int res = 0; for (int i = 0; i < 4; ++i) { int nx = x + dx[i]; int ny = y + dy[i]; if (!check(nx, ny) || visited[ny][nx]) continue; visited[ny][nx] = true; res |= dfs(nx, ny); } return res; } int main() { while (cin >> w >> h && (w || h)) { string a; maze.clear(); int cntB = 0, cntW = 0; for (int i = 0; i < h; ++i) { cin >> a; maze.push_back(a); } for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { if (maze[y][x] != '.') continue; memset(visited, 0, sizeof(visited)); visited[y][x] = true; int res = dfs(x, y); if (res == 2) cntB++; else if (res == 1) cntW++; } } cout << cntB << " " << cntW << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int w, h; bool visited[64][64]; vector<string> maze; bool check(int x, int y) { return x >= 0 && x < w && y >= 0 && y < h; } int dfs(int x, int y) { if (maze[y][x] == 'B') return 1; else if (maze[y][x] == 'W') return 2; int res = 0; for (int i = 0; i < 4; ++i) { int nx = x + dx[i]; int ny = y + dy[i]; if (!check(nx, ny) || visited[ny][nx]) continue; visited[ny][nx] = true; res |= dfs(nx, ny); } return res; } int main() { while (cin >> w >> h && (w || h)) { string a; maze.clear(); int cntB = 0, cntW = 0; for (int i = 0; i < h; ++i) { cin >> a; maze.push_back(a); } for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { if (maze[y][x] != '.') continue; memset(visited, 0, sizeof(visited)); visited[y][x] = true; int res = dfs(x, y); if (res == 1) cntB++; else if (res == 2) cntW++; } } cout << cntB << " " << cntW << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13]]
1
403
#include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) typedef long long ll; int a[50][50], b[2][50][50]; int w, h, k; int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}; bool isok(int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; } void dfs(int i, int j) { if (!a[i][j]) b[k - 1][i][j] = 1; REP(s, 4) { int ii = i + dx[s], jj = j + dy[s]; // cout << ii << " " << jj << " " << isok(ii,jj) << " " << b[k-1][ii][jj] << // " " << a[ii][jj] << endl; if (isok(ii, jj) && !b[k - 1][ii][jj] && !a[ii][jj]) { dfs(ii, jj); } } } int main(void) { while (cin >> w >> h && w) { REP(i, h) { REP(j, w) { char c; cin >> c; if (c == 'B') a[i][j] = 1; else if (c == 'W') a[i][j] = 2; else a[i][j] = 0; b[0][i][j] = 0; b[1][i][j] = 0; } } k = 1; REP(i, h) { REP(j, w) { if (a[i][j] == 1) dfs(i, j); } } cout << endl; k = 2; REP(i, h) { REP(j, w) { if (a[i][j] == 2) dfs(i, j); } } int bl = 0, wh = 0; REP(i, h) { REP(j, w) { bl += (b[0][i][j] && !b[1][i][j]); wh += (b[1][i][j] && !b[0][i][j]); } } cout << bl << " " << wh << endl; } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) typedef long long ll; int a[50][50], b[2][50][50]; int w, h, k; int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1}; bool isok(int i, int j) { return i >= 0 && i < h && j >= 0 && j < w; } void dfs(int i, int j) { if (!a[i][j]) b[k - 1][i][j] = 1; REP(s, 4) { int ii = i + dx[s], jj = j + dy[s]; if (isok(ii, jj) && !b[k - 1][ii][jj] && !a[ii][jj]) { dfs(ii, jj); } } } int main(void) { while (cin >> w >> h && w) { REP(i, h) { REP(j, w) { char c; cin >> c; if (c == 'B') a[i][j] = 1; else if (c == 'W') a[i][j] = 2; else a[i][j] = 0; b[0][i][j] = 0; b[1][i][j] = 0; } } k = 1; REP(i, h) { REP(j, w) { if (a[i][j] == 1) dfs(i, j); } } k = 2; REP(i, h) { REP(j, w) { if (a[i][j] == 2) dfs(i, j); } } int bl = 0, wh = 0; REP(i, h) { REP(j, w) { bl += (b[0][i][j] && !b[1][i][j]); wh += (b[1][i][j] && !b[0][i][j]); } } cout << bl << " " << wh << endl; } return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
547
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <string.h> #include <string> #include <vector> using namespace std; typedef complex<double> P; #define EPS (1e-10) #define EQ(a, b) (abs((a) - (b)) < EPS) #define EQV(a, b) (EQ(a.real(), b.real()) && EQ(a.imag(), b.imag())) #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, n) for (int i = a; i <= n; i++) //--------------------------------------------------------------------- vector<string> f(10); int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int w, h; void rec(int x, int y, char c) { rep(i, 4) { int nx = x + dx[i]; int ny = y + dy[i]; if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue; if (f[ny][nx] == '.') { f[ny][nx] = (c == 'B' ? 'b' : 'w'); rec(nx, ny, c); } else if ((f[ny][nx] == 'b' && c == 'W') || (f[ny][nx] == 'w' || c == 'B')) { f[ny][nx] = 'o'; rec(nx, ny, c); } } } int main() { while (cin >> w >> h, (w || h)) { f.clear(); rep(y, h) { string s; cin >> s; f.push_back(s); } rep(y, h) { rep(x, w) { if (f[y][x] == 'W' || f[y][x] == 'B') rec(x, y, f[y][x]); } } int blacks = 0, whites = 0; rep(y, h) { rep(x, w) { if (f[y][x] == 'b') blacks++; else if (f[y][x] == 'w') whites++; } } cout << blacks << " " << whites << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <queue> #include <string.h> #include <string> #include <vector> using namespace std; typedef complex<double> P; #define EPS (1e-10) #define EQ(a, b) (abs((a) - (b)) < EPS) #define EQV(a, b) (EQ(a.real(), b.real()) && EQ(a.imag(), b.imag())) #define rep(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, n) for (int i = a; i <= n; i++) //--------------------------------------------------------------------- vector<string> f(10); int DX[] = {1, 0, -1, 0}; int DY[] = {0, 1, 0, -1}; int w, h; void rec(int x, int y, char c) { rep(i, 4) { int nx = x + DX[i]; int ny = y + DY[i]; if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue; if (f[ny][nx] == '.') { f[ny][nx] = (c == 'B' ? 'b' : 'w'); rec(nx, ny, c); } else if ((f[ny][nx] == 'b' && c == 'W') || (f[ny][nx] == 'w' && c == 'B')) { ; f[ny][nx] = 'o'; rec(nx, ny, c); } } } int main() { while (cin >> w >> h, (w || h)) { f.clear(); rep(y, h) { string s; cin >> s; f.push_back(s); } rep(y, h) { rep(x, w) { if (f[y][x] == 'W' || f[y][x] == 'B') rec(x, y, f[y][x]); } } int blacks = 0, whites = 0; rep(y, h) { rep(x, w) { if (f[y][x] == 'b') blacks++; else if (f[y][x] == 'w') whites++; } } cout << blacks << " " << whites << endl; } return 0; }
[["-", 0, 30, 0, 43, 49, 50, 49, 80, 49, 22], ["+", 0, 30, 0, 43, 49, 50, 49, 80, 49, 22], ["-", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 69, 28, 22], ["-", 15, 339, 51, 16, 12, 23, 0, 16, 17, 106], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 98], ["+", 75, 76, 0, 57, 64, 9, 0, 1, 0, 35]]
1
474
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repb(i, a, b) for (int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define F first; #define S second; using namespace std; typedef pair<int, int> P; int h, w; int dy[4] = {1, -1, 0, 0}; int dx[4] = {0, 0, 1, -1}; int f[50][50]; bool contain(int y, int x) { return (0 <= y && y < h && 0 <= x && x < w); } signed main() { while (1) { cin >> w >> h; if (h + w == 0) break; vector<string> s(h); rep(i, 0, h) cin >> s[i]; rep(i, 0, h) rep(j, 0, w) f[i][j] = 0; int bc = 0, wc = 0; rep(i, 0, h) { rep(j, 0, w) { if (s[i][j] == '.') continue; queue<P> q; q.push(P(i, j)); int bt = (s[i][j] == 'W' ? 1 : 0); while (!q.empty()) { P p = q.front(); q.pop(); rep(k, 0, 4) { int ny = p.F + dy[k]; int nx = p.S + dx[k]; // cout << ny << " " << nx << endl; if (!contain(ny, nx)) continue; if (s[ny][nx] == '.') { // if(s[ny][nx] == 'W' || s[ny][nx] == 'B') continue; if (f[ny][nx] & (1 << bt)) continue; f[ny][nx] |= (1 << bt); // cout << p.first << " " << p.second << endl; q.push(P(ny, nx)); } } } } } rep(i, 0, h) { rep(j, 0, w) { // cout << f[i][j] << " "; if (f[i][j] == 1) bc++; if (f[i][j] == 2) wc++; } // cout << endl; } cout << bc << " " << wc << endl; } }
#include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < n; i++) #define repb(i, a, b) for (int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long #define F first; #define S second; using namespace std; typedef pair<int, int> P; int h, w; int dy[4] = {1, -1, 0, 0}; int dx[4] = {0, 0, 1, -1}; int f[50][50]; bool contain(int y, int x) { return (0 <= y && y < h && 0 <= x && x < w); } signed main() { while (1) { cin >> w >> h; if (h + w == 0) break; vector<string> s(h); rep(i, 0, h) cin >> s[i]; rep(i, 0, h) rep(j, 0, w) f[i][j] = 0; int bc = 0, wc = 0; rep(i, 0, h) { rep(j, 0, w) { if (s[i][j] == '.') continue; queue<P> q; q.push(P(i, j)); int bt = (s[i][j] == 'W' ? 1 : 0); while (!q.empty()) { P p = q.front(); q.pop(); rep(k, 0, 4) { int ny = p.first + dy[k]; int nx = p.second + dx[k]; // cout << ny << " " << nx << endl; if (!contain(ny, nx)) continue; if (s[ny][nx] == '.') { // if(s[ny][nx] == 'W' || s[ny][nx] == 'B') continue; if (f[ny][nx] & (1 << bt)) continue; f[ny][nx] |= (1 << bt); // cout << p.first << " " << p.second << endl; q.push(P(ny, nx)); } } } } } rep(i, 0, h) { rep(j, 0, w) { // cout << f[i][j] << " "; if (f[i][j] == 1) bc++; if (f[i][j] == 2) wc++; } // cout << endl; } cout << bc << " " << wc << endl; } }
[["-", 0, 43, 49, 50, 51, 16, 31, 118, 119, 120], ["+", 0, 43, 49, 50, 51, 16, 31, 118, 119, 120]]
1
500
#include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <vector> using namespace std; #define I(n, m) \ if (find(v.begin(), v.end(), make_pair(n, m)) == v.end()) \ ret |= D(n, m, v); typedef vector<pair<int, int>> V; char m[99][99]; int D(int i, int j, V &v) { if (m[i][j] == 'B') return 1; if (m[i][j] == 'W') return 2; if (m[i][j] == 'X') return 0; int ret = 0; v.push_back(make_pair(i, j)); I(i - i, j) I(i + 1, j) I(i, j - 1) I(i, j + 1) return ret; } main() { int w, h, i, j, r, s; for (; scanf("%d%d", &w, &h), w; printf("%d %d\n", r, s)) { for (memset(m, 'X', sizeof(m)), r = s = 0, i = 1; i <= h; i++) scanf("%s", m[i] + 1), m[i][w + 1] = 'X'; for (i = 1; i <= h; i++) for (j = 1; j <= w; j++) if (m[i][j] == '.') { V v; for (int x = D(i, j, v), k = 0; k < v.size(); k++) m[v[k].first][v[k].second] = x; } for (i = 1; i <= h; i++) for (j = 1; j <= w; j++) if (m[i][j] == 1) r++; else if (m[i][j] == 2) s++; } }
#include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <vector> using namespace std; #define I(n, m) \ if (find(v.begin(), v.end(), make_pair(n, m)) == v.end()) \ ret |= D(n, m, v); typedef vector<pair<int, int>> V; char m[99][99]; int D(int i, int j, V &v) { if (m[i][j] == 'B') return 1; if (m[i][j] == 'W') return 2; if (m[i][j] == 'X') return 0; int ret = 0; v.push_back(make_pair(i, j)); I(i - 1, j) I(i + 1, j) I(i, j - 1) I(i, j + 1) return ret; } main() { int w, h, i, j, r, s; for (; scanf("%d%d", &w, &h), w; printf("%d %d\n", r, s)) { for (memset(m, 'X', sizeof(m)), r = s = 0, i = 1; i <= h; i++) scanf("%s", m[i] + 1), m[i][w + 1] = 'X'; for (i = 1; i <= h; i++) for (j = 1; j <= w; j++) if (m[i][j] == '.') { V v; for (int x = D(i, j, v), k = 0; k < v.size(); k++) m[v[k].first][v[k].second] = x; } for (i = 1; i <= h; i++) for (j = 1; j <= w; j++) if (m[i][j] == 1) r++; else if (m[i][j] == 2) s++; } }
[["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
428
import sys sys.setrecursionlimit(3000) def dfs(r, c, n): board[r][c] = n drc = [(-1, 0), (0, 1), (1, 0), (0, -1)] for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < h and 0 <= nc < w and board[nr][nc] != n: if board[nr][nc] in 'WB': pile.append(board[nr][nc]) continue dfs(nr, nc, n) while True: w, h = map(int, input().split()) if w == 0 and h == 0: break board = [list(input()) for _ in range(h)] place = 0 piles = [] black, white = [], [] for r in range(h): for c in range(w): if board[r][c] == '.': pile = [] place += 1 dfs(r, c, place) piles.append(pile) for i, pile in enumerate(piles): if not pile: continue if all(p == 'B' for p in pile): black.append(i) elif all(p == 'W' for p in pile): white.append(i) ans_b, ans_w = 0, 0 for row in board: for c in row: if c in black: ans_b += 1 elif c in white: ans_w += 1 print(ans_b, ans_w)
import sys sys.setrecursionlimit(3000) def dfs(r, c, n): board[r][c] = n drc = [(-1, 0), (0, 1), (1, 0), (0, -1)] for dr, dc in drc: nr, nc = r + dr, c + dc if 0 <= nr < h and 0 <= nc < w and board[nr][nc] != n: if board[nr][nc] in 'WB': pile.append(board[nr][nc]) continue dfs(nr, nc, n) while True: w, h = map(int, input().split()) if w == 0 and h == 0: break board = [list(input()) for _ in range(h)] place = 0 piles = [] black, white = [], [] for r in range(h): for c in range(w): if board[r][c] == '.': pile = [] place += 1 dfs(r, c, place) piles.append(pile) for i, pile in enumerate(piles): if not pile: continue if all(p == 'B' for p in pile): black.append(i+1) elif all(p == 'W' for p in pile): white.append(i+1) ans_b, ans_w = 0, 0 for row in board: for c in row: if c in black: ans_b += 1 elif c in white: ans_w += 1 print(ans_b, ans_w)
[["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 12, 612]]
5
337
import sys from collections import Counter sys.set_coroutine_wrapper(2500) def paint(field, i, j, b, f, moves={(-1, 0), (1, 0), (0, 1), (0, -1)}): fij = field[i][j] if fij & f: return if fij & 4 and not fij & b: return field[i][j] |= b | f for di, dj in moves: ni = i + di nj = j + dj if nj < 0 or w <= nj or ni < 0 or h <= ni: continue paint(field, ni, nj, b, f) buf = [] chardict = {'.': 0, 'W': 5, 'B': 6} while True: w, h = map(int, input().split()) if w == 0: break field = [] init_w, init_b = 0, 0 for _ in range(h): line = input().strip() init_w += line.count('W') init_b += line.count('B') field.append([chardict[c] for c in line]) for i in range(h): for j in range(w): fij = field[i][j] if fij & 4 and not fij & 24: paint(field, i, j, fij & 3, (fij & 3) << 3) result = Counter(b & 3 for row in field for b in row) print(result[2] - init_b, result[1] - init_w)
import sys from collections import Counter sys.setrecursionlimit(2502) def paint(field, i, j, b, f, moves={(-1, 0), (1, 0), (0, 1), (0, -1)}): fij = field[i][j] if fij & f: return if fij & 4 and not fij & b: return field[i][j] |= b | f for di, dj in moves: ni = i + di nj = j + dj if nj < 0 or w <= nj or ni < 0 or h <= ni: continue paint(field, ni, nj, b, f) buf = [] chardict = {'.': 0, 'W': 5, 'B': 6} while True: w, h = map(int, input().split()) if w == 0: break field = [] init_w, init_b = 0, 0 for _ in range(h): line = input().strip() init_w += line.count('W') init_b += line.count('B') field.append([chardict[c] for c in line]) for i in range(h): for j in range(w): fij = field[i][j] if fij & 4 and not fij & 24: paint(field, i, j, fij & 3, (fij & 3) << 3) result = Counter(b & 3 for row in field for b in row) print(result[2] - init_b, result[1] - init_w)
[["-", 0, 656, 0, 1, 0, 652, 63, 319, 319, 22], ["+", 0, 656, 0, 1, 0, 652, 63, 319, 319, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 612], ["+", 0, 656, 0, 1, 0, 652, 3, 4, 0, 612]]
5
340
#include <iostream> #include <vector> #define MAX 100000 #include <bits/stdc++.h> using namespace std; int main() { int N, M; int w[1500], h[1500]; // int x[MAX]={0}; while ((cin >> N) && (cin >> M)) { int tt = 0; // w.resize(M); // h.resize(N); for (int i = 0; i < N; i++) { cin >> h[i]; } for (int j = 0; j < M; j++) { cin >> w[j]; } map<int, int> x, y; for (int i = 0; i < N; i++) { int p = 0; for (int j = i; j < N; j++) { p += h[j]; x[p]++; } } for (int i = 0; i < M; i++) { int p = 0; for (int j = i; j < M; j++) { p += w[j]; y[p]++; // tt+=x[p]; } } for (map<int, int>::iterator it = x.begin(); it != x.end(); it++) { tt += it->second * y[it->first]; } cout << tt << endl; } return 0; }
#include <iostream> #include <vector> #define MAX 100000 #include <bits/stdc++.h> using namespace std; int main() { int N, M; int w[1500], h[1500]; // int x[MAX]={0}; while ((cin >> N >> M) && N) { int tt = 0; // w.resize(M); // h.resize(N); for (int i = 0; i < N; i++) { cin >> h[i]; } for (int j = 0; j < M; j++) { cin >> w[j]; } map<int, int> x, y; for (int i = 0; i < N; i++) { int p = 0; for (int j = i; j < N; j++) { p += h[j]; x[p]++; } } for (int i = 0; i < M; i++) { int p = 0; for (int j = i; j < M; j++) { p += w[j]; y[p]++; // tt+=x[p]; } } for (map<int, int>::iterator it = x.begin(); it != x.end(); it++) { tt += it->second * y[it->first]; } cout << tt << endl; } return 0; }
[["-", 0, 52, 15, 339, 51, 16, 31, 23, 0, 25], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["-", 0, 52, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 15, 339, 51, 16, 12, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
1
269
#include <bits/stdc++.h> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<VVD> VVVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<VVS> VVVS; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<VVB> VVVB; typedef vector<PII> VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII; typedef vector<PLL> VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL; typedef unsigned int UI; typedef vector<UI> VUI; typedef vector<VUI> VVUI; #define fst first #define snd second // #define Y first // #define X second #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define RANGEBOX(x, y, maxX, maxY) \ (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) #define RANGE(x, l, r) ((l) <= (x) && (x) <= (r)) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define rrep(i, N) for (int i = N - 1; i >= 0; i--) #define REP(i, init, N) for (int i = (init); i < (int)(N); i++) #define RREP(i, N, last) for (int i = (init - 1); i >= last; i--) #define MAXUD(orig, target) orig = max(orig, target) #define MINUD(orig, target) orig = min(orig, target) #define DUMP(x) cerr << #x << " = " << (x) << endl template <typename T> inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; }; template <typename T> inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); }; template <typename T = int> inline void dump(vector<T> vs, bool ent = false) { rep(i, vs.size()) cout << vs[i] << (i + 1 == vs.size() ? '\n' : ' '); if (ent) cout << endl; } template <typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; } const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const double DINF = 0x3f3f3f3f; const int DX[] = {1, 0, -1, 0}; const int DY[] = {0, -1, 0, 1}; const double EPS = 1e-12; // const double PI = acos(-1.0); // lambda: [](T1 x)->T2{return y;} // simple lambda: [](T x){return x;} LL solve(int N, int M) { VI H(N), W(M); rep(i, N) cin >> H[i]; rep(i, M) cin >> W[i]; VI wsums; rep(i, M) { int w = 0; REP(j, i, M) { w += W[j]; wsums.PB(w); } } sort(ALL(wsums)); LL cnt = 0; rep(i, N) { int h = 0; REP(j, i, N) { h += H[i]; cnt += upper_bound(ALL(wsums), h) - lower_bound(ALL(wsums), h); } } return cnt; } int main(void) { int N, M; while (cin >> N >> M, N) cout << solve(N, M) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef ostringstream OSS; typedef istringstream ISS; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<VVLL> VVVLL; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<VVD> VVVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<VVS> VVVS; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<VVB> VVVB; typedef vector<PII> VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII; typedef vector<PLL> VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL; typedef unsigned int UI; typedef vector<UI> VUI; typedef vector<VUI> VVUI; #define fst first #define snd second // #define Y first // #define X second #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define RANGEBOX(x, y, maxX, maxY) \ (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY)) #define RANGE(x, l, r) ((l) <= (x) && (x) <= (r)) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define rrep(i, N) for (int i = N - 1; i >= 0; i--) #define REP(i, init, N) for (int i = (init); i < (int)(N); i++) #define RREP(i, N, last) for (int i = (init - 1); i >= last; i--) #define MAXUD(orig, target) orig = max(orig, target) #define MINUD(orig, target) orig = min(orig, target) #define DUMP(x) cerr << #x << " = " << (x) << endl template <typename T> inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; }; template <typename T> inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); }; template <typename T = int> inline void dump(vector<T> vs, bool ent = false) { rep(i, vs.size()) cout << vs[i] << (i + 1 == vs.size() ? '\n' : ' '); if (ent) cout << endl; } template <typename T = int> inline void dump(vector<vector<T>> vs, bool ent = false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; } const int INF = 0x3f3f3f3f; const LL INFL = 0x3f3f3f3f3f3f3f3fLL; const double DINF = 0x3f3f3f3f; const int DX[] = {1, 0, -1, 0}; const int DY[] = {0, -1, 0, 1}; const double EPS = 1e-12; // const double PI = acos(-1.0); // lambda: [](T1 x)->T2{return y;} // simple lambda: [](T x){return x;} LL solve(int N, int M) { VI H(N), W(M); rep(i, N) cin >> H[i]; rep(i, M) cin >> W[i]; VI wsums; rep(i, M) { int w = 0; REP(j, i, M) { w += W[j]; wsums.PB(w); } } sort(ALL(wsums)); LL cnt = 0; rep(i, N) { int h = 0; REP(j, i, N) { h += H[j]; cnt += upper_bound(ALL(wsums), h) - lower_bound(ALL(wsums), h); } } return cnt; } int main(void) { int N, M; while (cin >> N >> M, N) cout << solve(N, M) << endl; return 0; }
[["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
756
#include <algorithm> #include <iostream> using namespace std; int X[1500001] = {}, Y[1500001] = {}; int main() { int w, h; while (cin >> w >> h) { if (w == 0 && h == 0) break; int ans = 0; int x[1501] = {}, y[1501] = {}; for (int i = 0; i < h; i++) cin >> y[i]; for (int i = 0; i < w; i++) cin >> x[i]; for (int i = 0; i < 1500001; i++) { X[i] = 0; Y[i] = 0; } for (int i = 0; i < w; i++) { int sum = 0; for (int j = i; j < w; j++) { sum += x[j]; X[sum]++; } } for (int i = 0; i < h; i++) { int sum = 0; for (int j = i; j < h; j++) { sum += y[j]; Y[sum]++; } } for (int i = 0; i < 1500001; i++) { ans += X[i] * Y[i]; } cout << ans << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; int X[1500001] = {}, Y[1500001] = {}; int main() { int w, h; while (cin >> h >> w) { if (w == 0 && h == 0) break; int ans = 0; int x[1501] = {}, y[1501] = {}; for (int i = 0; i < h; i++) cin >> y[i]; for (int i = 0; i < w; i++) cin >> x[i]; for (int i = 0; i < 1500001; i++) { X[i] = 0; Y[i] = 0; } for (int i = 0; i < w; i++) { int sum = 0; for (int j = i; j < w; j++) { sum += x[j]; X[sum]++; } } for (int i = 0; i < h; i++) { int sum = 0; for (int j = i; j < h; j++) { sum += y[j]; Y[sum]++; } } for (int i = 0; i < 1500001; i++) { ans += X[i] * Y[i]; } cout << ans << endl; } return 0; }
[["-", 0, 52, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 52, 15, 339, 51, 16, 17, 152], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 152], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22]]
1
289
#include <iostream> using namespace std; int max(int a, int b) { if (a >= b) return a; else return b; } int main() { int n, m; while (cin >> n >> m) { if (n == 0 && m == 0) break; int *h, *w; int *hNum, *wNum; h = new int[n]; w = new int[m]; int maxHLength = 0; int maxWLength = 0; for (int i = 0; i < n; i++) { cin >> h[i]; maxHLength += h[i]; } for (int i = 0; i < m; i++) { cin >> w[i]; maxWLength += w[i]; } hNum = new int[maxHLength + 1]; wNum = new int[maxWLength + 1]; for (int i = 0; i <= maxHLength; i++) { hNum[i] = 0; } for (int i = 0; i <= maxWLength; i++) { wNum[i] = 0; } int maxLength = 0; for (int i = 0; i < n; i++) { int length = 0; for (int j = i; j < n; j++) { length += h[j]; hNum[length]++; } } for (int i = 0; i < m; i++) { int length = 0; for (int j = i; j < m; j++) { length += w[j]; wNum[length]++; } } int sum = 0; maxLength = max(maxHLength, maxWLength); for (int i = 0; i <= maxLength; i++) { sum += hNum[i] * wNum[i]; } cout << sum << endl; } return 0; }
#include <iostream> using namespace std; int max(int a, int b) { if (a >= b) return b; else return a; } int main() { int n, m; while (cin >> n >> m) { if (n == 0 && m == 0) break; int *h, *w; int *hNum, *wNum; h = new int[n]; w = new int[m]; int maxHLength = 0; int maxWLength = 0; for (int i = 0; i < n; i++) { cin >> h[i]; maxHLength += h[i]; } for (int i = 0; i < m; i++) { cin >> w[i]; maxWLength += w[i]; } hNum = new int[maxHLength + 1]; wNum = new int[maxWLength + 1]; for (int i = 0; i <= maxHLength; i++) { hNum[i] = 0; } for (int i = 0; i <= maxWLength; i++) { wNum[i] = 0; } int maxLength = 0; for (int i = 0; i < n; i++) { int length = 0; for (int j = i; j < n; j++) { length += h[j]; hNum[length]++; } } for (int i = 0; i < m; i++) { int length = 0; for (int j = i; j < m; j++) { length += w[j]; wNum[length]++; } } int sum = 0; maxLength = max(maxHLength, maxWLength); for (int i = 0; i <= maxLength; i++) { sum += hNum[i] * wNum[i]; } cout << sum << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 57, 64, 37, 0, 22], ["+", 0, 14, 8, 9, 0, 57, 64, 37, 0, 22], ["-", 8, 9, 0, 57, 75, 76, 0, 37, 0, 22], ["+", 8, 9, 0, 57, 75, 76, 0, 37, 0, 22]]
1
385
#include "bits/stdc++.h" using namespace std; int main() { int n, flag = 0; while (cin >> n, n) { if (flag) cout << endl; int m[4], c[4] = {10, 50, 100, 500}, k[4] = {}; for (int i = 0; i < 4; ++i) { cin >> m[i]; } for (int i = 0; i < 4; ++i) { n -= m[i] * c[i]; k[i] += m[i]; if (n <= 0) { k[3] -= (-n) / 500; n += ((-n) / 500) * 500; k[2] -= (-n) / 100; n += ((-n) / 100) * 100; k[1] -= (-n) / 50; n += ((-n) / 50) * 50; k[0] -= (-n) / 10; n += ((-n) / 10) * 10; break; } } for (int i = 0; i < 4; ++i) { if (k[i] <= 0) continue; printf("%d %d\n", c[i], k[i]); } flag++; } }
#include "bits/stdc++.h" using namespace std; int main() { int n, flag = 0; while (cin >> n, n) { if (flag) cout << endl; int m[4], c[4] = {10, 50, 100, 500}, k[4] = {}; for (int i = 0; i < 4; ++i) { cin >> m[i]; } for (int i = 0; i < 4; ++i) { n -= m[i] * c[i]; k[i] += m[i]; if (i == 3) { k[3] -= (-n) / 500; n += ((-n) / 500) * 500; k[2] -= (-n) / 100; n += ((-n) / 100) * 100; k[1] -= (-n) / 50; n += ((-n) / 50) * 50; k[0] -= (-n) / 10; n += ((-n) / 10) * 10; break; } } for (int i = 0; i < 4; ++i) { if (k[i] <= 0) continue; printf("%d %d\n", c[i], k[i]); } flag++; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
287
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using msi = map<string, int>; using mii = map<int, int>; using pii = pair<int, int>; using vlai = valarray<int>; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define range(i, s, n) for (int i = s; i < n; i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } constexpr int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int n; vlai p = {10, 50, 100, 500, 0}; while (cin >> n, n) { vlai c(0, 4); cin >> c[0] >> c[1] >> c[2] >> c[3]; int b = (p * c).sum() - n; rrep(i, 4) while (b >= p[i]) { b -= p[i]; c[i]--; } if (p[4]++) cout << endl; rep(i, 3) { if (c[i] > 0) cout << p[i] << " " << c[i] << endl; } } }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using msi = map<string, int>; using mii = map<int, int>; using pii = pair<int, int>; using vlai = valarray<int>; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define range(i, s, n) for (int i = s; i < n; i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } constexpr int lcm(int a, int b) { return a * b / gcd(a, b); } int main() { int n; vlai p = {10, 50, 100, 500, 0}; while (cin >> n, n) { vlai c(0, 4); cin >> c[0] >> c[1] >> c[2] >> c[3]; int b = (p * c).sum() - n; rrep(i, 4) while (b >= p[i]) { b -= p[i]; c[i]--; } if (p[4]++) cout << endl; rep(i, 4) { if (c[i] > 0) cout << p[i] << " " << c[i] << endl; } } }
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
320
#include <algorithm> #include <ciso646> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; const ll INF = (ll)1000000007 * 1000000007; const double PI = 3.14159265358979; const double E = 2.718281828459045; const double root2 = sqrt(2); typedef pair<int, int> P; typedef unsigned int ui; int main() { int x; bool g = true; while (cin >> x) { if (x == 0) break; if (!g) cout << endl; g = false; int coin[4]; for (int i = 0; i < 4; i++) cin >> coin[i]; int re = 10 * coin[0] + 50 * coin[1] + 100 * coin[2] + 500 * coin[3] - x; int recoin[4] = {}; recoin[3] = re / 500; re %= 500; recoin[2] = re / 100; re %= 100; recoin[1] = re / 50; re %= 50; recoin[0] = re / 10; int out[4]; for (int i = 0; i < 4; i++) out[i] = coin[i] - recoin[i]; if (out[0] > 0) cout << 10 << " " << coin[0] << endl; if (out[1] > 0) cout << 50 << " " << coin[1] << endl; if (out[2] > 0) cout << 100 << " " << coin[2] << endl; if (out[3] > 0) cout << 500 << " " << coin[3] << endl; } return 0; }
#include <algorithm> #include <ciso646> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; const ll MOD = 1000000007; const ll INF = (ll)1000000007 * 1000000007; const double PI = 3.14159265358979; const double E = 2.718281828459045; const double root2 = sqrt(2); typedef pair<int, int> P; typedef unsigned int ui; int main() { int x; bool g = true; while (cin >> x) { if (x == 0) break; if (!g) cout << endl; g = false; int coin[4]; for (int i = 0; i < 4; i++) cin >> coin[i]; int re = 10 * coin[0] + 50 * coin[1] + 100 * coin[2] + 500 * coin[3] - x; int recoin[4] = {}; recoin[3] = re / 500; re %= 500; recoin[2] = re / 100; re %= 100; recoin[1] = re / 50; re %= 50; recoin[0] = re / 10; int out[4]; for (int i = 0; i < 4; i++) out[i] = coin[i] - recoin[i]; if (out[0] > 0) cout << 10 << " " << out[0] << endl; if (out[1] > 0) cout << 50 << " " << out[1] << endl; if (out[2] > 0) cout << 100 << " " << out[2] << endl; if (out[3] > 0) cout << 500 << " " << out[3] << endl; } return 0; }
[["-", 64, 1, 0, 16, 31, 16, 12, 69, 28, 22], ["+", 64, 1, 0, 16, 31, 16, 12, 69, 28, 22]]
1
379
#include <cstdio> #include <iostream> using namespace std; enum coins { ten = 0, fifty, hundred, five_hundred, coin_max }; const int kcoin[coin_max] = {10, 50, 100, 500}; int M; int min_nums; int ans_nums[coin_max]; int nums[coin_max]; int tans_nums[coin_max]; int minimumExchange(int m, int *nums) { int t = 0; int ans = 0; for (int i = five_hundred; i >= ten; --i) { t = m / kcoin[i]; m -= kcoin[i] * t; nums[i] = t; ans += t; } return ans; } void solve() { for (int a = 0; a <= nums[ten]; ++a) { for (int b = 0; b <= nums[fifty]; ++b) { for (int c = 0; c <= nums[hundred]; ++c) { for (int d = 0; d <= nums[five_hundred]; ++d) { int m = a * kcoin[ten] + b * kcoin[fifty] + c * kcoin[hundred] + d * kcoin[five_hundred]; if (m >= M) { int t = 0; int exchanges[coin_max]; nums[0] -= a; nums[1] -= b; nums[2] -= c; nums[3] -= d; tans_nums[0] += a; tans_nums[1] += b; tans_nums[2] += c; tans_nums[3] += d; minimumExchange(m - M, exchanges); for (int i = 0; i < coin_max; ++i) { t += nums[i] + exchanges[i]; } if (min_nums > t) { min_nums = t; for (int i = 0; i < coin_max; ++i) { ans_nums[i] = tans_nums[i]; } } tans_nums[0] -= a; tans_nums[1] -= b; tans_nums[2] -= c; tans_nums[3] -= d; nums[0] += a; nums[1] += b; nums[2] += c; nums[3] += d; } } } } } } int main() { bool bFirstDataSet = true; while (true) { scanf("%d", &M); if (M == 0) break; for (int i = 0; i < coin_max; ++i) { tans_nums[i] = ans_nums[i] = nums[i] = 0; } for (int i = 0; i < coin_max; ++i) { scanf("%d", nums + i); } if (!bFirstDataSet) { printf("\n"); bFirstDataSet = false; } min_nums = 100; solve(); for (int i = 0; i < 4; ++i) { if (ans_nums[i]) { printf("%d %d\n", kcoin[i], ans_nums[i]); } } } return 0; }
#include <cstdio> #include <iostream> using namespace std; enum coins { ten = 0, fifty, hundred, five_hundred, coin_max }; const int kcoin[coin_max] = {10, 50, 100, 500}; int M; int min_nums; int ans_nums[coin_max]; int nums[coin_max]; int tans_nums[coin_max]; int minimumExchange(int m, int *nums) { int t = 0; int ans = 0; for (int i = five_hundred; i >= ten; --i) { t = m / kcoin[i]; m -= kcoin[i] * t; nums[i] = t; ans += t; } return ans; } void solve() { for (int a = 0; a <= nums[ten]; ++a) { for (int b = 0; b <= nums[fifty]; ++b) { for (int c = 0; c <= nums[hundred]; ++c) { for (int d = 0; d <= nums[five_hundred]; ++d) { int m = a * kcoin[ten] + b * kcoin[fifty] + c * kcoin[hundred] + d * kcoin[five_hundred]; if (m >= M) { int t = 0; int exchanges[coin_max]; nums[0] -= a; nums[1] -= b; nums[2] -= c; nums[3] -= d; tans_nums[0] += a; tans_nums[1] += b; tans_nums[2] += c; tans_nums[3] += d; minimumExchange(m - M, exchanges); for (int i = 0; i < coin_max; ++i) { t += nums[i] + exchanges[i]; } if (min_nums > t) { min_nums = t; for (int i = 0; i < coin_max; ++i) { ans_nums[i] = tans_nums[i]; } } tans_nums[0] -= a; tans_nums[1] -= b; tans_nums[2] -= c; tans_nums[3] -= d; nums[0] += a; nums[1] += b; nums[2] += c; nums[3] += d; } } } } } } int main() { bool bFirstDataSet = true; while (true) { scanf("%d", &M); if (M == 0) break; for (int i = 0; i < coin_max; ++i) { tans_nums[i] = ans_nums[i] = nums[i] = 0; } for (int i = 0; i < coin_max; ++i) { scanf("%d", nums + i); } if (!bFirstDataSet) { printf("\n"); } bFirstDataSet = false; min_nums = 100; solve(); for (int i = 0; i < 4; ++i) { if (ans_nums[i]) { printf("%d %d\n", kcoin[i], ans_nums[i]); } } } return 0; }
[["+", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 0, 52, 8, 9, 0, 57, 64, 9, 0, 46]]
1
621
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <map> #include <memory> #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; static const double EPS = 1e-5; #define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) int main(void) { int m, c[4], r[4]; int d[4] = {10, 50, 100, 500}; bool firstline = true; while (cin >> m, m) { if (!firstline) cout << endl; else firstline = false; int sum = 0; REP(i, 4) { cin >> c[i]; sum += d[i] * c[i]; r[i] = 0; } sum -= m; REP(i, 4) { r[i] = sum / d[3 - i]; sum %= d[3 - i]; } REP(i, 4) { int x = c[i] - r[i]; if (x > 0) { cout << d[i] << " " << x << endl; } } } return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <functional> #include <iostream> #include <map> #include <memory> #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; static const double EPS = 1e-5; #define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) int main(void) { int m, c[4], r[4]; int d[4] = {10, 50, 100, 500}; bool firstline = true; while (cin >> m, m) { if (!firstline) cout << endl; else firstline = false; int sum = 0; REP(i, 4) { cin >> c[i]; sum += d[i] * c[i]; r[i] = 0; } sum -= m; REP(i, 4) { r[3 - i] = sum / d[3 - i]; sum %= d[3 - i]; } REP(i, 4) { int x = c[i] - r[i]; if (x > 0) { cout << d[i] << " " << x << endl; } } } return 0; }
[["+", 0, 11, 31, 69, 341, 342, 0, 16, 31, 13], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 17, 33]]
1
272
#include <stdio.h> int main() { int a; int k = 0; while (scanf("%d", &a), a) { if (k) printf("\n"); k = 1; int b, c, d, e; scanf("%d%d%d%d", &b, &c, &d, &e); int rb = 0, rc = 0, rd = 0, re = 0, min = 999999; for (int i = 0; i <= b; i++) for (int j = 0; j <= c; j++) for (int k = 0; k <= d; k++) for (int l = 0; l <= e; l++) { int val = i * 10 + j * 50 + k * 100 + l * 500 - a; if (val < 0) continue; if (i && val % 50 / 10) continue; if (j && val % 100 / 50) continue; if (k && val % 500 / 100) continue; if (l && val % 1000 / 500) continue; if (min > b - i + c - j + d - k + e - l + val % 1000 / 500 + val % 500 / 100 + val % 100 / 50 + val % 50 / 10) { min = b - i + c - j + d - k + e - l + val % 1000 / 500 + val % 500 / 100 + val % 100 / 50 + val % 50 / 10; rb = i; rc = j; rd = k; re = l; } } if (rb) printf("10 %d\n", rb); if (rc) printf("50 %d\n", rc); if (rd) printf("100 %d\n", rd); if (re) printf("500 %d\n", re); } }
#include <stdio.h> int main() { int a; int k = 0; while (scanf("%d", &a), a) { if (k) printf("\n"); k = 1; int b, c, d, e; scanf("%d%d%d%d", &b, &c, &d, &e); int rb = 0, rc = 0, rd = 0, re = 0, min = 999999; for (int i = 0; i <= b; i++) for (int j = 0; j <= c; j++) for (int k = 0; k <= d; k++) for (int l = 0; l <= e; l++) { int val = i * 10 + j * 50 + k * 100 + l * 500 - a; if (val < 0) continue; if (i && val % 50 / 10) continue; if (j && val % 100 / 50) continue; if (k && val % 500 / 100) continue; if (l && val / 500) continue; if (min > b - i + c - j + d - k + e - l + val / 500 + val % 500 / 100 + val % 100 / 50 + val % 50 / 10) { min = b - i + c - j + d - k + e - l + val / 500 + val % 500 / 100 + val % 100 / 50 + val % 50 / 10; rb = i; rc = j; rd = k; re = l; } } if (rb) printf("10 %d\n", rb); if (rc) printf("50 %d\n", rc); if (rd) printf("100 %d\n", rd); if (re) printf("500 %d\n", re); } }
[["-", 15, 339, 51, 16, 12, 16, 31, 16, 17, 109], ["-", 15, 339, 51, 16, 12, 16, 31, 16, 12, 13], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 17, 109], ["-", 31, 16, 31, 16, 12, 16, 31, 16, 12, 13]]
1
391
#include <cstring> #include <iostream> #define rep(i, n) for (int i = 0; i < n; i++) int main() { int m, c[4], p[4], r[4]; int d[4] = {10, 50, 100, 500}; bool firstline = true; while (std::cin >> m, (m)) { if (!firstline) { std::cout << std::endl; } firstline = false; rep(i, 4) { std::cin >> c[i]; } int min = 20 * 20 * 20 * 20, minc[4]; memset(minc, 0, sizeof(minc)); for (p[0] = 0; p[0] <= c[0]; p[0]++) { for (p[1] = 0; p[1] <= c[1]; p[1]++) { for (p[2] = 0; p[2] <= c[2]; p[2]++) { for (p[3] = 0; p[3] <= c[3]; p[3]++) { memset(r, 0, sizeof(r)); int sum = 0; rep(i, 4) { sum += d[i] * p[i]; } if (sum < m) { continue; } sum -= m; rep(i, 4) { while (sum >= d[3 - i]) { sum -= d[i]; r[i]++; } } int remain = 0; rep(i, 4) { remain += c[i] - p[i] + r[i]; } if (remain < min) { min = remain; rep(i, 4) { minc[i] = p[i]; } } } } } } rep(i, 4) { if (minc[i] > 0) { std::cout << d[i] << ' ' << minc[i] << std::endl; } } } return 0; }
#include <cstring> #include <iostream> #define rep(i, n) for (int i = 0; i < n; i++) int main() { int m, c[4], p[4], r[4]; int d[4] = {10, 50, 100, 500}; bool firstline = true; while (std::cin >> m, (m)) { if (!firstline) { std::cout << std::endl; } firstline = false; rep(i, 4) { std::cin >> c[i]; } int min = 20 * 20 * 20 * 20, minc[4]; memset(minc, 0, sizeof(minc)); for (p[0] = 0; p[0] <= c[0]; p[0]++) { for (p[1] = 0; p[1] <= c[1]; p[1]++) { for (p[2] = 0; p[2] <= c[2]; p[2]++) { for (p[3] = 0; p[3] <= c[3]; p[3]++) { memset(r, 0, sizeof(r)); int sum = 0; rep(i, 4) { sum += d[i] * p[i]; } if (sum < m) { continue; } sum -= m; rep(i, 4) { while (sum >= d[3 - i]) { sum -= d[3 - i]; r[3 - i]++; } } int remain = 0; rep(i, 4) { remain += c[i] - p[i] + r[i]; } if (remain < min) { min = remain; rep(i, 4) { minc[i] = p[i]; } } } } } } rep(i, 4) { if (minc[i] > 0) { std::cout << d[i] << ' ' << minc[i] << std::endl; } } } return 0; }
[["+", 0, 11, 12, 69, 341, 342, 0, 16, 31, 13], ["+", 0, 11, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 31, 13], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33]]
1
438
#include <iostream> using namespace std; #define INF 1 << 28 int p; int n[4]; int v[4] = {10, 50, 100, 500}; int count_coin(int a, int b, int c, int d) { int sum = v[0] * a + v[1] * b + v[2] * c + v[3] * d - p; if (sum < 0) return INF; int change = 0; for (int i = 3; i >= 0; i--) { int t = sum / v[i]; sum -= t * v[i]; change += t; if (sum == 0) break; } return change + a + b + c + d; } int main() { bool first = true; while (cin >> p, p != 0) { for (int i = 0; i < 4; i++) cin >> n[i]; int min_coin = INF; int a, b, c, d; for (int i = 0; i <= n[0]; i++) for (int j = 0; j <= n[1]; j++) for (int k = 0; k <= n[2]; k++) for (int l = 0; l <= n[3]; l++) { int t = count_coin(i, j, k, l); if (min_coin > t) { min_coin = t; a = i, b = j, c = k, d = l; } } if (!first) cout << endl; else first = false; if (a != 0) cout << v[0] << ' ' << a << endl; if (b != 0) cout << v[1] << ' ' << b << endl; if (c != 0) cout << v[2] << ' ' << c << endl; if (d != 0) cout << v[3] << ' ' << d << endl; } return 0; }
#include <iostream> using namespace std; #define INF 1 << 28 int p; int n[4]; int v[4] = {10, 50, 100, 500}; int count_coin(int a, int b, int c, int d) { int sum = v[0] * a + v[1] * b + v[2] * c + v[3] * d - p; if (sum < 0) return INF; int change = 0; for (int i = 3; i >= 0; i--) { int t = sum / v[i]; sum -= t * v[i]; change += t; if (sum == 0) break; } return change - (a + b + c + d); } int main() { bool first = true; while (cin >> p, p != 0) { for (int i = 0; i < 4; i++) cin >> n[i]; int min_coin = INF; int a, b, c, d; for (int i = 0; i <= n[0]; i++) for (int j = 0; j <= n[1]; j++) for (int k = 0; k <= n[2]; k++) for (int l = 0; l <= n[3]; l++) { int t = count_coin(i, j, k, l); if (min_coin > t) { min_coin = t; a = i, b = j, c = k, d = l; } } if (!first) cout << endl; else first = false; if (a != 0) cout << v[0] << ' ' << a << endl; if (b != 0) cout << v[1] << ' ' << b << endl; if (c != 0) cout << v[2] << ' ' << c << endl; if (d != 0) cout << v[3] << ' ' << d << endl; } return 0; }
[["-", 0, 16, 31, 16, 31, 16, 31, 16, 17, 72], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 17, 33], ["+", 8, 9, 0, 37, 0, 16, 12, 23, 0, 24], ["+", 8, 9, 0, 37, 0, 16, 12, 23, 0, 25]]
1
427
#include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <vector> #define all(n) n.begin(), n.end() #define REP(i, s, n) for (int i = s; i < n; i++) #define rep(i, n) REP(i, 0, n) #define insert(a, b, c, d) PP(P(a, b), P(c, d)) #define F first #define S second #define pb push_back #define INF (1 << 27) #define EPS 1e-10 #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; typedef pair<int, int> P; typedef pair<P, P> PP; typedef unsigned long long ull; typedef long long ll; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int V[4] = {10, 50, 100, 500}; int C[4], I[4], R[4], A[4]; int pay; const int T[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX}; void ret(int sum) { int A = sum; for (int i = 3; i >= 0; i--) { int t = min(A / V[i], C[i]); A -= t * V[i]; R[i] = t; } } int main() { bool first = false; while (cin >> pay && pay) { rep(i, 4) cin >> C[i]; int pre = INT_MAX; A[0] = A[1] = A[2] = A[3] = -1; rep(i, C[0] + 1) { // 10 rep(j, C[1] + 1) { // 50 rep(k, C[2] + 1) { // 100 rep(l, C[3] + 1) { // 500 int sum = i * 10 + j * 50 + k * 100 + l * 500; if (sum < pay) continue; I[0] = i, I[1] = j, I[2] = k, I[3] = l; ret(sum - pay); int total = 0; bool ok = true; rep(m, 4) { total += C[m] - I[m] + R[m]; // if(I[m] != R[m])ok = false; assert(C[m] >= I[m]); } if (total < pre) { rep(m, 4) A[m] = I[m]; pre = total; } } } } } if (first) cout << endl; first = true; rep(i, 4) { if (A[i] == 0) continue; cout << V[i] << " " << A[i] << endl; } } return 0; } /* Way to check the time of processing speed clock_t start,end; start = clock(); ------function------- end = clock(); cout << setiosflags(ios::fixed) << setprecision(10) << (double)(end-start)/CLOCKS_PER_SEC << endl; */
#include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <vector> #define all(n) n.begin(), n.end() #define REP(i, s, n) for (int i = s; i < n; i++) #define rep(i, n) REP(i, 0, n) #define insert(a, b, c, d) PP(P(a, b), P(c, d)) #define F first #define S second #define pb push_back #define INF (1 << 27) #define EPS 1e-10 #define equals(a, b) (fabs((a) - (b)) < EPS) using namespace std; typedef pair<int, int> P; typedef pair<P, P> PP; typedef unsigned long long ull; typedef long long ll; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const int V[4] = {10, 50, 100, 500}; int C[4], I[4], R[4], A[4]; int pay; const int T[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX}; void ret(int sum) { int A = sum; for (int i = 3; i >= 0; i--) { int t = min(A / V[i], T[i]); A -= t * V[i]; R[i] = t; } } int main() { bool first = false; while (cin >> pay && pay) { rep(i, 4) cin >> C[i]; int pre = INT_MAX; A[0] = A[1] = A[2] = A[3] = -1; rep(i, C[0] + 1) { // 10 rep(j, C[1] + 1) { // 50 rep(k, C[2] + 1) { // 100 rep(l, C[3] + 1) { // 500 int sum = i * 10 + j * 50 + k * 100 + l * 500; if (sum < pay) continue; I[0] = i, I[1] = j, I[2] = k, I[3] = l; ret(sum - pay); int total = 0; bool ok = true; rep(m, 4) { total += C[m] - I[m] + R[m]; // if(I[m] != R[m])ok = false; assert(C[m] >= I[m]); } if (total < pre) { rep(m, 4) A[m] = I[m]; pre = total; } } } } } if (first) cout << endl; first = true; rep(i, 4) { if (A[i] == 0) continue; cout << V[i] << " " << A[i] << endl; } } return 0; } /* Way to check the time of processing speed clock_t start,end; start = clock(); ------function------- end = clock(); cout << setiosflags(ios::fixed) << setprecision(10) << (double)(end-start)/CLOCKS_PER_SEC << endl; */
[["-", 49, 50, 51, 2, 3, 4, 0, 69, 28, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 69, 28, 22]]
1
594
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; int n; int c[] = {10, 50, 100, 500}; int k[4]; int a[4]; int main(void) { bool f = false; while (cin >> n) { if (!n) break; if (f) cout << endl; f = true; memset(a, 0, sizeof(a)); int sum = 0; for (int i = 0; i < 4; i++) { cin >> k[i]; sum += k[i]; } sum -= n; for (int i = 3; i >= 0; i--) { a[i] += sum / c[i]; sum %= c[i]; } for (int i = 0; i < 4; i++) { if (max(0, k[i] - a[i])) { cout << c[i] << " " << max(0, k[i] - a[i]) << endl; } } } }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; int n; int c[] = {10, 50, 100, 500}; int k[4]; int a[4]; int main(void) { bool f = false; while (cin >> n) { if (!n) break; if (f) cout << endl; f = true; memset(a, 0, sizeof(a)); int sum = 0; for (int i = 0; i < 4; i++) { cin >> k[i]; sum += k[i] * c[i]; } sum -= n; for (int i = 3; i >= 0; i--) { a[i] += sum / c[i]; sum %= c[i]; } for (int i = 0; i < 4; i++) { if (max(0, k[i] - a[i])) { cout << c[i] << " " << max(0, k[i] - a[i]) << endl; } } } }
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 69, 28, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 73]]
1
232
#include <iostream> #include <vector> using namespace std; int main() { int n; int TYPE[5] = {10, 50, 100, 500, 1000}; vector<int> vec; int firstFlag = 0; while (true) { cin >> n; if (n == 0) break; if (firstFlag == 0) { firstFlag = 1; } else { cout << endl; } vec = vector<int>(4, 0); for (int i = 0; i < 4; i++) { cin >> vec[i]; } int ans = 0; int flag = -1; for (int i = 0; i < 4; i++) { ans = ans + TYPE[i] * vec[i]; /*if(ans < n){ }else{ flag = i; break; }*/ } int otu = ans - n; int oturi[5]; int keepO = 0; for (int i = 4; i >= 0; i--) { keepO = otu % TYPE[i]; oturi[i] = otu / TYPE[i]; otu = keepO; } for (int i = 0; i < 4; i++) { if (oturi[i] < vec[i]) { cout << TYPE[i] << " " << vec[i] - oturi[i] << endl; } } /* for(int i = flag +1 ;i < 4-1;i++){ if(i == 3 || i == 1){ if(vec[i] >= 2){ cout <<TYPE[i] << " " << (vec[i]/2)*2 << endl; } } else{ if(vec[i] >= 5){ cout <<TYPE[i] << " " << (vec[i]/5)*5 << endl; } } } */ /*int keep10 = (n%50)/10;// if(keep10 <= vec[0]){ vec[0] = vec[0]-keep10; }else{ vec[1] = vec[1] - 1; } int keep50 = (n%100)/10 - keep10; if(keep50 <= vec[1]){ vec[1] = vec[1]-keep50; }else{ vec[2] = vec[2] - 1; } int keep100 = (n%500) */ } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n; int TYPE[5] = {10, 50, 100, 500, 1000}; vector<int> vec; int firstFlag = 0; while (true) { cin >> n; if (n == 0) break; if (firstFlag == 0) { firstFlag = 1; } else { cout << endl; } vec = vector<int>(4, 0); for (int i = 0; i < 4; i++) { cin >> vec[i]; } int ans = 0; int flag = -1; for (int i = 0; i < 4; i++) { ans = ans + TYPE[i] * vec[i]; /*if(ans < n){ }else{ flag = i; break; }*/ } int otu = ans - n; int oturi[5]; int keepO = 0; for (int i = 3; i >= 0; i--) { keepO = otu % TYPE[i]; oturi[i] = otu / TYPE[i]; otu = keepO; } for (int i = 0; i < 4; i++) { if (oturi[i] < vec[i]) { cout << TYPE[i] << " " << vec[i] - oturi[i] << endl; } } /* for(int i = flag +1 ;i < 4-1;i++){ if(i == 3 || i == 1){ if(vec[i] >= 2){ cout <<TYPE[i] << " " << (vec[i]/2)*2 << endl; } } else{ if(vec[i] >= 5){ cout <<TYPE[i] << " " << (vec[i]/5)*5 << endl; } } } */ /*int keep10 = (n%50)/10;// if(keep10 <= vec[0]){ vec[0] = vec[0]-keep10; }else{ vec[1] = vec[1] - 1; } int keep50 = (n%100)/10 - keep10; if(keep50 <= vec[1]){ vec[1] = vec[1]-keep50; }else{ vec[2] = vec[2] - 1; } int keep100 = (n%500) */ } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
276
def f(x) k = 0 k += x / 500 x %= 500 k += x / 100 x %= 100 k += x / 50 x %= 50 k + x / 10 end ans = [] loop { price = gets.to_i break if price == 0 a, b, c, d = gets.split.map &:to_i min = Float::INFINITY min_by = nil (0..a).each{|x| (0..b).each{|y| (0..c).each{|z| (0..d).each{|w| total = 10*x+50*y+100*z+500*w next if total < price net = f(total - price) - (x + y + z + w) if net < min min = net min_by = [x, y, z, w] end } } } } tmp = %w(10 50 100 500) ans << (0..3).map{|i| min_by[i] > 0 ? "#{tmp[i]} #{min_by[i]}\n" : nil}.compact } puts ans.join("\n")
def f(x) k = 0 k += x / 500 x %= 500 k += x / 100 x %= 100 k += x / 50 x %= 50 k + x / 10 end ans = [] loop { price = gets.to_i break if price == 0 a, b, c, d = gets.split.map &:to_i min = Float::INFINITY min_by = nil (0..a).each{|x| (0..b).each{|y| (0..c).each{|z| (0..d).each{|w| total = 10*x+50*y+100*z+500*w next if total < price net = f(total - price) - (x + y + z + w) if net < min min = net min_by = [x, y, z, w] end } } } } tmp = %w(10 50 100 500) ans << (0..3).map{|i| min_by[i] > 0 ? "#{tmp[i]} #{min_by[i]}\n" : nil}.compact.join } puts ans.join("\n")
[["+", 196, 196, 8, 734, 0, 738, 12, 652, 17, 131], ["+", 196, 196, 8, 734, 0, 738, 12, 652, 735, 22]]
4
243
#include <cmath> #include <iostream> #include <string> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define EPS 1e-8 int n, hx, hy, dx, dy; int x[30], y[30]; bool flag; void dfs(int unvisit, int cx, int cy, double t) { if (flag) return; if (unvisit == 0) flag = true; else { REP(i, n) { if (!((unvisit >> i) & 1)) continue; if (hypot(dx - x[i], dy - y[i]) < t + hypot(cx - x[i], cy - y[i])) return; } REP(i, n) { if (!((unvisit >> i) & 1)) continue; dfs((unvisit & ~(1 << i)), x[i], y[i], t + hypot(cx - x[i], cy - y[i])); } } } string solve() { flag = false; dfs((1 << n) - 1, hx, hy, 0); return (flag) ? "YES" : "NO"; } int main() { while (cin >> n >> hx >> hy >> dx >> dy, n) { REP(i, n) { cin >> x[i] >> y[i]; } cout << solve() << endl; } return 0; }
#include <cmath> #include <iostream> #include <string> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define EPS 1e-8 int n, hx, hy, dx, dy; int x[30], y[30]; bool flag; void dfs(int unvisit, int cx, int cy, double t) { if (flag) return; if (unvisit == 0) flag = true; else { REP(i, n) { if (!((unvisit >> i) & 1)) continue; if (hypot(dx - x[i], dy - y[i]) <= t + hypot(cx - x[i], cy - y[i])) return; } REP(i, n) { if (!((unvisit >> i) & 1)) continue; dfs((unvisit & ~(1 << i)), x[i], y[i], t + hypot(cx - x[i], cy - y[i])); } } } string solve() { flag = false; dfs((1 << n) - 1, hx, hy, 0); return (flag) ? "YES" : "NO"; } int main() { while (cin >> n >> hx >> hy >> dx >> dy, n) { REP(i, n) { cin >> x[i] >> y[i]; } cout << solve() << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
306
loop { n, hx, hy, dx, dy = gets.split.map &:to_i break if n == 0 points = [[hx, hy]] + (1..n).map { gets.split.map &:to_i } dist = (0..n).map{|i| (0..n).map{|j| x1, y1 = points[i] x2, y2 = points[j] sqrt((x1-x2)**2 + (y1-y2)**2) } } deadline = points.map{|x, y| sqrt((x - dx)**2 + (y - dy)**2) } stack = [[0, 0] + (1..n).to_a] success = false until stack.empty? t, i, *unreached = stack.pop if unreached == [] success = true break end next if unreached.any?{|j| t + dist[i][j] >= deadline[j]} unreached.each{|j| stack << [t + dist[i][j], j, *(unreached - [j])] } end puts success ? 'YES' : 'NO' }
include Math loop { n, hx, hy, dx, dy = gets.split.map &:to_i break if n == 0 points = [[hx, hy]] + (1..n).map { gets.split.map &:to_i } dist = (0..n).map{|i| (0..n).map{|j| x1, y1 = points[i] x2, y2 = points[j] sqrt((x1-x2)**2 + (y1-y2)**2) } } deadline = points.map{|x, y| sqrt((x - dx)**2 + (y - dy)**2) } stack = [[0, 0] + (1..n).to_a] success = false until stack.empty? t, i, *unreached = stack.pop if unreached == [] success = true break end next if unreached.any?{|j| t + dist[i][j] >= deadline[j]} unreached.each{|j| stack << [t + dist[i][j], j, *(unreached - [j])] } end puts success ? 'YES' : 'NO' }
[["+", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 36, 36, 0, 493, 0, 652, 3, 4, 0, 743]]
4
252
#include <cstdio> #pragma warning(disable : 4996) #define MAX_N 1500 #define MAX_D 1000 #define MAX_R MAX_N *MAX_D int N, M, H[MAX_N], W[MAX_N]; int dp[2][MAX_R + 1]; int main() { while (true) { scanf("%d", &N); scanf("%d", &M); if (N == 0 && M == 0) { break; } for (int i = 0; i < N; i++) { scanf("%d", &H[i]); } for (int i = 0; i < M; i++) { scanf("%d", &W[i]); } for (int i = 0; i <= N; i++) { int dist = 0; for (int j = i; j < N; j++) { dist += H[j]; dp[0][dist] += 1; } } for (int i = 0; i <= M; i++) { int dist = 0; for (int j = i; j < M; j++) { dist += H[j]; dp[1][dist] += 1; } } int count = 0; for (int i = 0; i <= MAX_R; i++) { count += dp[0][i] * dp[1][i]; dp[0][i] = 0; dp[1][i] = 0; } printf("%d\n", count); } return 0; }
#include <cstdio> #pragma warning(disable : 4996) #define MAX_N 1500 #define MAX_D 1000 #define MAX_R MAX_N *MAX_D int N, M, H[MAX_N], W[MAX_N]; int dp[2][MAX_R + 1]; int main() { while (true) { scanf("%d", &N); scanf("%d", &M); if (N == 0 && M == 0) { break; } for (int i = 0; i < N; i++) { scanf("%d", &H[i]); } for (int i = 0; i < M; i++) { scanf("%d", &W[i]); } for (int i = 0; i <= N; i++) { int dist = 0; for (int j = i; j < N; j++) { dist += H[j]; dp[0][dist] += 1; } } for (int i = 0; i <= M; i++) { int dist = 0; for (int j = i; j < M; j++) { dist += W[j]; dp[1][dist] += 1; } } int count = 0; for (int i = 0; i <= MAX_R; i++) { count += dp[0][i] * dp[1][i]; dp[0][i] = 0; dp[1][i] = 0; } printf("%d\n", count); } return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22]]
1
323
#include <iostream> using namespace std; const int MAX_N = 1500, MAX_M = 1500, MAX_W = 1000; int roadV[MAX_N], roadH[MAX_M]; int widthV[MAX_N * MAX_W + 1]; int widthH[MAX_M * MAX_W + 1]; inline int min(int a, int b) { if (a < b) return a; return b; } int main() { ios_base::sync_with_stdio(0); int n, m, i, j, sumV, sumH, cnt, minWidth; while (1) { cin >> n >> m; if (n == 0 && m == 0) break; sumV = 0; sumH = 0; for (i = 0; i < n; i++) { cin >> roadV[i]; sumV += roadV[i]; } for (i = 0; i < m; i++) { cin >> roadH[i]; sumH += roadH[i]; } minWidth = min(sumV, sumH); for (i = 1; i <= minWidth; i++) { widthV[i] = 0; } for (i = 1; i <= minWidth; i++) { widthH[i] = 0; } for (i = 0; i < n; i++) { sumV = 0; for (j = i; j < n; j++) { sumV += roadV[j]; widthV[sumV]++; } } for (i = 0; i < m; i++) { sumH = 0; for (j = i; j < m; j++) { sumH += roadH[j]; widthV[sumH]++; } } cnt = 0; for (i = 1; i <= minWidth; i++) { cnt += widthV[i] * widthH[i]; } cout << cnt << endl; } return 0; }
#include <iostream> using namespace std; const int MAX_N = 1500, MAX_M = 1500, MAX_W = 1000; int roadV[MAX_N], roadH[MAX_M]; int widthV[MAX_N * MAX_W + 1]; int widthH[MAX_M * MAX_W + 1]; inline int min(int a, int b) { if (a < b) return a; return b; } int main() { ios_base::sync_with_stdio(0); int n, m, i, j, sumV, sumH, cnt, minWidth; while (1) { cin >> n >> m; if (n == 0 && m == 0) break; sumV = 0; sumH = 0; for (i = 0; i < n; i++) { cin >> roadV[i]; sumV += roadV[i]; } for (i = 0; i < m; i++) { cin >> roadH[i]; sumH += roadH[i]; } minWidth = min(sumV, sumH); for (i = 1; i <= minWidth; i++) { widthV[i] = 0; } for (i = 1; i <= minWidth; i++) { widthH[i] = 0; } for (i = 0; i < n; i++) { sumV = 0; for (j = i; j < n; j++) { sumV += roadV[j]; widthV[sumV]++; } } for (i = 0; i < m; i++) { sumH = 0; for (j = i; j < m; j++) { sumH += roadH[j]; widthH[sumH]++; } } cnt = 0; for (i = 1; i <= minWidth; i++) { cnt += widthV[i] * widthH[i]; } cout << cnt << endl; } return 0; }
[["-", 8, 9, 0, 1, 0, 27, 28, 69, 28, 22], ["+", 8, 9, 0, 1, 0, 27, 28, 69, 28, 22]]
1
382
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string.h> #include <vector> #define pb push_back using namespace std; int n, m; int mitih[1500000], mitiw[1500000]; int main(void) { int i, j, x, tmp, res; vector<int> h, w; while (scanf("%d %d", &n, &m), n | m) { h.clear(), w.clear(); for (i = 1; i <= n; i++) { cin >> x; h.pb(x); } for (i = 1; i <= m; i++) { cin >> x; w.pb(x); } // set<int> st1,st2; vector<int> s1, s2; for (i = 0; i < n; i++) { tmp = 0; for (j = i; j < n; j++) { tmp += h[j]; s1.pb(tmp); } } for (i = 0; i < m; i++) { tmp = 0; for (j = i; j < m; j++) { tmp += w[j]; s2.pb(tmp); } } h.clear(); w.clear(); // for(auto itr=st1.begin();itr!=st1.end();++itr) h.pb(*itr); // for(auto itr=st2.begin();itr!=st2.end();++itr) w.pb(*itr); i = j = res = 0; sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); tmp = max(s1[s1.size() - 1], s2[s2.size() - 1]); /* for(i=0;i<s1.size();i++) printf("%d ",s1[i]); printf("\n"); for(i=0;i<s2.size();i++) printf("%d ",s2[i]); printf("\n"); */ // printf("5\n"); map<int, int> mp1, mp2; // tmp=max(s1.size(),s2.size()); for (i = 0; i < tmp; i++) { mp1[i] = mp2[i] = 0; } for (i = 0; i < s1.size(); i++) mp1[s1[i]]++; for (i = 0; i < s1.size(); i++) mp2[s2[i]]++; for (i = 0; i <= tmp; i++) { // printf("%d : %d %d\n",i,mp1[i],mp2[i]); res += mp1[i] * mp2[i]; } printf("%d\n", res); } return 0; } /* int solveninaritakattananika(){ int i,j,k,n; int res=0; n=max(h[h.size()-1],w[w.size()-1]); for(k=1;k<=n;k++){ for(i=0;i<h[h.size()-1]-k+1;i++){ for(j=0;j<w[w.size()-1]-k+1;j++){ if(mitih[i]==1&&mitih[i+k]==1&&mitiw[j]==1&&mitiw[j+k]==1) res++; //printf("%d %d %d %d : ",mitih[i],mitiw[j+k],mitih[i+k],mitiw[j]); //printf("(%d,%d) k=%d res=%d\n",i,j,k,res); } } } return res; } */
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string.h> #include <vector> #define pb push_back using namespace std; int n, m; int mitih[1500000], mitiw[1500000]; int main(void) { int i, j, x, tmp, res; vector<int> h, w; while (scanf("%d %d", &n, &m), n | m) { h.clear(), w.clear(); for (i = 1; i <= n; i++) { cin >> x; h.pb(x); } for (i = 1; i <= m; i++) { cin >> x; w.pb(x); } // set<int> st1,st2; vector<int> s1, s2; for (i = 0; i < n; i++) { tmp = 0; for (j = i; j < n; j++) { tmp += h[j]; s1.pb(tmp); } } for (i = 0; i < m; i++) { tmp = 0; for (j = i; j < m; j++) { tmp += w[j]; s2.pb(tmp); } } h.clear(); w.clear(); // for(auto itr=st1.begin();itr!=st1.end();++itr) h.pb(*itr); // for(auto itr=st2.begin();itr!=st2.end();++itr) w.pb(*itr); i = j = res = 0; sort(s1.begin(), s1.end()); sort(s2.begin(), s2.end()); tmp = max(s1[s1.size() - 1], s2[s2.size() - 1]); /* for(i=0;i<s1.size();i++) printf("%d ",s1[i]); printf("\n"); for(i=0;i<s2.size();i++) printf("%d ",s2[i]); printf("\n"); */ // printf("5\n"); map<int, int> mp1, mp2; // tmp=max(s1.size(),s2.size()); for (i = 0; i < tmp; i++) { mp1[i] = mp2[i] = 0; } for (i = 0; i < s1.size(); i++) mp1[s1[i]]++; for (i = 0; i < s2.size(); i++) mp2[s2[i]]++; for (i = 0; i <= tmp; i++) { // printf("%d : %d %d\n",i,mp1[i],mp2[i]); res += mp1[i] * mp2[i]; } printf("%d\n", res); } return 0; } /* int solveninaritakattananika(){ int i,j,k,n; int res=0; n=max(h[h.size()-1],w[w.size()-1]); for(k=1;k<=n;k++){ for(i=0;i<h[h.size()-1]-k+1;i++){ for(j=0;j<w[w.size()-1]-k+1;j++){ if(mitih[i]==1&&mitih[i+k]==1&&mitiw[j]==1&&mitiw[j+k]==1) res++; //printf("%d %d %d %d : ",mitih[i],mitiw[j+k],mitih[i+k],mitiw[j]); //printf("(%d,%d) k=%d res=%d\n",i,j,k,res); } } } return res; } */
[["-", 0, 7, 15, 16, 12, 2, 63, 118, 28, 22], ["+", 0, 7, 15, 16, 12, 2, 63, 118, 28, 22]]
1
466
#include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { while (1) { int n, m; cin >> n >> m; if (n == 0) break; vector<int> h(n), w(m); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < m; i++) { cin >> w[i]; } unordered_map<int, int> width, height; for (int i = 0; i < n; i++) { int subtotal = 0; for (int j = i; j < m; j++) { subtotal += h[j]; if (height.count(subtotal) == 0) { height[subtotal] = 1; } else { height[subtotal]++; } } } for (int i = 0; i < m; i++) { int subtotal = 0; for (int j = i; j < n; j++) { subtotal += w[j]; if (width.count(subtotal) == 0) { width[subtotal] = 1; } else { width[subtotal]++; } } } int ans = 0; for (auto pair : width) { auto itr = height.find(pair.first); if (itr != height.end()) { ans += itr->second * pair.second; } } cout << ans << endl; } return 0; }
#include <iostream> #include <unordered_map> #include <vector> using namespace std; int main() { while (1) { int n, m; cin >> n >> m; if (n == 0) break; vector<int> h(n), w(m); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < m; i++) { cin >> w[i]; } unordered_map<int, int> width, height; for (int i = 0; i < n; i++) { int subtotal = 0; for (int j = i; j < n; j++) { subtotal += h[j]; if (height.count(subtotal) == 0) { height[subtotal] = 1; } else { height[subtotal]++; } } } for (int i = 0; i < m; i++) { int subtotal = 0; for (int j = i; j < m; j++) { subtotal += w[j]; if (width.count(subtotal) == 0) { width[subtotal] = 1; } else { width[subtotal]++; } } } int ans = 0; for (auto pair : width) { auto itr = height.find(pair.first); if (itr != height.end()) { ans += itr->second * pair.second; } } cout << ans << endl; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 22]]
1
314
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fi first #define se second #define fcout(n) cout << fixed << setprecision((n)) #define cinl(str) getline(cin, (str)) using namespace std; bool value(int y, int x, int R, int C) { return 0 <= y && y < R && 0 <= x && x < C; } typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<vi> vvi; double pie = acos(-1); int INF = 1000000007; int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0, 1, 0}; long long hsum2[1500005], wsum2[1500005]; int main() { int n, m; long long ans = 0; int h[1505], w[1505]; long long hsum1[1505], wsum1[1505]; while (true) { cin >> n >> m; if (n + m == 0) return 0; else { for (int i = 0; i < 1505; i++) { hsum1[i] = 0; wsum1[i] = 0; } fill(hsum2, hsum2 + 1500005, 0); fill(wsum2, wsum2 + 1500005, 0); for (int i = 0; i < n; i++) { cin >> h[i]; if (i == 0) { hsum1[i] += h[i]; } else { hsum1[i] = hsum1[i - 1] + h[i]; } } for (int i = 0; i < m; i++) { cin >> w[i]; if (i == 0) { wsum1[i] += w[i]; } else { wsum1[i] += wsum1[i - 1] + w[i]; } } for (int i = 0; i < n; i++) { hsum2[hsum1[i]]++; for (int j = i + 1; j < n; j++) { hsum2[hsum1[j] - hsum1[i]]++; } } for (int i = 0; i < m; i++) { wsum2[wsum1[i]]++; for (int j = 0; j < m; j++) { wsum2[wsum1[j] - wsum1[i]]++; } } } for (int i = 0; i < 1500005; i++) { ans += hsum2[i] * wsum2[i]; } cout << ans << endl; ans = 0; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fi first #define se second #define fcout(n) cout << fixed << setprecision((n)) #define cinl(str) getline(cin, (str)) using namespace std; bool value(int y, int x, int R, int C) { return 0 <= y && y < R && 0 <= x && x < C; } typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<vi> vvi; double pie = acos(-1); int INF = 1000000007; int dx[4] = {0, -1, 0, 1}; int dy[4] = {-1, 0, 1, 0}; long long hsum2[1500005], wsum2[1500005]; int main() { int n, m; long long ans = 0; int h[1505], w[1505]; long long hsum1[1505], wsum1[1505]; while (true) { cin >> n >> m; if (n + m == 0) return 0; else { for (int i = 0; i < 1505; i++) { hsum1[i] = 0; wsum1[i] = 0; } fill(hsum2, hsum2 + 1500005, 0); fill(wsum2, wsum2 + 1500005, 0); for (int i = 0; i < n; i++) { cin >> h[i]; if (i == 0) { hsum1[i] += h[i]; } else { hsum1[i] = hsum1[i - 1] + h[i]; } } for (int i = 0; i < m; i++) { cin >> w[i]; if (i == 0) { wsum1[i] += w[i]; } else { wsum1[i] += wsum1[i - 1] + w[i]; } } for (int i = 0; i < n; i++) { hsum2[hsum1[i]]++; for (int j = i + 1; j < n; j++) { hsum2[hsum1[j] - hsum1[i]]++; } } for (int i = 0; i < m; i++) { wsum2[wsum1[i]]++; for (int j = i + 1; j < m; j++) { wsum2[wsum1[j] - wsum1[i]]++; } } } for (int i = 0; i < 1500005; i++) { ans += hsum2[i] * wsum2[i]; } cout << ans << endl; ans = 0; } }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 31, 22], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 7, 10, 43, 49, 50, 51, 16, 12, 13]]
1
565
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, m, n) for (int i = m; i < (n); i++) const int MAX = 1500 * 1000 + 1; int N, M; int H[2020]; int W[2020]; ll A[MAX]; ll B[MAX]; bool solve() { cin >> N >> M; REP(i, N) cin >> H[i]; REP(i, M) cin >> W[i]; if (N == 0) return false; REP(i, N) { int tmp = 0; REP2(j, i, N) { tmp += H[i]; A[tmp] += 1; } } REP(i, M) { int tmp = 0; REP2(j, i, M) { tmp += W[i]; B[tmp] += 1; } } ll ans = 0; REP(i, MAX) { ans += A[i] * B[i]; } cout << ans << endl; memset(A, 0, sizeof(A)); memset(B, 0, sizeof(B)); return true; } int main() { while (solve()) ; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, m, n) for (int i = m; i < (n); i++) const int MAX = 1500 * 1000 + 1; int N, M; int H[2020]; int W[2020]; ll A[MAX]; ll B[MAX]; bool solve() { cin >> N >> M; REP(i, N) cin >> H[i]; REP(i, M) cin >> W[i]; if (N == 0) return false; REP(i, N) { int tmp = 0; REP2(j, i, N) { tmp += H[j]; A[tmp] += 1; } } REP(i, M) { int tmp = 0; REP2(j, i, M) { tmp += W[j]; B[tmp] += 1; } } ll ans = 0; REP(i, MAX) { ans += A[i] * B[i]; } cout << ans << endl; memset(A, 0, sizeof(A)); memset(B, 0, sizeof(B)); return true; } int main() { while (solve()) ; }
[["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
262
// clang-format off #include <bits/stdc++.h> using namespace std; #define int long long #define main signed main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979; template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } constexpr bool odd(const int n) { return n & 1; } constexpr bool even(const int n) { return ~n & 1; } template<typename T = int> T in() { T x; cin >> x; return x; } template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; } template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; } template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; } template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); } template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } // clang-format on main { while (true) { int n = in(); int m = in(); if (n == 0 && m == 0) break; auto h = in(vector<int>(n)); auto w = in(vector<int>(m)); vector<int> l1(n * 1000 + 1), l2(n * 1000 + 1); rep(i, n) { int s = 0; loop(j, i, n) { s += h[j]; l1[s]++; } } rep(i, m) { int s = 0; loop(j, i, m) { s += w[j]; l2[s]++; } } int c = 0; for (int i = 1; i <= n * 1000; i++) c += l1[i] * l2[i]; cout << c << endl; } }
// clang-format off #include <bits/stdc++.h> using namespace std; #define int long long #define main signed main() #define loop(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) loop(i, 0, n) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define prec(n) fixed << setprecision(n) constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979; template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; } template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; } constexpr bool odd(const int n) { return n & 1; } constexpr bool even(const int n) { return ~n & 1; } template<typename T = int> T in() { T x; cin >> x; return x; } template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; } template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; } template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; } template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; } template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); } template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } // clang-format on main { while (true) { int n = in(); int m = in(); if (n == 0 && m == 0) break; auto h = in(vector<int>(n)); auto w = in(vector<int>(m)); vector<int> l1(1500 * 1000 + 1), l2(1500 * 1000 + 1); rep(i, n) { int s = 0; loop(j, i, n) { s += h[j]; l1[s]++; } } rep(i, m) { int s = 0; loop(j, i, m) { s += w[j]; l2[s]++; } } int c = 0; for (int i = 1; i <= n * 1000; i++) c += l1[i] * l2[i]; cout << c << endl; } }
[["-", 0, 2, 3, 4, 0, 16, 31, 16, 31, 22], ["+", 0, 2, 3, 4, 0, 16, 31, 16, 31, 13]]
1
771
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define out(S) cout << (S) << endl; #define ShowAll(collection) \ for (auto i : collection) { \ out(i); \ } #define beginend(v) v.begin(), v.end() using pii = pair<int, int>; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vvi = vector<vi>; using vvc = vector<vector<char>>; using ti3 = tuple<int, int, int>; template <typename T> void removeAt(vector<T> &v, int index) { v.erase(v.begin() + index); } int solve(int n, int m) { vi w(m + 1, 0), h(n + 1, 0); rep(i, n) cin >> h[i + 1]; rep(i, m) cin >> w[i + 1]; rep(i, n) h[i + 1] += h[i]; rep(i, m) w[i + 1] += w[i]; map<int, int> hm, wm; rep(i, n + 1) for (int j = i + 1; j <= n; ++j) hm[h[j] - h[i]]++; rep(i, m + 1) for (int j = i + 1; j <= m; ++j) wm[w[j] - w[i]]++; int ans = 0; rep(i, min(h[n], w[n]) + 1) ans += (hm[i] * wm[i]); return ans; } int main() { int N, M; while (cin >> N >> M, N | M) { out(solve(N, M)); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define out(S) cout << (S) << endl; #define ShowAll(collection) \ for (auto i : collection) { \ out(i); \ } #define beginend(v) v.begin(), v.end() using pii = pair<int, int>; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vvi = vector<vi>; using vvc = vector<vector<char>>; using ti3 = tuple<int, int, int>; template <typename T> void removeAt(vector<T> &v, int index) { v.erase(v.begin() + index); } int solve(int n, int m) { vi w(m + 1, 0), h(n + 1, 0); rep(i, n) cin >> h[i + 1]; rep(i, m) cin >> w[i + 1]; rep(i, n) h[i + 1] += h[i]; rep(i, m) w[i + 1] += w[i]; map<int, int> hm, wm; rep(i, n + 1) for (int j = i + 1; j <= n; ++j) hm[h[j] - h[i]]++; rep(i, m + 1) for (int j = i + 1; j <= m; ++j) wm[w[j] - w[i]]++; int ans = 0; rep(i, max(h[n], w[n]) + 1) ans += (hm[i] * wm[i]); return ans; } int main() { int N, M; while (cin >> N >> M, N | M) { out(solve(N, M)); } }
[["-", 31, 2, 3, 4, 0, 16, 31, 2, 63, 22], ["+", 31, 2, 3, 4, 0, 16, 31, 2, 63, 22]]
1
390
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9 + 7; void solve(int n, int m) { vector<int> h(n), w(m); rep(i, n) cin >> h[i]; rep(i, m) cin >> w[i]; vector<int> hh, ww; rep(i, n) { int len = 0; for (int j = i; j < n; j++) { len += h[i]; hh.push_back(len); } } rep(i, m) { int len = 0; for (int j = i; j < m; j++) { len += w[i]; ww.push_back(len); } } map<int, int> mh, mw; rep(i, (int)hh.size()) { if (mh.find(hh[i]) == mh.end()) { mh.emplace(hh[i], 0); } mh[hh[i]]++; } rep(i, (int)ww.size()) { if (mw.find(ww[i]) == mw.end()) { mw.emplace(ww[i], 0); } mw[ww[i]]++; } int ans = 0; vector<P> H, W; for (auto it = mh.begin(); it != mh.end(); it++) { int x = (*it).first; int c = (*it).second; if (mw.find(x) != mw.end()) { ans += c * mw[x]; } } cout << ans << endl; } signed main() { while (true) { int n, m; cin >> n >> m; if (n == 0 && m == 0) { break; } solve(n, m); } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9 + 7; void solve(int n, int m) { vector<int> h(n), w(m); rep(i, n) cin >> h[i]; rep(i, m) cin >> w[i]; vector<int> hh, ww; rep(i, n) { int len = 0; for (int j = i; j < n; j++) { len += h[j]; hh.push_back(len); } } rep(i, m) { int len = 0; for (int j = i; j < m; j++) { len += w[j]; ww.push_back(len); } } map<int, int> mh, mw; rep(i, (int)hh.size()) { if (mh.find(hh[i]) == mh.end()) { mh.emplace(hh[i], 0); } mh[hh[i]]++; } rep(i, (int)ww.size()) { if (mw.find(ww[i]) == mw.end()) { mw.emplace(ww[i], 0); } mw[ww[i]]++; } int ans = 0; vector<P> H, W; for (auto it = mh.begin(); it != mh.end(); it++) { int x = (*it).first; int c = (*it).second; if (mw.find(x) != mw.end()) { ans += c * mw[x]; } } cout << ans << endl; } signed main() { while (true) { int n, m; cin >> n >> m; if (n == 0 && m == 0) { break; } solve(n, m); } return 0; }
[["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
463
#include <iostream> #include <string.h> using namespace std; int num[2000 * 1500]; int main() { int N, M; while (cin >> N >> M && N != 0) { memset(num, 0, sizeof(num)); int h[1501], w[1501]; h[0] = w[0] = 0; for (int i = 1; i <= N; i++) { cin >> h[i]; h[i] += h[i - 1]; } for (int i = 1; i <= M; i++) { cin >> w[i]; w[i] += w[i - 1]; } for (int i = 0; i <= N; i++) { for (int j = i + 1; j <= N; j++) { num[h[i] - h[j]]++; } } int ans = 0; for (int i = 0; i <= M; i++) { for (int j = i + 1; j <= M; j++) { ans += num[w[i] - w[j]]; } } cout << ans << endl; } return 0; }
#include <iostream> #include <string.h> using namespace std; int num[2000 * 1500]; int main() { int N, M; while (cin >> N >> M && N != 0) { memset(num, 0, sizeof(num)); int h[1501], w[1501]; h[0] = w[0] = 0; for (int i = 1; i <= N; i++) { cin >> h[i]; h[i] += h[i - 1]; } for (int i = 1; i <= M; i++) { cin >> w[i]; w[i] += w[i - 1]; } for (int i = 0; i <= N; i++) { for (int j = i + 1; j <= N; j++) { num[h[j] - h[i]]++; } } int ans = 0; for (int i = 0; i <= M; i++) { for (int j = i + 1; j <= M; j++) { ans += num[w[j] - w[i]]; } } cout << ans << endl; } return 0; }
[["-", 341, 342, 0, 16, 31, 69, 341, 342, 0, 22], ["+", 341, 342, 0, 16, 31, 69, 341, 342, 0, 22], ["-", 341, 342, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 341, 342, 0, 16, 12, 69, 341, 342, 0, 22]]
1
257
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { for (int N, M; cin >> N >> M, N + M == 0;) { vector<int> H(N + 1); vector<int> W(M + 1); H[0] = W[0] = 0; for (int i = 1; i <= N; i++) { int k; cin >> k; H[i] = H[i - 1] + k; } for (int i = 1; i <= M; i++) { int k; cin >> k; W[i] = W[i - 1] + k; } vector<int> A; for (int i = 0; i < (int)H.size(); i++) { for (int j = i + 1; j < (int)H.size(); j++) { A.push_back(H[j] - H[i]); } } vector<int> B; for (int i = 0; i < (int)W.size(); i++) { for (int j = i + 1; j < (int)W.size(); j++) { B.push_back(W[j] - W[i]); } } sort(A.begin(), A.end()); sort(B.begin(), B.end()); int res = 0; for (int i = 0; i < (int)A.size(); i++) { res += upper_bound(B.begin(), B.end(), A[i]) - lower_bound(B.begin(), B.end(), A[i]); } cout << res << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { for (int N, M; cin >> N >> M, N + M != 0;) { vector<int> H(N + 1); vector<int> W(M + 1); H[0] = W[0] = 0; for (int i = 1; i <= N; i++) { int k; cin >> k; H[i] = H[i - 1] + k; } for (int i = 1; i <= M; i++) { int k; cin >> k; W[i] = W[i - 1] + k; } vector<int> A; for (int i = 0; i < (int)H.size(); i++) { for (int j = i + 1; j < (int)H.size(); j++) { A.push_back(H[j] - H[i]); } } vector<int> B; for (int i = 0; i < (int)W.size(); i++) { for (int j = i + 1; j < (int)W.size(); j++) { B.push_back(W[j] - W[i]); } } sort(A.begin(), A.end()); sort(B.begin(), B.end()); int res = 0; for (int i = 0; i < (int)A.size(); i++) { res += upper_bound(B.begin(), B.end(), A[i]) - lower_bound(B.begin(), B.end(), A[i]); } cout << res << endl; } }
[["-", 8, 9, 0, 7, 15, 34, 12, 16, 17, 60], ["+", 8, 9, 0, 7, 15, 34, 12, 16, 17, 79]]
1
390
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(int argc, char const *argv[]) { while (1) { int n, m; cin >> n >> m; vector<int> hmap, wmap; vector<int> map; if (!n || !m) return 0; int o = 0; for (int i = 0; i < n; i++) { int h; cin >> h; hmap.push_back(o); o += h; } hmap.push_back(o); o = 0; for (int i = 0; i < m; i++) { int w; cin >> w; wmap.push_back(o); o += w; } wmap.push_back(o); int cnt = 0; map.resize(max(hmap[n], wmap[m])); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n + 1; j++) { map[hmap[j] - hmap[i]] += 1; } } for (int i = 0; i < m; i++) { for (int j = i + 1; j < m + 1; j++) { int it = wmap[j] - wmap[i]; if (map[it] > 0) cnt += map[it]; } } cout << cnt << endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(int argc, char const *argv[]) { while (1) { int n, m; cin >> n >> m; vector<int> hmap, wmap; vector<int> map; if (!n || !m) return 0; int o = 0; for (int i = 0; i < n; i++) { int h; cin >> h; hmap.push_back(o); o += h; } hmap.push_back(o); o = 0; for (int i = 0; i < m; i++) { int w; cin >> w; wmap.push_back(o); o += w; } wmap.push_back(o); int cnt = 0; map.resize(max(hmap[n], wmap[m]) + 10); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n + 1; j++) { map[hmap[j] - hmap[i]]++; } } for (int i = 0; i < m; i++) { for (int j = i + 1; j < m + 1; j++) { int it = wmap[j] - wmap[i]; if (map[it] > 0) cnt += map[it]; } } cout << cnt << endl; } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 29]]
1
306
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, j) FOR(i, 0, j) #define mp std::make_pair const int INF = 1 << 24; const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; typedef unsigned long long ull; typedef std::pair<int, int> P; int N, M, H[1501], W[1501]; std::map<int, int> sH; int main() { while (std::cin >> N >> M, N) { H[0] = 0; FOR(i, 1, N + 1) { std::cin >> H[i]; H[i] += H[i - 1]; } REP(i, N + 1) { FOR(j, i + 1, N + 1) { sH[H[j] - H[i]]++; } } W[0] = 0; FOR(i, 1, M + 1) { std::cin >> W[i]; W[i] += W[i - 1]; } int res = 0; REP(i, M + 1) { FOR(j, i + 1, M + 1) { res += sH[W[j] - W[i]]; } } std::cout << res << std::endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, j) FOR(i, 0, j) #define mp std::make_pair const int INF = 1 << 24; const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1}; typedef unsigned long long ull; typedef std::pair<int, int> P; int N, M, H[1501], W[1501]; std::map<int, int> sH; int main() { while (std::cin >> N >> M, N) { sH.clear(); H[0] = 0; FOR(i, 1, N + 1) { std::cin >> H[i]; H[i] += H[i - 1]; } REP(i, N + 1) { FOR(j, i + 1, N + 1) { sH[H[j] - H[i]]++; } } W[0] = 0; FOR(i, 1, M + 1) { std::cin >> W[i]; W[i] += W[i - 1]; } int res = 0; REP(i, M + 1) { FOR(j, i + 1, M + 1) { res += sH[W[j] - W[i]]; } } std::cout << res << std::endl; } }
[["+", 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
335
loop { n, m = gets.split.map &:to_i break if n == 0 hs = (1..n).map { gets.to_i } ws = (1..m).map { gets.to_i } h_hash = Hash.new(0) (0..hs.size-1).each{|i| s = 0 (i..hs.size-1).each{|j| s += hs[j] h_hash[s] += 1 } } w_hash = Hash.new(0) (0..ws.size-1).each{|i| s = 0 (i..ws.size-1).each{|j| s += ws[j] w_hash[s] += 1 } } hs = h_hash.to_a.sort_by(&:first) ws = w_hash.to_a.sort_by(&:first) i = 0 j = 0 count = 0 while i < hs.size && j < ws.size if hs[i][0] == ws[j][0] count += hs[i][1] * ws[i][1] i += 1 j += 1 elsif hs[i][0] < ws[j][0] i += 1 else j += 1 end end p count }
loop { n, m = gets.split.map &:to_i break if n == 0 hs = (1..n).map { gets.to_i } ws = (1..m).map { gets.to_i } h_hash = Hash.new(0) (0..hs.size-1).each{|i| s = 0 (i..hs.size-1).each{|j| s += hs[j] h_hash[s] += 1 } } w_hash = Hash.new(0) (0..ws.size-1).each{|i| s = 0 (i..ws.size-1).each{|j| s += ws[j] w_hash[s] += 1 } } hs = h_hash.to_a.sort_by(&:first) ws = w_hash.to_a.sort_by(&:first) i = 0 j = 0 count = 0 while i < hs.size && j < ws.size if hs[i][0] == ws[j][0] count += hs[i][1] * ws[j][1] i += 1 j += 1 elsif hs[i][0] < ws[j][0] i += 1 else j += 1 end end p count }
[["-", 0, 755, 12, 738, 12, 742, 500, 742, 0, 22], ["+", 0, 755, 12, 738, 12, 742, 500, 742, 0, 22]]
4
266
#include <iostream> #include <numeric> #include <vector> using namespace std; int main() { while (true) { // N, M, P ?????\??? int n, m, p; cin >> n >> m >> p; // 0 0 0 ???????????? if (n == 0 && m == 0 && p == 0) return 0; // x ?????\??? vector<int> x(n); for (auto &a : x) cin >> a; // ???????????????????????? if (x[n - 1] == 0) { cout << 0 << endl; continue; } //????¨?????????? int sum = accumulate(x.begin(), x.end(), 0) * 100; //????????????????????? double total = sum * (100 - p) / 100; //???????????? int money = total / x[m - 1]; cout << money << endl; } return 0; }
#include <iostream> #include <numeric> #include <vector> using namespace std; int main() { while (true) { // N, M, P ?????\??? int n, m, p; cin >> n >> m >> p; // 0 0 0 ???????????? if (n == 0 && m == 0 && p == 0) return 0; // x ?????\??? vector<int> x(n); for (auto &a : x) cin >> a; // ???????????????????????? if (x[m - 1] == 0) { cout << 0 << endl; continue; } //????テつィ?????????? int sum = accumulate(x.begin(), x.end(), 0) * 100; //????????????????????? double total = sum * (100 - p) / 100; //???????????? int money = total / x[m - 1]; cout << money << endl; } return 0; }
[["-", 51, 16, 31, 69, 341, 342, 0, 16, 31, 22], ["+", 51, 16, 31, 69, 341, 342, 0, 16, 31, 22]]
1
159
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, p; while (cin >> n >> m >> p && (n || m == 0 || p == 0)) { int sum = 0; int maisu = 0; int winner = -1; for (int i = 0; i < n; i++) { cin >> maisu; sum += maisu; if (i + 1 == m) winner = maisu; } if (winner != 0) { cout << (sum * (100 - p)) / winner << endl; } else { cout << 0 << endl; } winner = -1; maisu = 0; sum = 0; } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, p; while (cin >> n >> m >> p && (n || m || p)) { int sum = 0; int maisu = 0; int winner = -1; for (int i = 0; i < n; i++) { cin >> maisu; sum += maisu; if (i + 1 == m) winner = maisu; } if (winner != 0) { cout << (sum * (100 - p)) / winner << endl; } else { cout << 0 << endl; } winner = -1; maisu = 0; sum = 0; } return 0; }
[["-", 12, 23, 0, 16, 31, 16, 12, 16, 17, 60], ["-", 12, 23, 0, 16, 31, 16, 12, 16, 12, 13], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 17, 60], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 12, 13]]
1
160
#include <iostream> using namespace std; int main() { int n, m, p; while (cin >> n >> m >> p, n, m, p) { int sum = 0; int key; for (int i = 1; i <= n; i++) { int k; cin >> k; sum += k; if (i == m) key = k; } if (key == 0) cout << "0\n"; else cout << sum * (100 - p) / key << endl; } }
#include <iostream> using namespace std; int main() { int n, m, p; while (cin >> n >> m >> p, n || m || p) { int sum = 0; int key; for (int i = 1; i <= n; i++) { int k; cin >> k; sum += k; if (i == m) key = k; } if (key == 0) cout << "0\n"; else cout << sum * (100 - p) / key << endl; } }
[["-", 0, 52, 15, 339, 51, 34, 12, 34, 0, 21], ["+", 15, 339, 51, 34, 12, 16, 31, 16, 17, 106], ["-", 15, 339, 51, 34, 12, 34, 12, 34, 0, 21], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
110
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; #define rep(i, n) for (int i = 0; i < n; i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() int main(void) { int n, m, p; while (cin >> n >> m >> p, n) { double t = 0, h = 0; rep(i, n) { int s; cin >> s; if (i + 1 == m) h = s; t += s; } cout << floor(h ? t * p / h : 0) << endl; } }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; #define rep(i, n) for (int i = 0; i < n; i++) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() int main(void) { int n, m, p; while (cin >> n >> m >> p, n) { double t = 0, h = 0; rep(i, n) { int s; cin >> s; if (i + 1 == m) h = s; t += s; } cout << floor(h ? t * (100 - p) / h : 0) << endl; } }
[["+", 0, 41, 64, 16, 31, 16, 12, 23, 0, 24], ["+", 64, 16, 31, 16, 12, 23, 0, 16, 31, 13], ["+", 64, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 41, 64, 16, 31, 16, 12, 23, 0, 25]]
1
135
#include <bits/stdc++.h> using namespace std; void solve(int n, int m, int p) { vector<int> v; int a; int sum = 0; for (int i = 0; i < n; i++) { cin >> a; sum += a; v.push_back(a); } if (v[m - 1]) cout << (sum * p / v[m - 1]) << endl; else cout << 0 << endl; } int main(void) { int a, b, c; while (cin >> a >> b >> c, a) { solve(a, b, c); } }
#include <bits/stdc++.h> using namespace std; void solve(int n, int m, int p) { vector<int> v; int a; int sum = 0; for (int i = 0; i < n; i++) { cin >> a; sum += a; v.push_back(a); } if (v[m - 1]) cout << (sum * (100 - p) / v[m - 1]) << endl; else cout << 0 << endl; } int main(void) { int a, b, c; while (cin >> a >> b >> c, a) { solve(a, b, c); } }
[["+", 12, 23, 0, 16, 31, 16, 12, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 31, 13], ["+", 0, 16, 31, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 23, 0, 16, 31, 16, 12, 23, 0, 25]]
1
135
#include "bits/stdc++.h" using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, p; while (cin >> n >> m >> p, n && m && p) { int su = 0; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; su += x[i]; } m--; if (x[m] == 0) cout << 0 << endl; else cout << (su * (100 - p)) / x[m] << endl; } }
#include "bits/stdc++.h" using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, p; while (cin >> n >> m >> p, n || m || p) { int su = 0; vector<int> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; su += x[i]; } m--; if (x[m] == 0) cout << 0 << endl; else cout << (su * (100 - p)) / x[m] << endl; } }
[["-", 15, 339, 51, 34, 12, 16, 31, 16, 17, 98], ["+", 15, 339, 51, 34, 12, 16, 31, 16, 17, 106], ["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
135
#include <iostream> using namespace std; int main() { int n, m, p, a, v, sum = 0; while (1) { cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; for (int i = 1; i <= n; i++) { cin >> a; sum += a; if (i == m) v = a; } if (v == 0) cout << "0\n"; else cout << sum * (100 - p) / v << '\n'; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, p, a, v, sum = 0; while (1) { cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; for (int i = 1; i <= n; i++) { cin >> a; sum += a; if (i == m) v = a; } if (v == 0) cout << "0\n"; else cout << sum * (100 - p) / v << '\n'; sum = 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
124
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, m, p; while (cin >> n >> m >> p, n || m || p) { vector<int> x(n); int bet = 0; for (int i = 0; i < n; i++) { // input cin >> x[i]; bet += x[i]; } bet = bet * p; if (x[m - 1] == 0) { cout << 0 << endl; } else { double tmp = bet / x[m - 1]; cout << (int)tmp << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int n, m, p; while (cin >> n >> m >> p, n || m || p) { vector<int> x(n); int bet = 0; for (int i = 0; i < n; i++) { // input cin >> x[i]; bet += x[i]; } bet = bet * (100 - p); if (x[m - 1] == 0) { cout << 0 << endl; } else { double tmp = bet / x[m - 1]; cout << (int)tmp << endl; } } return 0; }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 31, 13], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
1
138
#include <algorithm> #include <iostream> #include <math.h> #include <numeric> #include <string> #include <vector> using namespace std; int N, M, P; int main() { while (cin >> N >> M >> P, N && M && P) { int sum = 0, temp = 0; for (int i = 0; i < N; ++i) { int a; cin >> a; if (i == M - 1) temp = a; sum += a; } if (temp != 0) { cout << sum * (100 - P) / temp << endl; } else { cout << 0 << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <numeric> #include <string> #include <vector> using namespace std; int N, M, P; int main() { while (cin >> N >> M >> P, N || M || P) { int sum = 0, temp = 0; for (int i = 0; i < N; ++i) { int a; cin >> a; if (i == M - 1) temp = a; sum += a; } if (temp != 0) { cout << sum * (100 - P) / temp << endl; } else { cout << 0 << endl; } } return 0; }
[["-", 15, 339, 51, 34, 12, 16, 31, 16, 17, 98], ["+", 15, 339, 51, 34, 12, 16, 31, 16, 17, 106], ["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106]]
1
129
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) const double EPS = 1e-10; int main() { int n, m, p; while (cin >> n >> m >> p, n, m, p) { vi player(n, 0); int sum = 0; REP(i, n) { cin >> player[i]; sum += player[i]; } sum *= (100 - p); if (player[m - 1]) { cout << sum / player[m - 1] << endl; } else { cout << 0 << endl; } } }
#include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EACH(t, i, c) for (t::iretator i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) const double EPS = 1e-10; int main() { int n, m, p; while (cin >> n >> m >> p, n) { vi player(n, 0); int sum = 0; REP(i, n) { cin >> player[i]; sum += player[i]; } sum *= (100 - p); if (player[m - 1]) { cout << sum / player[m - 1] << endl; } else { cout << 0 << endl; } } }
[["-", 0, 52, 15, 339, 51, 34, 12, 34, 0, 21], ["-", 15, 339, 51, 34, 12, 34, 12, 34, 31, 22], ["-", 15, 339, 51, 34, 12, 34, 12, 34, 0, 21], ["-", 15, 339, 51, 34, 12, 34, 12, 34, 12, 22]]
1
291
#include <stdio.h> int main(void) { double sum; int n, m, p, i, x[100]; while (1) { scanf("%d%d%d", &n, &m, &p); if (n == 0 && m == 0 && p == 0) break; sum = 0; for (i = 0; i < n; i++) { scanf("%d", &x[i]); sum += 100 * x[i]; } if (x[m - 1] == 0) { sum = sum * (100 - p) * 0.01; sum /= x[m - 1]; printf("%d\n", (int)sum); } else printf("0\n"); } return 0; }
#include <stdio.h> int main(void) { double sum; int n, m, p, i, x[100]; while (1) { scanf("%d%d%d", &n, &m, &p); if (n == 0 && m == 0 && p == 0) break; sum = 0; for (i = 0; i < n; i++) { scanf("%d", &x[i]); sum += 100 * x[i]; } if (x[m - 1] != 0) { sum = sum * (100 - p) * 0.01; sum /= x[m - 1]; printf("%d\n", (int)sum); } else printf("0\n"); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79]]
1
164
#include <iostream> using namespace std; int main() { int n, m, p, ans; while (1) { cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; ans = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; ans += x; if (i == m) m = x; } if (m == 0) { ans = 0; } else { ans = ans * (100 - p) / m; } cout << ans << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, p, ans; while (1) { cin >> n >> m >> p; if (n == 0 && m == 0 && p == 0) break; ans = 0; int a; for (int i = 1; i <= n; i++) { int x; cin >> x; ans += x; if (i == m) a = x; } if (a == 0) { ans = 0; } else { ans = ans * (100 - p) / a; } cout << ans << endl; } return 0; }
[["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 49, 22], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 0, 35], ["-", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
1
128
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef istringstream ISS; typedef ostringstream OSS; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define FOR(v, c) for (auto &v : c) #define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it) #define ALL(c) (c).begin(), (c).end() #define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end() #define PB(n) push_back(n) #define MP(a, b) make_pair((a), (b)) #define EXIST(c, e) ((c).find(e) != (c).end()) #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { int n, m, p; cin >> n >> m >> p; if (!(n | m | p)) { break; } VI xs(n); FOR(x, xs) { cin >> x; } int total = accumulate(ALL(xs), 0) * 100; int rest = 1. * total * (1. - p / 100.); if (xs[m - 1] == 0) { cout << 0 << endl; } else { cout << (int)(rest / xs[m - 1]) << endl; } } return 0; }
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef istringstream ISS; typedef ostringstream OSS; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define FOR(v, c) for (auto &v : c) #define EACH(it, c) for (auto it = c.begin(); it != c.end(); ++it) #define ALL(c) (c).begin(), (c).end() #define DRANGE(c, p) (c).begin(), (c).begin() + p, (c).end() #define PB(n) push_back(n) #define MP(a, b) make_pair((a), (b)) #define EXIST(c, e) ((c).find(e) != (c).end()) #define fst first #define snd second #define DUMP(x) cerr << #x << " = " << (x) << endl #define DEBUG(x) \ cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << (x) << endl int main() { cin.tie(0); ios::sync_with_stdio(false); while (true) { int n, m, p; cin >> n >> m >> p; if (!(n | m | p)) { break; } VI xs(n); FOR(x, xs) { cin >> x; } int total = accumulate(ALL(xs), 0) * 100; double rest = 1. * total * (100 - p) / 100; if (xs[m - 1] == 0) { cout << 0 << endl; } else { cout << (int)(rest / xs[m - 1]) << endl; } } return 0; }
[["-", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 52, 8, 9, 0, 43, 39, 40], ["-", 49, 50, 51, 16, 12, 23, 0, 16, 31, 13], ["+", 51, 16, 31, 16, 12, 23, 0, 16, 31, 13], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 17, 85], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 85], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
321
#include <iostream> #include <vector> using namespace std; int main() { int n, m, p; while (cin >> n >> m >> p, n && m && p) { vector<int> vec(n, 0); for (int i = 0; i < n; i++) { cin >> vec[i]; } int sum = 0; for (int i = 0; i < n; i++) { sum += vec[i]; } sum = sum * (100 - p); // cout << sum << endl; if (vec[m - 1] == 0) cout << 0 << endl; else cout << (int)(sum / vec[m - 1]) << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n, m, p; while (cin >> n >> m >> p, n | m | p) { vector<int> vec(n, 0); for (int i = 0; i < n; i++) { cin >> vec[i]; } int sum = 0; for (int i = 0; i < n; i++) { sum += vec[i]; } sum = sum * (100 - p); if (vec[m - 1] == 0) cout << 0 << endl; else cout << (int)(sum / vec[m - 1]) << endl; } return 0; }
[["-", 15, 339, 51, 34, 12, 16, 31, 16, 17, 98], ["+", 15, 339, 51, 34, 12, 16, 31, 16, 17, 139], ["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 139]]
1
151
#include <iostream> #include <vector> int main(int argc, char const *argv[]) { while (true) { int N, M, P; std::cin >> N >> M >> P; if (N == 0 && M == 0 && P == 0) break; std::vector<int> X(N); double pool = 0.0; for (int i = 0; i < N; ++i) { std::cin >> X[i]; pool += X[i] * 100; } if (X[M - 1] == 0) { std::cout << 0 << std::endl; } else { double for_divide = (1.0 - (double)P / 100.0) * pool; std::cout << (int)(for_divide / X[M - 1]) << std::endl; } } return 0; }
#include <iostream> #include <vector> int main(int argc, char const *argv[]) { while (true) { int N, M, P; std::cin >> N >> M >> P; if (N == 0 && M == 0 && P == 0) break; std::vector<int> X(N); double pool = 0.0; for (int i = 0; i < N; ++i) { std::cin >> X[i]; pool += X[i] * 100; } if (X[M - 1] == 0) { std::cout << 0 << std::endl; } else { double for_divide = pool - ((double)P / 100.0) * pool; std::cout << (int)(for_divide / X[M - 1]) << std::endl; } } return 0; }
[["-", 0, 43, 49, 50, 51, 16, 31, 23, 0, 24], ["-", 49, 50, 51, 16, 31, 23, 0, 16, 31, 13], ["+", 0, 9, 0, 43, 49, 50, 51, 16, 31, 22], ["+", 49, 50, 51, 16, 12, 16, 31, 23, 0, 24]]
1
175
while True: N, M, P = map(int, input().split()) if N == 0 and M == 0 and P == 0: break X = [int(input()) for _ in range(N)] win = X[M - 1] if win == 0: print(0) else: print(int(sum(X) * 100 * (1 - P / 100) // win))
while True: N, M, P = map(int, input().split()) if N == 0 and M == 0 and P == 0: break X = [int(input()) for _ in range(N)] win = X[M - 1] if win == 0: print(0) else: print(int(round(sum(X) * 100 * (1 - P / 100) / win, 10)))
[["+", 3, 4, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["-", 3, 4, 0, 652, 3, 4, 0, 657, 17, 676], ["+", 3, 4, 0, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 21], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 612], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
93
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: N,M,P = map(int,input().split(" ")) if N == 0 and M == 0 and P == 0: break count = 0 for i in range(N): x = int(input()) count += x if i + 1 == M: hitman = x if hitman == 0: print(0) else: print(int((count*100)*((100-P)/100)/hitman))
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: N,M,P = map(int,input().split(" ")) if N == 0 and M == 0 and P == 0: break count = 0 for i in range(N): x = int(input()) count += x if i + 1 == M: hitman = x if hitman == 0: print(0) else: print(int((count)*((100-P))/hitman))
[["-", 0, 657, 31, 657, 31, 23, 0, 657, 17, 48], ["-", 0, 657, 31, 657, 31, 23, 0, 657, 12, 612], ["-", 0, 657, 31, 657, 12, 23, 0, 657, 17, 85], ["-", 0, 657, 31, 657, 12, 23, 0, 657, 12, 612]]
5
106
#!/usr/bin/python # -*- coding: utf-8 -*- import math while True: amount, number, per = map(int, input().split()) if amount == 0 and number == 0 and per == 0: break vote = [int(input()) for i in range(amount)] # for _ in range(amount): # vote.append(int(input())) if vote[number-1] == 0: print("0") else: print(math.floor((100 * sum(vote) * ((100 - per) / 100)) / vote[number-1]))
#!/usr/bin/python # -*- coding: utf-8 -*- import math while True: amount, number, per = map(int, input().split()) if amount == 0 and number == 0 and per == 0: break vote = [int(input()) for _ in range(amount)] if vote[number-1] == 0: print("0") else: print(math.floor(100 * sum(vote) * (100 - per) / 100 / vote[number-1]))
[["-", 0, 1, 0, 662, 12, 658, 0, 659, 31, 22], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 31, 22], ["-", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["-", 0, 657, 31, 23, 0, 657, 12, 23, 0, 24], ["-", 0, 657, 31, 23, 0, 657, 12, 23, 0, 25], ["-", 0, 652, 3, 4, 0, 657, 31, 23, 0, 25]]
5
109
def solve(n, m, p): tot = 0 a = 0 for i in range(n): x = int(input()) tot += 100 * x if i == m-1: a = x if a == 0: print(0) return tot *= (100-p) / 100.0 ans = int(tot / a) print(ans) while 1: n, m, p = map(int, input().split()) if n == 0: break solve(n, m, p)
def solve(n, m, p): tot = 0 a = 0 for i in range(n): x = int(input()) tot += 100 * x if i == m-1: a = x if a == 0: print(0) return tot = tot * (100-p) / 100.0 ans = int(tot / a) print(ans) while 1: n, m, p = map(int, input().split()) if n == 0: break solve(n, m, p)
[["-", 0, 14, 8, 196, 0, 1, 0, 677, 17, 108], ["+", 0, 14, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 31, 22], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 17, 48]]
5
113