# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
57141 | 2018-07-14T06:38:59 Z | 강태규(#1651) | JOIRIS (JOI16_joiris) | C++11 | 4 ms | 1036 KB |
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <unordered_map> #include <functional> #include <cstring> #include <cmath> #include <ctime> #include <cstdlib> using namespace std; typedef long long llong; typedef long double ld; typedef pair<int, int> pii; typedef pair<llong, llong> pll; void fail() { printf("-1\n"); exit(0); } vector<pii> ans; int n, k; int a[50]; int mod[50]; int rem[50]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", a + i); mod[i % k] += a[i]; } for (int i = 0; i < k; ++i) mod[i] %= k; for (int i = 1; i < n % k; ++i) if (mod[0] != mod[i]) fail(); for (int i = n % k; i + 1 < k; ++i) if (mod[i] != mod[k - 1]) fail(); for (int i = 1; i < n; ++i) { while (a[i - 1] > a[i]) { ans.emplace_back(1, i); a[i] += k; } } for (int i = 1; i < n; ++i) { for (int j = a[i - 1]; j < a[i]; ++j) { for (int p = i - k; 0 <= p; p -= k) { ans.emplace_back(2, p); } --rem[i % k]; } } for (int i = k - 1; i--; ) rem[i] += rem[i + 1]; for (int i = 1; i < k; ++i) { while (rem[i] < 0) { ans.emplace_back(1, i - 1); rem[i] += k; } } if (n % k) { for (int i = n - k; 0 <= i; i -= k) { for (int j = 0; j < rem[1]; ++j) { ans.emplace_back(2, i); } } } printf("%d\n", (int)ans.size()); for (pii i : ans) { printf("%d %d\n", i.first, i.second + 1); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 3 ms | 492 KB | Output is correct |
4 | Correct | 4 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 492 KB | Output is correct |
6 | Correct | 3 ms | 500 KB | Output is correct |
7 | Correct | 4 ms | 644 KB | Output is correct |
8 | Correct | 2 ms | 644 KB | Output is correct |
9 | Correct | 3 ms | 644 KB | Output is correct |
10 | Correct | 2 ms | 644 KB | Output is correct |
11 | Correct | 3 ms | 644 KB | Output is correct |
12 | Correct | 4 ms | 644 KB | Output is correct |
13 | Correct | 2 ms | 644 KB | Output is correct |
14 | Correct | 3 ms | 644 KB | Output is correct |
15 | Correct | 3 ms | 644 KB | Output is correct |
16 | Correct | 0 ms | 648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 648 KB | Output is correct |
2 | Correct | 3 ms | 648 KB | Output is correct |
3 | Correct | 3 ms | 648 KB | Output is correct |
4 | Correct | 2 ms | 648 KB | Output is correct |
5 | Correct | 3 ms | 660 KB | Output is correct |
6 | Correct | 3 ms | 680 KB | Output is correct |
7 | Correct | 3 ms | 680 KB | Output is correct |
8 | Correct | 3 ms | 680 KB | Output is correct |
9 | Correct | 2 ms | 708 KB | Output is correct |
10 | Correct | 2 ms | 708 KB | Output is correct |
11 | Correct | 2 ms | 716 KB | Output is correct |
12 | Correct | 3 ms | 720 KB | Output is correct |
13 | Correct | 2 ms | 720 KB | Output is correct |
14 | Correct | 2 ms | 720 KB | Output is correct |
15 | Correct | 3 ms | 720 KB | Output is correct |
16 | Correct | 2 ms | 720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 3 ms | 492 KB | Output is correct |
4 | Correct | 4 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 492 KB | Output is correct |
6 | Correct | 3 ms | 500 KB | Output is correct |
7 | Correct | 4 ms | 644 KB | Output is correct |
8 | Correct | 2 ms | 644 KB | Output is correct |
9 | Correct | 3 ms | 644 KB | Output is correct |
10 | Correct | 2 ms | 644 KB | Output is correct |
11 | Correct | 3 ms | 644 KB | Output is correct |
12 | Correct | 4 ms | 644 KB | Output is correct |
13 | Correct | 2 ms | 644 KB | Output is correct |
14 | Correct | 3 ms | 644 KB | Output is correct |
15 | Correct | 3 ms | 644 KB | Output is correct |
16 | Correct | 0 ms | 648 KB | Output is correct |
17 | Correct | 3 ms | 720 KB | Output is correct |
18 | Correct | 3 ms | 728 KB | Output is correct |
19 | Correct | 3 ms | 748 KB | Output is correct |
20 | Correct | 3 ms | 748 KB | Output is correct |
21 | Correct | 3 ms | 748 KB | Output is correct |
22 | Correct | 2 ms | 748 KB | Output is correct |
23 | Correct | 3 ms | 756 KB | Output is correct |
24 | Correct | 3 ms | 772 KB | Output is correct |
25 | Correct | 3 ms | 776 KB | Output is correct |
26 | Correct | 3 ms | 776 KB | Output is correct |
27 | Correct | 3 ms | 784 KB | Output is correct |
28 | Correct | 3 ms | 784 KB | Output is correct |
29 | Correct | 2 ms | 808 KB | Output is correct |
30 | Correct | 3 ms | 808 KB | Output is correct |
31 | Correct | 3 ms | 808 KB | Output is correct |
32 | Correct | 2 ms | 808 KB | Output is correct |
33 | Correct | 3 ms | 808 KB | Output is correct |
34 | Correct | 3 ms | 808 KB | Output is correct |
35 | Correct | 2 ms | 808 KB | Output is correct |
36 | Correct | 2 ms | 844 KB | Output is correct |
37 | Correct | 3 ms | 844 KB | Output is correct |
38 | Correct | 2 ms | 844 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 3 ms | 492 KB | Output is correct |
4 | Correct | 4 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 492 KB | Output is correct |
6 | Correct | 3 ms | 500 KB | Output is correct |
7 | Correct | 4 ms | 644 KB | Output is correct |
8 | Correct | 2 ms | 644 KB | Output is correct |
9 | Correct | 3 ms | 644 KB | Output is correct |
10 | Correct | 2 ms | 644 KB | Output is correct |
11 | Correct | 3 ms | 644 KB | Output is correct |
12 | Correct | 4 ms | 644 KB | Output is correct |
13 | Correct | 2 ms | 644 KB | Output is correct |
14 | Correct | 3 ms | 644 KB | Output is correct |
15 | Correct | 3 ms | 644 KB | Output is correct |
16 | Correct | 0 ms | 648 KB | Output is correct |
17 | Correct | 2 ms | 648 KB | Output is correct |
18 | Correct | 3 ms | 648 KB | Output is correct |
19 | Correct | 3 ms | 648 KB | Output is correct |
20 | Correct | 2 ms | 648 KB | Output is correct |
21 | Correct | 3 ms | 660 KB | Output is correct |
22 | Correct | 3 ms | 680 KB | Output is correct |
23 | Correct | 3 ms | 680 KB | Output is correct |
24 | Correct | 3 ms | 680 KB | Output is correct |
25 | Correct | 2 ms | 708 KB | Output is correct |
26 | Correct | 2 ms | 708 KB | Output is correct |
27 | Correct | 2 ms | 716 KB | Output is correct |
28 | Correct | 3 ms | 720 KB | Output is correct |
29 | Correct | 2 ms | 720 KB | Output is correct |
30 | Correct | 2 ms | 720 KB | Output is correct |
31 | Correct | 3 ms | 720 KB | Output is correct |
32 | Correct | 2 ms | 720 KB | Output is correct |
33 | Correct | 3 ms | 720 KB | Output is correct |
34 | Correct | 3 ms | 728 KB | Output is correct |
35 | Correct | 3 ms | 748 KB | Output is correct |
36 | Correct | 3 ms | 748 KB | Output is correct |
37 | Correct | 3 ms | 748 KB | Output is correct |
38 | Correct | 2 ms | 748 KB | Output is correct |
39 | Correct | 3 ms | 756 KB | Output is correct |
40 | Correct | 3 ms | 772 KB | Output is correct |
41 | Correct | 3 ms | 776 KB | Output is correct |
42 | Correct | 3 ms | 776 KB | Output is correct |
43 | Correct | 3 ms | 784 KB | Output is correct |
44 | Correct | 3 ms | 784 KB | Output is correct |
45 | Correct | 2 ms | 808 KB | Output is correct |
46 | Correct | 3 ms | 808 KB | Output is correct |
47 | Correct | 3 ms | 808 KB | Output is correct |
48 | Correct | 2 ms | 808 KB | Output is correct |
49 | Correct | 3 ms | 808 KB | Output is correct |
50 | Correct | 3 ms | 808 KB | Output is correct |
51 | Correct | 2 ms | 808 KB | Output is correct |
52 | Correct | 2 ms | 844 KB | Output is correct |
53 | Correct | 3 ms | 844 KB | Output is correct |
54 | Correct | 2 ms | 844 KB | Output is correct |
55 | Correct | 2 ms | 844 KB | Output is correct |
56 | Correct | 3 ms | 844 KB | Output is correct |
57 | Correct | 3 ms | 844 KB | Output is correct |
58 | Correct | 3 ms | 844 KB | Output is correct |
59 | Correct | 3 ms | 844 KB | Output is correct |
60 | Correct | 2 ms | 844 KB | Output is correct |
61 | Correct | 2 ms | 844 KB | Output is correct |
62 | Correct | 2 ms | 844 KB | Output is correct |
63 | Correct | 3 ms | 844 KB | Output is correct |
64 | Correct | 2 ms | 844 KB | Output is correct |
65 | Correct | 3 ms | 844 KB | Output is correct |
66 | Correct | 2 ms | 844 KB | Output is correct |
67 | Correct | 2 ms | 844 KB | Output is correct |
68 | Correct | 3 ms | 844 KB | Output is correct |
69 | Correct | 3 ms | 844 KB | Output is correct |
70 | Correct | 4 ms | 916 KB | Output is correct |
71 | Correct | 4 ms | 936 KB | Output is correct |
72 | Correct | 4 ms | 940 KB | Output is correct |
73 | Correct | 3 ms | 944 KB | Output is correct |
74 | Correct | 3 ms | 948 KB | Output is correct |
75 | Correct | 2 ms | 968 KB | Output is correct |
76 | Correct | 2 ms | 972 KB | Output is correct |
77 | Correct | 2 ms | 972 KB | Output is correct |
78 | Correct | 3 ms | 980 KB | Output is correct |
79 | Correct | 2 ms | 980 KB | Output is correct |
80 | Correct | 2 ms | 980 KB | Output is correct |
81 | Correct | 2 ms | 992 KB | Output is correct |
82 | Correct | 2 ms | 992 KB | Output is correct |
83 | Correct | 3 ms | 992 KB | Output is correct |
84 | Correct | 2 ms | 1004 KB | Output is correct |
85 | Correct | 2 ms | 1004 KB | Output is correct |
86 | Correct | 3 ms | 1016 KB | Output is correct |
87 | Correct | 3 ms | 1016 KB | Output is correct |
88 | Correct | 2 ms | 1016 KB | Output is correct |
89 | Correct | 3 ms | 1016 KB | Output is correct |
90 | Correct | 2 ms | 1016 KB | Output is correct |
91 | Correct | 2 ms | 1016 KB | Output is correct |
92 | Correct | 2 ms | 1036 KB | Output is correct |