# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
70391 |
2018-08-22T19:08:34 Z |
Benq |
JOIRIS (JOI16_joiris) |
C++14 |
|
4 ms |
1472 KB |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
int n, k, a[51], dif[51], nex[51];
vpi op;
void cut() {
int mn = MOD; FOR(i,1,n+1) mn = min(mn,a[i]);
FOR(i,1,n+1) a[i] -= mn;
}
void nor() {
while (1) {
int mx = 0; FOR(i,1,n+1) mx = max(mx,a[i]);
if (mx < k) {
//FOR(i,1,n+1) cout << a[i] << " ";
//cout << "\n";
return;
}
FOR(i,1,n+1) if (a[i] == 0) {
op.pb({1,i});
a[i] += k;
}
cut();
}
}
void ad(int x) {
int hei = 0;
//FOR(i,1,n+1) cout << a[i] << " ";
//cout << "\n";
FOR(i,x,x+k) {
a[i] ++;
hei = max(hei,a[i]);
}
//FOR(i,1,n+1) cout << a[i] << " ";
//cout << "\n";
op.pb({2,x});
FOR(i,1,n+1) if (i < x || i >= x+k) {
while (a[i] < hei) {
a[i] += k;
op.pb({1,i});
}
}
/*FOR(i,1,n+1) cout << a[i] << " ";
cout << "\n";*/
cut();
/*FOR(i,1,n+1) cout << a[i] << " ";
cout << "\n";
cout << "\n";*/
}
void genDif() {
FOR(i,1,n-k+2) dif[i] = -1;
FOR(i,2,n+1) {
// dif[i]+a[i]-a[i-1] = dif[i-k]
if (i-k < 1) {
if (i > n-k+1) {
if ((a[i]-a[i-1]) % k != 0) {
// cout << "A\n";
cout << -1;
exit(0);
}
continue;
} else {
dif[i] = ((a[i-1]-a[i])%k+k)%k;
}
} else {
if (i > n-k+1) {
if (dif[i-k] != -1 && dif[i-k] != ((a[i]-a[i-1])%k+k)%k) {
// cout << "B\n";
cout << -1;
exit(0);
}
dif[i-k] = ((a[i]-a[i-1])%k+k)%k;
} else {
nex[i-k] = ((a[i]-a[i-1])%k+k)%k;
}
}
}
FOR(i,1,min(n-k+2,k+1)) {
int lo = i, hi = i; while (hi+k <= n-k+1) hi += k;
if (dif[lo] != -1) {
for (int j = lo+k; j <= hi; j += k) {
if (dif[j] > -1 && dif[j] != (dif[j-k]-nex[j-k]+k)%k) {
cout << -1;
exit(0);
}
dif[j] = (dif[j-k]-nex[j-k]+k)%k;
}
} else {
if (dif[hi] == -1) dif[hi] = 0;
for (int j = hi-k; j >= 0; j -= k) {
if (dif[j] > -1 && dif[j] != (dif[j+k]+nex[j])%k) {
cout << -1;
exit(0);
}
dif[j] = (dif[j+k]+nex[j])%k;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k;
FOR(i,1,n+1) cin >> a[i];
genDif();
FOR(i,1,n+1) {
nor();
while (dif[i]) {
ad(i);
dif[i] --;
}
}
cout << sz(op) << "\n";
for (auto a: op) cout << a.f << " " << a.s << "\n";
}
/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
520 KB |
Output is correct |
5 |
Correct |
3 ms |
576 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
3 ms |
704 KB |
Output is correct |
8 |
Correct |
2 ms |
704 KB |
Output is correct |
9 |
Correct |
2 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
2 ms |
704 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
14 |
Correct |
2 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
704 KB |
Output is correct |
16 |
Correct |
2 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
868 KB |
Output is correct |
2 |
Correct |
3 ms |
868 KB |
Output is correct |
3 |
Correct |
3 ms |
868 KB |
Output is correct |
4 |
Correct |
2 ms |
868 KB |
Output is correct |
5 |
Correct |
2 ms |
868 KB |
Output is correct |
6 |
Correct |
3 ms |
868 KB |
Output is correct |
7 |
Correct |
3 ms |
868 KB |
Output is correct |
8 |
Correct |
3 ms |
916 KB |
Output is correct |
9 |
Correct |
3 ms |
916 KB |
Output is correct |
10 |
Correct |
3 ms |
916 KB |
Output is correct |
11 |
Correct |
4 ms |
916 KB |
Output is correct |
12 |
Correct |
3 ms |
916 KB |
Output is correct |
13 |
Correct |
2 ms |
916 KB |
Output is correct |
14 |
Correct |
2 ms |
916 KB |
Output is correct |
15 |
Correct |
2 ms |
916 KB |
Output is correct |
16 |
Correct |
2 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
520 KB |
Output is correct |
5 |
Correct |
3 ms |
576 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
3 ms |
704 KB |
Output is correct |
8 |
Correct |
2 ms |
704 KB |
Output is correct |
9 |
Correct |
2 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
2 ms |
704 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
14 |
Correct |
2 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
704 KB |
Output is correct |
16 |
Correct |
2 ms |
736 KB |
Output is correct |
17 |
Correct |
2 ms |
1004 KB |
Output is correct |
18 |
Correct |
2 ms |
1076 KB |
Output is correct |
19 |
Correct |
3 ms |
1076 KB |
Output is correct |
20 |
Correct |
2 ms |
1076 KB |
Output is correct |
21 |
Correct |
4 ms |
1076 KB |
Output is correct |
22 |
Correct |
2 ms |
1076 KB |
Output is correct |
23 |
Correct |
3 ms |
1076 KB |
Output is correct |
24 |
Correct |
2 ms |
1076 KB |
Output is correct |
25 |
Correct |
3 ms |
1076 KB |
Output is correct |
26 |
Correct |
3 ms |
1076 KB |
Output is correct |
27 |
Correct |
3 ms |
1076 KB |
Output is correct |
28 |
Correct |
2 ms |
1076 KB |
Output is correct |
29 |
Correct |
3 ms |
1184 KB |
Output is correct |
30 |
Correct |
2 ms |
1184 KB |
Output is correct |
31 |
Correct |
2 ms |
1184 KB |
Output is correct |
32 |
Correct |
2 ms |
1184 KB |
Output is correct |
33 |
Correct |
2 ms |
1184 KB |
Output is correct |
34 |
Correct |
3 ms |
1184 KB |
Output is correct |
35 |
Correct |
2 ms |
1184 KB |
Output is correct |
36 |
Correct |
2 ms |
1240 KB |
Output is correct |
37 |
Correct |
3 ms |
1240 KB |
Output is correct |
38 |
Correct |
2 ms |
1240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
520 KB |
Output is correct |
5 |
Correct |
3 ms |
576 KB |
Output is correct |
6 |
Correct |
2 ms |
576 KB |
Output is correct |
7 |
Correct |
3 ms |
704 KB |
Output is correct |
8 |
Correct |
2 ms |
704 KB |
Output is correct |
9 |
Correct |
2 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
2 ms |
704 KB |
Output is correct |
13 |
Correct |
2 ms |
704 KB |
Output is correct |
14 |
Correct |
2 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
704 KB |
Output is correct |
16 |
Correct |
2 ms |
736 KB |
Output is correct |
17 |
Correct |
3 ms |
868 KB |
Output is correct |
18 |
Correct |
3 ms |
868 KB |
Output is correct |
19 |
Correct |
3 ms |
868 KB |
Output is correct |
20 |
Correct |
2 ms |
868 KB |
Output is correct |
21 |
Correct |
2 ms |
868 KB |
Output is correct |
22 |
Correct |
3 ms |
868 KB |
Output is correct |
23 |
Correct |
3 ms |
868 KB |
Output is correct |
24 |
Correct |
3 ms |
916 KB |
Output is correct |
25 |
Correct |
3 ms |
916 KB |
Output is correct |
26 |
Correct |
3 ms |
916 KB |
Output is correct |
27 |
Correct |
4 ms |
916 KB |
Output is correct |
28 |
Correct |
3 ms |
916 KB |
Output is correct |
29 |
Correct |
2 ms |
916 KB |
Output is correct |
30 |
Correct |
2 ms |
916 KB |
Output is correct |
31 |
Correct |
2 ms |
916 KB |
Output is correct |
32 |
Correct |
2 ms |
916 KB |
Output is correct |
33 |
Correct |
2 ms |
1004 KB |
Output is correct |
34 |
Correct |
2 ms |
1076 KB |
Output is correct |
35 |
Correct |
3 ms |
1076 KB |
Output is correct |
36 |
Correct |
2 ms |
1076 KB |
Output is correct |
37 |
Correct |
4 ms |
1076 KB |
Output is correct |
38 |
Correct |
2 ms |
1076 KB |
Output is correct |
39 |
Correct |
3 ms |
1076 KB |
Output is correct |
40 |
Correct |
2 ms |
1076 KB |
Output is correct |
41 |
Correct |
3 ms |
1076 KB |
Output is correct |
42 |
Correct |
3 ms |
1076 KB |
Output is correct |
43 |
Correct |
3 ms |
1076 KB |
Output is correct |
44 |
Correct |
2 ms |
1076 KB |
Output is correct |
45 |
Correct |
3 ms |
1184 KB |
Output is correct |
46 |
Correct |
2 ms |
1184 KB |
Output is correct |
47 |
Correct |
2 ms |
1184 KB |
Output is correct |
48 |
Correct |
2 ms |
1184 KB |
Output is correct |
49 |
Correct |
2 ms |
1184 KB |
Output is correct |
50 |
Correct |
3 ms |
1184 KB |
Output is correct |
51 |
Correct |
2 ms |
1184 KB |
Output is correct |
52 |
Correct |
2 ms |
1240 KB |
Output is correct |
53 |
Correct |
3 ms |
1240 KB |
Output is correct |
54 |
Correct |
2 ms |
1240 KB |
Output is correct |
55 |
Correct |
3 ms |
1240 KB |
Output is correct |
56 |
Correct |
2 ms |
1276 KB |
Output is correct |
57 |
Correct |
2 ms |
1276 KB |
Output is correct |
58 |
Correct |
2 ms |
1276 KB |
Output is correct |
59 |
Correct |
2 ms |
1440 KB |
Output is correct |
60 |
Correct |
2 ms |
1440 KB |
Output is correct |
61 |
Correct |
2 ms |
1440 KB |
Output is correct |
62 |
Correct |
2 ms |
1440 KB |
Output is correct |
63 |
Correct |
2 ms |
1440 KB |
Output is correct |
64 |
Correct |
3 ms |
1440 KB |
Output is correct |
65 |
Correct |
3 ms |
1440 KB |
Output is correct |
66 |
Correct |
2 ms |
1440 KB |
Output is correct |
67 |
Correct |
2 ms |
1440 KB |
Output is correct |
68 |
Correct |
3 ms |
1440 KB |
Output is correct |
69 |
Correct |
3 ms |
1440 KB |
Output is correct |
70 |
Correct |
2 ms |
1440 KB |
Output is correct |
71 |
Correct |
3 ms |
1440 KB |
Output is correct |
72 |
Correct |
3 ms |
1440 KB |
Output is correct |
73 |
Correct |
3 ms |
1440 KB |
Output is correct |
74 |
Correct |
3 ms |
1440 KB |
Output is correct |
75 |
Correct |
4 ms |
1440 KB |
Output is correct |
76 |
Correct |
3 ms |
1440 KB |
Output is correct |
77 |
Correct |
3 ms |
1440 KB |
Output is correct |
78 |
Correct |
3 ms |
1440 KB |
Output is correct |
79 |
Correct |
4 ms |
1440 KB |
Output is correct |
80 |
Correct |
2 ms |
1440 KB |
Output is correct |
81 |
Correct |
3 ms |
1440 KB |
Output is correct |
82 |
Correct |
3 ms |
1440 KB |
Output is correct |
83 |
Correct |
3 ms |
1440 KB |
Output is correct |
84 |
Correct |
3 ms |
1440 KB |
Output is correct |
85 |
Correct |
3 ms |
1452 KB |
Output is correct |
86 |
Correct |
2 ms |
1452 KB |
Output is correct |
87 |
Correct |
3 ms |
1452 KB |
Output is correct |
88 |
Correct |
3 ms |
1452 KB |
Output is correct |
89 |
Correct |
3 ms |
1452 KB |
Output is correct |
90 |
Correct |
3 ms |
1452 KB |
Output is correct |
91 |
Correct |
2 ms |
1468 KB |
Output is correct |
92 |
Correct |
3 ms |
1472 KB |
Output is correct |