Submission #200937

#TimeUsernameProblemLanguageResultExecution timeMemory
200937SamAndDoktor (COCI17_doktor)C++17
100 / 100
271 ms45944 KiB
#include <bits/stdc++.h> using namespace std; #define m_p make_pair const int N = 500005; int n; int a[N]; int p[N]; vector<pair<int, int> > v[N + N]; int ans; int ansl, ansr; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) { p[i] = p[i - 1]; if (a[i] == i) ++p[i]; v[i + a[i]].push_back(m_p(min(i, a[i]), max(i, a[i]))); } ans = p[n]; ansl = ansr = 1; for (int i = 0; i <= n + n; ++i) { sort(v[i].begin(), v[i].end()); reverse(v[i].begin(), v[i].end()); for (int j = 0; j < v[i].size(); ++j) { int l = v[i][j].first, r = v[i][j].second; if ((j + 1) + p[n] - (p[r] - p[l - 1]) > ans) { ans = (j + 1) + p[n] - (p[r] - p[l - 1]); ansl = l; ansr = r; } } } printf("%d %d\n", a[ansl], a[ansr]); return 0; }

Compilation message (stderr)

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