Submission #1041470

# Submission time Handle Problem Language Result Execution time Memory
1041470 2024-08-02T04:24:54 Z phong JOIRIS (JOI16_joiris) C++17
100 / 100
1 ms 2908 KB
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

#define ll long long
const int nmax = 1e6 + 5, N = 1e5;
const ll oo = 1e9;
const int lg = 31, M = 2, mod = 1e6;
#define pii pair<ll, ll>
#define fi first
#define se second
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; cout << "\n";
#define endl "\n"
#define task "code"
using namespace std;


int n, k;
int a[nmax], c[nmax];
vector<pii> ans;
void add(int id, int i){
    ans.push_back({id, i});
    if(ans.size() > 1e4) cout << -1, exit(0);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
//    freopen(task".inp", "r", stdin);
//    freopen(task".out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    while(1){
        bool ok = 1;
        for(int i = 1; i <= n; ++i) ok &= (a[i] == 0);
        if(ok) break;
        for(int i = 2; i <= n; ++i){
            while(a[i] < a[i -1]){
                add(1, i);
                a[i] += k;
            }
        }
        for(int i = 1; i <= n; ++i) c[i] = a[i];
        for(int i = 0; i <= a[n]; ++i){
            int pos = upper_bound(a + 1, a + 1 + n, i) - a - 1;
            while(pos >= k){
                for(int j = pos - k + 1; j <= pos; ++j) c[j]++;
                add(2, pos - k + 1);
                pos -= k;
            }
        }

        for(int i = 1; i < k; ++i){
            while(c[i] < c[n]){
                c[i] += k;
                add(1, i);
            }
        }
        int mi = oo;
        for(int i = 1; i <= n; ++i){
            mi = min(mi, c[i]);
        }
        for(int i = 1; i <= n; ++i) a[i] = c[i] - mi;
    }
    cout << ans.size() << endl;
    for(auto [id, i] : ans) cout <<id << ' ' << i << endl;


}
/*
4 2
1 0 1 2
*/

Compilation message

joiris.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2508 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2472 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2508 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2908 KB Output is correct
18 Correct 1 ms 2908 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2392 KB Output is correct
21 Correct 0 ms 2396 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2908 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 1 ms 2908 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2908 KB Output is correct
36 Correct 1 ms 2908 KB Output is correct
37 Correct 1 ms 2908 KB Output is correct
38 Correct 1 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB Output is correct
2 Correct 1 ms 2908 KB Output is correct
3 Correct 1 ms 2908 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2908 KB Output is correct
6 Correct 1 ms 2904 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2908 KB Output is correct
10 Correct 0 ms 2908 KB Output is correct
11 Correct 0 ms 2508 KB Output is correct
12 Correct 1 ms 2908 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2908 KB Output is correct
15 Correct 0 ms 2908 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 0 ms 2396 KB Output is correct
25 Correct 0 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 1 ms 2472 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2908 KB Output is correct
34 Correct 1 ms 2908 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 0 ms 2392 KB Output is correct
37 Correct 0 ms 2396 KB Output is correct
38 Correct 1 ms 2392 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2908 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 0 ms 2396 KB Output is correct
48 Correct 1 ms 2908 KB Output is correct
49 Correct 1 ms 2908 KB Output is correct
50 Correct 1 ms 2908 KB Output is correct
51 Correct 1 ms 2908 KB Output is correct
52 Correct 1 ms 2908 KB Output is correct
53 Correct 1 ms 2908 KB Output is correct
54 Correct 1 ms 2908 KB Output is correct
55 Correct 1 ms 2908 KB Output is correct
56 Correct 0 ms 2908 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 0 ms 2396 KB Output is correct
59 Correct 0 ms 2396 KB Output is correct
60 Correct 0 ms 2396 KB Output is correct
61 Correct 1 ms 2396 KB Output is correct
62 Correct 0 ms 2396 KB Output is correct
63 Correct 1 ms 2392 KB Output is correct
64 Correct 0 ms 2392 KB Output is correct
65 Correct 0 ms 2396 KB Output is correct
66 Correct 0 ms 2396 KB Output is correct
67 Correct 1 ms 2396 KB Output is correct
68 Correct 0 ms 2396 KB Output is correct
69 Correct 1 ms 2392 KB Output is correct
70 Correct 1 ms 2392 KB Output is correct
71 Correct 1 ms 2396 KB Output is correct
72 Correct 0 ms 2396 KB Output is correct
73 Correct 0 ms 2396 KB Output is correct
74 Correct 1 ms 2648 KB Output is correct
75 Correct 1 ms 2396 KB Output is correct
76 Correct 1 ms 2392 KB Output is correct
77 Correct 1 ms 2908 KB Output is correct
78 Correct 0 ms 2396 KB Output is correct
79 Correct 1 ms 2908 KB Output is correct
80 Correct 1 ms 2908 KB Output is correct
81 Correct 1 ms 2396 KB Output is correct
82 Correct 1 ms 2396 KB Output is correct
83 Correct 1 ms 2392 KB Output is correct
84 Correct 1 ms 2392 KB Output is correct
85 Correct 0 ms 2396 KB Output is correct
86 Correct 0 ms 2396 KB Output is correct
87 Correct 0 ms 2908 KB Output is correct
88 Correct 1 ms 2908 KB Output is correct
89 Correct 0 ms 2768 KB Output is correct
90 Correct 1 ms 2908 KB Output is correct
91 Correct 1 ms 2908 KB Output is correct
92 Correct 0 ms 2392 KB Output is correct