답안 #197374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197374 2020-01-20T15:51:18 Z Neklixx Doktor (COCI17_doktor) C++14
100 / 100
268 ms 49076 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define sh cin.tie(0); cin.sync_with_stdio(0); cout.tie(0);
#define FILE freopen("test.in", "r", stdin);
#define vprint(v) for (int ii = 0; ii < v.size(); ii++){cout << v[ii] << " ";}
#define debugv(v) if (v.size() != 0) {cout << "[ "; for (int __ = 0; __ < (int)(v.size()) - 1; __++){cout << v[__] << ", ";} cout << v[(int)(v.size()) - 1] << " ]" << endl;} else {cout << "[]" << endl;}
#define debug cout << "-----------------------------------------------" << endl;
#define print1(a) cout << "{ " << a << " }" << endl;
#define print2(a, b) cout << "{ " << a << ", " << b << " }" << endl;
#define print3(a, b, c) cout << "{ " << a << ", " << b << ", " << c << " }" << endl;
#define print4(a, b, c, d) cout << "{ " << a << ", " << b << ", " << c << ", " << d << " }" << endl;
using namespace std;
//#define int long long
const int INF = 1e9 + 228;
const int MAXN = 5e5 + 228;
vector<int> rot[MAXN][2];
int pos[MAXN];
signed main()
{
#ifdef LOCAL
    FILE;
#endif
    sh;
	int n;
	cin >> n;
	//assert(n != 2);
	vector<int> v;
	for (int i = 0; i < n; i++) {
		int aa;
		cin >> aa;
		v.pb(aa - 1);
	}    
	for (int i = 0; i < n; i++) {
		int nw = v[i];
		pos[nw] = i;
		int len = abs(nw - i) + 1;
		int mid = min(nw, i) + len / 2;
		mid--;
		//print4(i, nw, mid, len);
		rot[mid + (len % 2)][len % 2].pb(min(nw, i));
	}
	for (int i = 0; i < n; i++) {
		sort(all(rot[i][0]));sort(all(rot[i][1]));reverse(all(rot[i][1]));reverse(all(rot[i][0]));
	}
	vector<int> p;
	p.pb(0);
	for (int i = 0; i < n; i++) {
		p.pb(p[i] + (v[i] == i));
	}
	int mx = 0, l = 0, r = 0;
	for (int mid = 0; mid < n; mid++) {
		int now = 0;
		int re = 0;
		for (auto to : rot[mid][0]) {
			now++;
			re = now - (p[mid + mid - to + 2] - p[to]);
			if (re > mx) {
				mx = re;
				l = to;
				r = mid + mid - to + 1;
				//print4(mid, re, l, r);
			} 
		}
		//print1(mx);
		now = 0;
		re = 0;
		for (auto to : rot[mid][1]) {
			now++;
			re = now - (p[mid + mid - to + 1] - p[to]);
			if (re > mx) {
				mx = re;
				l = to;
				r = mid + mid - to;
			} 
		}
		//print1(mx);
	}
	cout << v[l] + 1 << ' ' << v[r] + 1 << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 23800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 30 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 23860 KB Output is correct
2 Correct 26 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 24060 KB Output is correct
2 Correct 25 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 24056 KB Output is correct
2 Correct 25 ms 23804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 24312 KB Output is correct
2 Correct 108 ms 32484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 27380 KB Output is correct
2 Correct 51 ms 26476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 268 ms 42064 KB Output is correct
2 Correct 160 ms 36068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 35752 KB Output is correct
2 Correct 133 ms 49076 KB Output is correct