Submission #87688

# Submission time Handle Problem Language Result Execution time Memory
87688 2018-12-01T22:46:16 Z jasony123123 Doktor (COCI17_doktor) C++11
100 / 100
317 ms 42988 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define vsort(a) sort(a.begin(), a.end());
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf

typedef long long ll;
typedef pair<int, int > pii;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void io();

const int MAXN = 500010;

int N;
int A[MAXN];
int pref[MAXN];
v<pii> splits[MAXN * 2];

int main() {
	io();
	cin >> N;
	FORE(i, 1, N) {
		cin >> A[i];
		pii swit = { i, A[i] };
		if (i > A[i])
			swap(swit.first, swit.second);
		splits[i + A[i]].push_back(swit);
		pref[i] = pref[i - 1] + (i == A[i] ? 1 : 0);
	}

	int ans = pref[N];
	pii best = { 1,1 };

	FORE(s, 2, 2 * N) if (splits[s].size() > 0) {
		sort(splits[s].begin(), splits[s].end(), greater<pii>());
		FOR(i, 0, splits[s].size()) {
			pii intv = splits[s][i];
			int numG = i + 1 + pref[N] - (pref[intv.second] - pref[intv.first - 1]);
			if (numG > ans) {
				ans = numG;
				best = intv;
			}
		}
	}

	cout << A[best.first] << " " << A[best.second] << "\n";
	return 0;
}


void io() {
#ifdef LOCAL_PROJECT
	freopen("a.in", "r", stdin);
	//freopen("a.out","w",stdout); // console output is better (in most cases)
#else
	// add i/o method of specific testing system
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23936 KB Output is correct
2 Correct 24 ms 23952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 24028 KB Output is correct
2 Correct 23 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24260 KB Output is correct
2 Correct 26 ms 24260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24260 KB Output is correct
2 Correct 27 ms 24260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 24452 KB Output is correct
2 Correct 109 ms 30428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 30428 KB Output is correct
2 Correct 46 ms 30428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 317 ms 39604 KB Output is correct
2 Correct 155 ms 39604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 39604 KB Output is correct
2 Correct 131 ms 42988 KB Output is correct