Submission #102020

# Submission time Handle Problem Language Result Execution time Memory
102020 2019-03-21T15:01:31 Z tincamatei JOIRIS (JOI16_joiris) C++14
100 / 100
4 ms 464 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 50;
const int MOVE_LIMIT = 10000;
int a[1+MAX_N+1], dif[1+MAX_N+1];

int top;
int t[MOVE_LIMIT], x[MOVE_LIMIT];

void pushMove(int _t, int _x) {
	assert(top < MOVE_LIMIT);
	t[top] = _t;
	x[top++] = _x;
}

// Horizontal Long bar at i
void solveDif(int n, int k, int i) {
	int level = 0;
	for(int j = 0; j < k; ++j)
		if(a[i + j] > level)
			level = a[i + j];
	
	pushMove(2, i);

	for(int j = 1; j <= n; ++j)
		while((j < i || j >= i + k) && a[j] <= level) {
			a[j] += k;
			pushMove(1, j);
		}
	
	for(int j = 1; j <= n; ++j)
		if(j < i || j >= i + k)
			a[j]--;
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n, k;

	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	
	// relevel k-multiples
	for(int i = n / k * k; i > 0; i -= k) {
		while(i < n && a[i] % k != a[i + 1] % k)
			solveDif(n, k, i - k + 1);
	}
	
	if(n % k != 0)
		for(int i = n % k; i < n; i += k)
			while(a[i] % k != a[i + 1] % k)
				solveDif(n, k, i + 1);

	// relevel where it's necesarry
	for(int i = 1; i <= n - k; ++i) {
		while(a[i] % k != a[i + 1] % k)
			solveDif(n, k, i + 1);
	}
	
	int maxlvl = 0;
	for(int i = 1; i <= n; ++i)
		if(a[i] > maxlvl)
			maxlvl = a[i];
	for(int i = 1; i <= n; ++i)
		while(a[i] < maxlvl) {
			pushMove(1, i);
			a[i] += k;
		}
	
	int i = 1;
	while(i < n && a[i] == a[i + 1])
		i++;
	
	if(i == n) {
		printf("%d\n", top);
		for(int j = 0; j < top; ++j)
			printf("%d %d\n", t[j], x[j]);
	} else
		printf("-1");

	fclose(fin);
	fclose(fout);
	return 0;
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
joiris.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 256 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 464 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 3 ms 384 KB Output is correct
34 Correct 3 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 256 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 3 ms 384 KB Output is correct
29 Correct 3 ms 256 KB Output is correct
30 Correct 3 ms 384 KB Output is correct
31 Correct 3 ms 464 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 256 KB Output is correct
39 Correct 3 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 3 ms 384 KB Output is correct
42 Correct 3 ms 384 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 256 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 3 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 256 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 2 ms 384 KB Output is correct
56 Correct 3 ms 384 KB Output is correct
57 Correct 2 ms 256 KB Output is correct
58 Correct 2 ms 256 KB Output is correct
59 Correct 2 ms 384 KB Output is correct
60 Correct 2 ms 256 KB Output is correct
61 Correct 3 ms 384 KB Output is correct
62 Correct 2 ms 384 KB Output is correct
63 Correct 2 ms 256 KB Output is correct
64 Correct 2 ms 384 KB Output is correct
65 Correct 2 ms 384 KB Output is correct
66 Correct 2 ms 128 KB Output is correct
67 Correct 3 ms 384 KB Output is correct
68 Correct 3 ms 256 KB Output is correct
69 Correct 0 ms 384 KB Output is correct
70 Correct 3 ms 384 KB Output is correct
71 Correct 3 ms 384 KB Output is correct
72 Correct 3 ms 384 KB Output is correct
73 Correct 3 ms 384 KB Output is correct
74 Correct 3 ms 384 KB Output is correct
75 Correct 3 ms 384 KB Output is correct
76 Correct 3 ms 384 KB Output is correct
77 Correct 2 ms 384 KB Output is correct
78 Correct 3 ms 384 KB Output is correct
79 Correct 3 ms 384 KB Output is correct
80 Correct 2 ms 384 KB Output is correct
81 Correct 3 ms 384 KB Output is correct
82 Correct 2 ms 384 KB Output is correct
83 Correct 2 ms 384 KB Output is correct
84 Correct 3 ms 256 KB Output is correct
85 Correct 2 ms 256 KB Output is correct
86 Correct 3 ms 256 KB Output is correct
87 Correct 2 ms 384 KB Output is correct
88 Correct 2 ms 256 KB Output is correct
89 Correct 2 ms 384 KB Output is correct
90 Correct 2 ms 384 KB Output is correct
91 Correct 3 ms 384 KB Output is correct
92 Correct 4 ms 384 KB Output is correct