#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef long long ll;
const int MAXN = 7;
int n, power10[8] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000};
int dp[10000000 + 5], a[MAXN + 5], b[MAXN + 5], idb, sb;
bool brutus(int arr[]) {
int id = 0, sa = 0;
for (int i = 0; i < n; i++) {
sa += arr[i];
id += power10[i] * arr[i];
}
if (sa < sb) return 0;
if (dp[id] != -1) return dp[id];
dp[id] = 0;
for (int i = 0; i < n; i++) {
if (arr[i] > 1) {
arr[i] -= 2;
arr[(i + 1) % n] += 1;
dp[id] |= brutus(arr);
arr[i] += 2;
arr[(i + 1) % n] -= 1;
}
}
return dp[id];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(dp, -1, sizeof(dp));
cin >> n;
idb = 0, sb = 0;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
sb += b[i];
idb += power10[i] * b[i];
}
dp[idb] = 1;
cout << (brutus(a) ? "Yes" : "No") << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
39380 KB |
Output is correct |
2 |
Correct |
18 ms |
39376 KB |
Output is correct |
3 |
Correct |
18 ms |
39380 KB |
Output is correct |
4 |
Correct |
16 ms |
39460 KB |
Output is correct |
5 |
Correct |
17 ms |
39444 KB |
Output is correct |
6 |
Correct |
17 ms |
39380 KB |
Output is correct |
7 |
Correct |
17 ms |
39340 KB |
Output is correct |
8 |
Correct |
15 ms |
39380 KB |
Output is correct |
9 |
Correct |
16 ms |
39384 KB |
Output is correct |
10 |
Correct |
16 ms |
39436 KB |
Output is correct |
11 |
Correct |
15 ms |
39448 KB |
Output is correct |
12 |
Correct |
16 ms |
39380 KB |
Output is correct |
13 |
Correct |
16 ms |
39436 KB |
Output is correct |
14 |
Correct |
17 ms |
39436 KB |
Output is correct |
15 |
Correct |
17 ms |
39380 KB |
Output is correct |
16 |
Correct |
16 ms |
39352 KB |
Output is correct |
17 |
Correct |
16 ms |
39380 KB |
Output is correct |
18 |
Correct |
17 ms |
39356 KB |
Output is correct |
19 |
Correct |
16 ms |
39344 KB |
Output is correct |
20 |
Correct |
17 ms |
39440 KB |
Output is correct |
21 |
Correct |
17 ms |
39380 KB |
Output is correct |
22 |
Correct |
17 ms |
39400 KB |
Output is correct |
23 |
Correct |
17 ms |
39376 KB |
Output is correct |
24 |
Correct |
18 ms |
39360 KB |
Output is correct |
25 |
Correct |
15 ms |
39380 KB |
Output is correct |
26 |
Correct |
17 ms |
39364 KB |
Output is correct |
27 |
Correct |
17 ms |
39440 KB |
Output is correct |
28 |
Correct |
16 ms |
39376 KB |
Output is correct |
29 |
Correct |
18 ms |
39432 KB |
Output is correct |
30 |
Correct |
19 ms |
39416 KB |
Output is correct |
31 |
Correct |
20 ms |
39380 KB |
Output is correct |
32 |
Correct |
19 ms |
39444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
39380 KB |
Output is correct |
2 |
Correct |
18 ms |
39376 KB |
Output is correct |
3 |
Correct |
18 ms |
39380 KB |
Output is correct |
4 |
Correct |
16 ms |
39460 KB |
Output is correct |
5 |
Correct |
17 ms |
39444 KB |
Output is correct |
6 |
Correct |
17 ms |
39380 KB |
Output is correct |
7 |
Correct |
17 ms |
39340 KB |
Output is correct |
8 |
Correct |
15 ms |
39380 KB |
Output is correct |
9 |
Correct |
16 ms |
39384 KB |
Output is correct |
10 |
Correct |
16 ms |
39436 KB |
Output is correct |
11 |
Correct |
15 ms |
39448 KB |
Output is correct |
12 |
Correct |
16 ms |
39380 KB |
Output is correct |
13 |
Correct |
16 ms |
39436 KB |
Output is correct |
14 |
Correct |
17 ms |
39436 KB |
Output is correct |
15 |
Correct |
17 ms |
39380 KB |
Output is correct |
16 |
Correct |
16 ms |
39352 KB |
Output is correct |
17 |
Correct |
16 ms |
39380 KB |
Output is correct |
18 |
Correct |
17 ms |
39356 KB |
Output is correct |
19 |
Correct |
16 ms |
39344 KB |
Output is correct |
20 |
Correct |
17 ms |
39440 KB |
Output is correct |
21 |
Correct |
17 ms |
39380 KB |
Output is correct |
22 |
Correct |
17 ms |
39400 KB |
Output is correct |
23 |
Correct |
17 ms |
39376 KB |
Output is correct |
24 |
Correct |
18 ms |
39360 KB |
Output is correct |
25 |
Correct |
15 ms |
39380 KB |
Output is correct |
26 |
Correct |
17 ms |
39364 KB |
Output is correct |
27 |
Correct |
17 ms |
39440 KB |
Output is correct |
28 |
Correct |
16 ms |
39376 KB |
Output is correct |
29 |
Correct |
18 ms |
39432 KB |
Output is correct |
30 |
Correct |
19 ms |
39416 KB |
Output is correct |
31 |
Correct |
20 ms |
39380 KB |
Output is correct |
32 |
Correct |
19 ms |
39444 KB |
Output is correct |
33 |
Runtime error |
48 ms |
79804 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
39380 KB |
Output is correct |
2 |
Correct |
18 ms |
39376 KB |
Output is correct |
3 |
Correct |
18 ms |
39380 KB |
Output is correct |
4 |
Correct |
16 ms |
39460 KB |
Output is correct |
5 |
Correct |
17 ms |
39444 KB |
Output is correct |
6 |
Correct |
17 ms |
39380 KB |
Output is correct |
7 |
Correct |
17 ms |
39340 KB |
Output is correct |
8 |
Correct |
15 ms |
39380 KB |
Output is correct |
9 |
Correct |
16 ms |
39384 KB |
Output is correct |
10 |
Correct |
16 ms |
39436 KB |
Output is correct |
11 |
Correct |
15 ms |
39448 KB |
Output is correct |
12 |
Correct |
16 ms |
39380 KB |
Output is correct |
13 |
Correct |
16 ms |
39436 KB |
Output is correct |
14 |
Correct |
17 ms |
39436 KB |
Output is correct |
15 |
Correct |
17 ms |
39380 KB |
Output is correct |
16 |
Correct |
16 ms |
39352 KB |
Output is correct |
17 |
Correct |
16 ms |
39380 KB |
Output is correct |
18 |
Correct |
17 ms |
39356 KB |
Output is correct |
19 |
Correct |
16 ms |
39344 KB |
Output is correct |
20 |
Correct |
17 ms |
39440 KB |
Output is correct |
21 |
Correct |
17 ms |
39380 KB |
Output is correct |
22 |
Correct |
17 ms |
39400 KB |
Output is correct |
23 |
Correct |
17 ms |
39376 KB |
Output is correct |
24 |
Correct |
18 ms |
39360 KB |
Output is correct |
25 |
Correct |
15 ms |
39380 KB |
Output is correct |
26 |
Correct |
17 ms |
39364 KB |
Output is correct |
27 |
Correct |
17 ms |
39440 KB |
Output is correct |
28 |
Correct |
16 ms |
39376 KB |
Output is correct |
29 |
Correct |
18 ms |
39432 KB |
Output is correct |
30 |
Correct |
19 ms |
39416 KB |
Output is correct |
31 |
Correct |
20 ms |
39380 KB |
Output is correct |
32 |
Correct |
19 ms |
39444 KB |
Output is correct |
33 |
Runtime error |
48 ms |
79804 KB |
Execution killed with signal 11 |
34 |
Halted |
0 ms |
0 KB |
- |