# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
826912 | 2023-08-16T06:27:56 Z | 반딧불(#10373) | JOIRIS (JOI16_joiris) | C++17 | 1 ms | 304 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k; int arr[52]; void subtask1(); void subtask2(); int main(){ scanf("%d %d", &n, &k); for(int i=1; i<=n; i++) scanf("%d", &arr[i]); if(k==2){ if(n%2==0) subtask1(); else subtask2(); } } vector<pair<int, int> > ans; void subtask1(){ if(accumulate(arr+1, arr+n+1, 0) % 2){ puts("-1"); exit(0); } for(int i=1; i<=n; i++){ while(arr[i] < arr[i-1]){ ans.push_back(make_pair(1, i)); arr[i] += 2; } } int minV = *min_element(arr+1, arr+n+1); for(int i=1; i<=n; i++) arr[i] -= minV; for(int i=1; i<n; i++){ int v = arr[i+1] - arr[i]; for(int j=i-1; j>=1; j-=2) for(int c=0; c<v; c++) ans.push_back(make_pair(2, j)); if(i%2==0) for(int j=i+1; j<=n; j++) arr[j] -= v; else for(int j=2; j<=i; j++) arr[j] += v; } int v = (arr[2] - arr[1]) / 2; for(int i=0; i<v; i++) ans.push_back(make_pair(1, 1)); printf("%d\n", (int)ans.size()); for(auto p: ans){ printf("%d %d\n", p.first, p.second); } } void subtask2(){ for(int i=1; i<=n; i++){ while(arr[i] < arr[i-1]){ ans.push_back(make_pair(1, i)); arr[i] += 2; } } int minV = *min_element(arr+1, arr+n+1); for(int i=1; i<=n; i++) arr[i] -= minV; for(int i=1; i<n; i++){ int v = arr[i+1] - arr[i]; for(int j=i-1; j>=1; j-=2) for(int c=0; c<v; c++) ans.push_back(make_pair(2, j)); if(i%2==0) for(int j=i+1; j<=n; j++) arr[j] -= v; else for(int j=2; j<=i; j++) arr[j] += v; } int v = (arr[2] - arr[1]) / 2; for(int i=0; i<v; i++) ans.push_back(make_pair(1, 1)), arr[1] += 2; if(arr[1] != arr[2]){ ans.push_back(make_pair(1, 1)); for(int i=2; i<n; i+=2) ans.push_back(make_pair(2, i)); } printf("%d\n", (int)ans.size()); for(auto p: ans){ printf("%d %d\n", p.first, p.second); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 304 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 300 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 1 ms | 304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Incorrect | 0 ms | 228 KB | Unexpected end of file - int32 expected |
18 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 0 ms | 212 KB | Output is correct |
15 | Correct | 0 ms | 212 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 212 KB | Output is correct |
18 | Correct | 0 ms | 212 KB | Output is correct |
19 | Correct | 0 ms | 212 KB | Output is correct |
20 | Correct | 0 ms | 212 KB | Output is correct |
21 | Correct | 1 ms | 212 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 0 ms | 212 KB | Output is correct |
24 | Correct | 0 ms | 304 KB | Output is correct |
25 | Correct | 1 ms | 212 KB | Output is correct |
26 | Correct | 0 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 0 ms | 300 KB | Output is correct |
30 | Correct | 1 ms | 212 KB | Output is correct |
31 | Correct | 0 ms | 212 KB | Output is correct |
32 | Correct | 1 ms | 304 KB | Output is correct |
33 | Incorrect | 0 ms | 228 KB | Unexpected end of file - int32 expected |
34 | Halted | 0 ms | 0 KB | - |