Submission #381385

#TimeUsernameProblemLanguageResultExecution timeMemory
381385IldarKADoktor (COCI17_doktor)C++14
100 / 100
793 ms57068 KiB
#include <bits/stdc++.h> using namespace std; int n, a[500001], pref[500001]; map < pair < int, int >, vector < pair < int, int > > > m; int get_sum(int l, int r){ if((r - l) % 2 == 0){ return pref[r] - pref[l - 1] - int(a[(r + l) / 2] == (r + l) / 2); } else{ return pref[r] - pref[l - 1]; } } int main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; int len = abs(a[i] - i); m[{(len + 1) / 2 + min(a[i], i), max(a[i], i) - (len + 1) / 2}].push_back({min(a[i], i), max(a[i], i)}); pref[i] += pref[i - 1] + int(a[i] == i); } int l = 1, r = 1; int mx = pref[n]; for(auto it : m){ sort(it.second.begin(), it.second.end()); int kol = (int)it.second.size(); for(int i = 0; i < it.second.size(); i++){ int san = get_sum(it.second[i].first, it.second[i].second); if(pref[n] - san + kol > mx){ mx = pref[n] - san + kol; l = it.second[i].first; r = it.second[i].second; } kol--; } } cout << a[l] << " " << a[r]; }

Compilation message (stderr)

doktor.cpp: In function 'int main()':
doktor.cpp:27:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i = 0; i < it.second.size(); 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...