Submission #87688

#TimeUsernameProblemLanguageResultExecution timeMemory
87688jasony123123Doktor (COCI17_doktor)C++11
100 / 100
317 ms42988 KiB
#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 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...