Submission #235126

# Submission time Handle Problem Language Result Execution time Memory
235126 2020-05-27T06:47:23 Z NONAME Doktor (COCI17_doktor) C++17
30 / 100
1000 ms 4088 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[i]);
			
		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 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 898 ms 388 KB Output is correct
2 Correct 563 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1099 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 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 1095 ms 1016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 4088 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -