Submission #235127

# Submission time Handle Problem Language Result Execution time Memory
235127 2020-05-27T06:48:40 Z NONAME Doktor (COCI17_doktor) C++17
40 / 100
1000 ms 4220 KB
#include <bits/stdc++.h>
#define N 5 * 100500
using namespace std;

int n, pf[N], a[N], ans, al = 0, ar = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
		pf[i] = (i - 1 < 0) ? 0 : pf[i - 1];
		
		pf[i] += (a[i] == i);	
	}
	
	for (int i = 0; i < n; i++)
	for (int j = i; j < n; j++) {
		int l = i, r = j, cur = 0;
		
		while (l < r) {
			cur += (a[l] == r);
			cur += (a[r] == l);
			
			l++, r--;
		}
		
		if (l == r && a[l] == l)
			cur++;
			
		cur += (i - 1 < 0) ? 0 : pf[i - 1];
		cur += (pf[n - 1] - pf[j]);
			
		if (cur > ans) {
			ans = cur;
			al = i;
			ar = j;	
		}
	}
	
	cout << a[al] + 1 << ' ' << a[ar] + 1;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 14 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 903 ms 504 KB Output is correct
2 Correct 565 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 1016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 4220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 2552 KB Time limit exceeded
2 Halted 0 ms 0 KB -