답안 #287955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287955 2020-09-01T07:13:30 Z 임성재(#5782) JOIRIS (JOI16_joiris) C++17
0 / 100
0 ms 384 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = 1e9 + 7;

int n, k;
int a[55];
vector<pii> ans;

bool chk() {
	//for(int i=1; i<=n; i++)
		//cout << a[i] << " ";

	//cout << endl;

	for(int i=2; i<=n; i++) {
		if(a[i] != a[1]) return true;
	}

	return false;
}

void qr(int tmp, int x) {
	if(tmp == 1) {
		a[x] += k;
	}
	else {
		for(int i=x; i<x + k; i++)
			a[i]++;
	}

	ans.eb(tmp, x);

	if(ans.size() > 10) {
		cout << -1;
		exit(0);
	}

	if(!chk()) {
		cout << ans.size() << "\n";

		for(auto i : ans) {
			cout << i.fi << " " << i.se << "\n";
		}

		exit(0);
	}
}

void f() {
	for(int i=n-1; i>=1; i--) {
		while(a[i] <= a[i+1]-2) {
			qr(1, i);
		}
	}
}

int main() {
	fast;

	cin >> n >> k;

	for(int i=1; i<=n; i++) {
		cin >> a[i];
	}

	for(int i=2; i<=n; i++) {
		while(a[i-1] > a[i]) {
			qr(1, i);
		}
	}

	f();

	int cnt = 0;
	int p = -1;

	while((int) ans.size() > p) {
		p = ans.size();

		int cur = 1;
		for(int i=1; i<=n; i++) {
			if(i < n && a[i] == a[i+1]) continue;

			for(int j=i; cur <= j-k+1; j-=k) {
				qr(2, j-k+1);
			}

			if(ans.size()) cur = ans.back().se;
			if(a[cur] != a[i]) cur = i;
		}

		if(k < n && a[k] != a[k+1]) {
			qr(2, 1);
		}

		f();
	}

	cout << -2;
}

Compilation message

joiris.cpp: In function 'int main()':
joiris.cpp:88:6: warning: unused variable 'cnt' [-Wunused-variable]
   88 |  int cnt = 0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -