Submission #116983

#TimeUsernameProblemLanguageResultExecution timeMemory
116983FutymyCloneDoktor (COCI17_doktor)C++14
100 / 100
268 ms44704 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 5; int n, a[N], f[N], p[N]; vector <pair <int, int> > vec[N + N]; int main(){ scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { int x = i - a[i]; p[a[i]] = i; vec[2 * i - 1 - x].push_back({min(i, a[i]), max(i, a[i])}); f[i] = f[i - 1] + (a[i] == i); } int Max = -1, ans1 = 0, ans2 = 0; for (int i = 1; i <= 2 * n - 1; i++) { sort(vec[i].begin(), vec[i].end(), greater <pair <int, int> >()); for (int j = 0; j < vec[i].size(); j++) { int res = j + 1 - (f[vec[i][j].second] - f[vec[i][j].first - 1]); if (res > Max) { Max = res; ans1 = a[vec[i][j].first]; ans2 = a[vec[i][j].second]; } } } if (p[ans1] > p[ans2]) swap(ans1, ans2); cout << ans1 << " " << ans2; return 0; }

Compilation message (stderr)

doktor.cpp: In function 'int main()':
doktor.cpp:23:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < vec[i].size(); j++) {
                         ~~^~~~~~~~~~~~~~~
doktor.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
doktor.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
#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...