Submission #549251

# Submission time Handle Problem Language Result Execution time Memory
549251 2022-04-15T12:50:33 Z xdfactor2034 Doktor (COCI17_doktor) C++17
0 / 100
59 ms 11776 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5+5;
int ar[maxn], lk[maxn];
int wl[maxn], wr[maxn];
int dpl[maxn], dpr[maxn];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> ar[i], lk[ar[i]] = i;
	for(int i = 1; i <= N; i++) {
		int score = i - ar[i];
		if(score >= 0) wl[i] = score, wr[i] = -1; else wl[i] = -1, wr[i] = -score;
	}
	int glob = 0;
	for(int i = 1; i <= N; i++) if(ar[i] == i) glob++;
	for(int i = 1; i <= N; i++) dpl[i] = (wl[i-1] + 2 == wl[i]) ? dpl[i-1]+1 : 1;
	for(int i = N; i >= 1; i--) dpr[i] = (wr[i+1] + 2 == wl[i]) ? dpr[i+1]+1 : 1;
	int bg = 1;
	int res = 0;
	int a = -1, b = -1;
	for(int i = 1; i <= N; i++) {
		if(dpl[i] >= dpl[i+1]) {
			int old = 0;
			for(int j = bg; j <= i; j++) if(ar[j] == j) old++;
			glob -= old;
			reverse(ar+bg, ar+i+1);
			int next = 0;
			for(int j = bg; j <= i; j++) if(ar[j] == j) next++;
			if(glob + next > res) res = glob+next, a = ar[bg], b = ar[i];
			glob += old;
			bg = i+1;
		}
	}
	int en = N;
	for(int i = N; i >= 1; i--) {
		if(dpr[i] >= dpr[i-1]) {
			int old = 0;
			for(int j = i; j <= en; j++) if(ar[j] == j) old++;
			glob -= old;
			reverse(ar+i, ar+en+1);
			int next = 0;
			for(int j = i; j <= en; j++) if(ar[j] == j) next++;
			if(glob + next > res) res = glob+next, a = ar[i], b = ar[en];
			glob += old;
			en = i-1;
		}
	}

	cout << a << ' ' << b << '\n'; 
}
# Verdict Execution time Memory Grader output
1 Failed 0 ms 340 KB Checker failed - contact admins or jury
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 1 ms 340 KB Checker failed - contact admins or jury
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Integer -1 violates the range [1, 4500]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Failed 2 ms 596 KB Checker failed - contact admins or jury
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 2404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 11776 KB Integer -1 violates the range [1, 490000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 6988 KB Output isn't correct
2 Halted 0 ms 0 KB -