Submission #792362

#TimeUsernameProblemLanguageResultExecution timeMemory
792362Nhoksocqt1Doktor (COCI17_doktor)C++17
0 / 100
123 ms35020 KiB
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 500005; vector<int> B[MAXN]; int a[MAXN], sum[MAXN], cnt[4 * MAXN], nArr; void process() { cin >> nArr; for (int i = 1; i <= nArr; ++i) { cin >> a[i]; B[max(i, a[i])].push_back(min(i, a[i])); } int maxcnt(0), l(1), r(1); for (int i = 1; i <= nArr; ++i) { sum[i] = sum[i - 1]; for (int it = 0; it < sz(B[i]); ++it) { int j(B[i][it]); if(i != j) { ++cnt[i - 3 * j + 2 * MAXN]; int midc = ((i - j + 1) & 1) ? (a[j + (i - j + 1) / 2] == (j + (i - j + 1) / 2)) : 0; //cout << j << ' ' << i << ' ' << 3 * i - j << ' ' << cnt[3 * i - j + MAXN] << '\n'; if(maxcnt < cnt[i - 3 * j + 2 * MAXN] - sum[i] + sum[j - 1] + midc) { maxcnt = cnt[i - 3 * j + 2 * MAXN] - sum[i] + sum[j + 1] + midc; l = j, r = i; } } else { ++sum[i]; } } } if(maxcnt < sum[nArr]) { maxcnt = sum[nArr]; l = r = 1; } cout << a[l] << ' ' << a[r] << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); process(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...