답안 #287924

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287924 2020-09-01T06:48:33 Z 임성재(#5782) Skyscraper (JOI16_skyscraper) C++17
0 / 100
1 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=2; i<=n; i++) {
		if(a[i] != a[1]) return true;
	}

	return false;
}

void f() {
	for(int i=n-1; i>=1; i--) {
		while(a[i] <= a[i+1]-2) {
			a[i] += k;
			ans.eb(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]) {
			a[i] += k;
			ans.eb(1, i);
		}
	}

	f();

	int cnt = 0;
	int p = -1;

	while(chk() && ans.size() < 10000 && (int) ans.size() > p) {
		p = ans.size();
		for(int i=1; i+k<=n; i++) {
			if(a[i] == a[i+k-1] && a[i] < a[i+k]) {
				ans.eb(2, i);

				for(int j=i; j<i+k; j++)
					a[j]++;
			}
		}

		if(k < n && a[k] != a[k+1]) {
			ans.eb(2, 1);

			for(int i=k+1; i<=n; i++) a[i]--;
		}

		f();
	}

	if(ans.size() >= 10000 || chk()) {
		cout << -1;
		return 0;
	}

	cout << ans.size() << "\n";

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

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:58:6: warning: unused variable 'cnt' [-Wunused-variable]
   58 |  int cnt = 0;
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 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 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -