Submission #235187

# Submission time Handle Problem Language Result Execution time Memory
235187 2020-05-27T09:13:26 Z NONAME Doktor (COCI17_doktor) C++17
100 / 100
395 ms 42872 KB
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define N 5 * 100500
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define el '\n'
using namespace std;

int n, pf[N], a[N], ans, al = 0, ar = 0;
vector <pair <int, int> > v[2 * N];

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++) {
		int l = i, r = a[i];
		
		if (l > r)
			swap(l, r);
			
		v[l + r].pb(mp(l, r));
	}
	
	for (int i = 0; i < 2 * n; i++) {
		sort(v[i].rbegin(), v[i].rend());
		for (int j = 0; j < sz(v[i]); j++) {
			int l = v[i][j].ft, r = v[i][j].sd;
			
			int cur = (j + 1) + (pf[n - 1] - pf[r]) + (l - 1 < 0 ? 0 : pf[l - 1]);

			if (cur > ans) {
				al = l;
				ar = r;
				ans = cur;	
			}
		}
	}
	
	cerr << ans << el;
	
	cout << a[al] + 1 << ' ' << a[ar] + 1;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 23936 KB Output is correct
2 Correct 18 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 19 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24064 KB Output is correct
2 Correct 19 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 24064 KB Output is correct
2 Correct 19 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24320 KB Output is correct
2 Correct 194 ms 30568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 26744 KB Output is correct
2 Correct 72 ms 25840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 395 ms 39416 KB Output is correct
2 Correct 309 ms 32104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 33048 KB Output is correct
2 Correct 266 ms 42872 KB Output is correct