제출 #102020

#제출 시각아이디문제언어결과실행 시간메모리
102020tincamateiJOIRIS (JOI16_joiris)C++14
100 / 100
4 ms464 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...