이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, r, x;
	cin >> n >> r >> x;
	r %= (2*n);
	int b[2*n-1];
	for(int i = 0; i < 2*n-1; i++) cin >> b[i];
	int a[2][2*n];
	bool flag = 0;
	int mn = n-1, ans = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 2*n; j++) a[0][j] = 0;
		a[0][2*i] = x;
		int idx = 0;
		for(int j = 0; j < 2*n; j++) if(!a[0][j]) {
			a[0][j] = b[idx++];
		}
		flag = 0;
		for(int j = 0; j < 2*n+r; j++) {
			for(int k = 1; k < n; k++) {
				a[flag^1][2*(k-1)] = min(a[flag][2*k], a[flag][2*k+1]);
				a[flag^1][2*k+1] = max(a[flag][2*k], a[flag][2*k+1]);
			}
			a[flag^1][2*n-2] = max(a[flag][0], a[flag][1]);
			a[flag^1][1] = min(a[flag][0], a[flag][1]);
			flag ^= 1;
		}
		for(int j = 0; j < 2*n; j++) if(a[flag][j] == x) {
			if(j/2 < mn) {
				mn = j/2;
				ans = i;
			} else if(j/2 == mn) {
				ans = max(ans, i);
			}
		}
	}
	cout << ans+1;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |