Submission #826910

# Submission time Handle Problem Language Result Execution time Memory
826910 2023-08-16T06:25:09 Z 반딧불(#10373) JOIRIS (JOI16_joiris) C++17
15 / 100
1 ms 300 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
int arr[52];

void subtask1();
void subtask2();

int main(){
	scanf("%d %d", &n, &k);
	for(int i=1; i<=n; i++) scanf("%d", &arr[i]);

	if(k==2){
		if(n%2==0) subtask1();
		else subtask2();
	}
}

vector<pair<int, int> > ans;

void subtask1(){
	if(accumulate(arr+1, arr+n+1, 0) % 2){
		puts("-1");
		exit(0);
	}

	for(int i=1; i<=n; i++){
		while(arr[i] < arr[i-1]){
			ans.push_back(make_pair(1, i));
			arr[i] += 2;
		}
	}

	int minV = *min_element(arr+1, arr+n+1);
	for(int i=1; i<=n; i++) arr[i] -= minV;

	for(int i=1; i<n; i++){
		int v = arr[i+1] - arr[i];
		for(int j=i-1; j>=1; j-=2) for(int c=0; c<v; c++) ans.push_back(make_pair(2, j));
		if(i%2==0) for(int j=i+1; j<=n; j++) arr[j] -= v;
		else for(int j=2; j<=i; j++) arr[j] += v;
	}

	int v = (arr[2] - arr[1]) / 2;
	for(int i=0; i<v; i++) ans.push_back(make_pair(1, 1));

	printf("%d\n", (int)ans.size());
	for(auto p: ans){
		printf("%d %d\n", p.first, p.second);
	}
}

void subtask2(){
	for(int i=1; i<=n; i++){
		while(arr[i] < arr[i-1]){
			ans.push_back(make_pair(1, i));
			arr[i] += 2;
		}
	}

	int minV = *min_element(arr+1, arr+n+1);
	for(int i=1; i<=n; i++) arr[i] -= minV;

	for(int i=1; i<n; i++){
		int v = arr[i+1] - arr[i];
		for(int j=i-1; j>=1; j-=2) for(int c=0; c<v; c++) ans.push_back(make_pair(2, j));
		if(i%2==0) for(int j=i+1; j<=n; j++) arr[j] -= v;
		else for(int j=2; j<=i; j++) arr[j] += v;
	}

	int v = (arr[2] - arr[1]) / 2;
	for(int i=0; i<v; i++) ans.push_back(make_pair(1, 1));

	if(arr[1] != arr[2]){
		ans.push_back(make_pair(1, 1));
		for(int i=2; i<n; i+=2) ans.push_back(make_pair(2, i));
	}

	printf("%d\n", (int)ans.size());
	for(auto p: ans){
		printf("%d %d\n", p.first, p.second);
	}
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d %d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~
joiris.cpp:15:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  for(int i=1; i<=n; i++) scanf("%d", &arr[i]);
      |                          ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 296 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Incorrect 0 ms 212 KB Unexpected end of file - int32 expected
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 296 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -