Submission #1025924

#TimeUsernameProblemLanguageResultExecution timeMemory
1025924vjudge1Doktor (COCI17_doktor)C++17
100 / 100
192 ms54204 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; int n, a[N], ind[N], pref[N]; vector<pair<int, int>> vec; vector<int> at[N]; void solve(){ cin >> n; for (int i = 1; i <= 2 * n; i += 2) cin >> a[i], a[i] = 2 * a[i] - 1, ind[a[i]] = i; for (int i = 1; i <= 2 * n; i += 2){ int l = i, r = ind[i]; if (l > r) swap(l, r); vec.push_back({l, r}); } sort(vec.begin(), vec.end()); for (int i = 0; i < vec.size(); i ++){ auto [l, r] = vec[i]; at[(l + r) / 2].push_back(i); } for (int i = 1; i <= 2 * n; i ++) pref[i] = pref[i - 1] + (a[i] == i); int mx = -1; pair<int, int> output; for (int i = 1; i <= 2 * n; i ++){ for (int j = 0; j < at[i].size(); j ++){ auto [l, r] = vec[at[i][j]]; int cnt = pref[l - 1] + (pref[2 * n] - pref[r]) + (at[i].size() - j); // cout << i << ", " << a[l] / 2 + 1 << " - " << a[r] / 2 + 1 << " : " << cnt << endl; if (mx < cnt){ mx = cnt; output = {a[l] / 2 + 1, a[r] / 2 + 1}; } } } cout << output.first << " " << output.second << endl; } int main(){ int t = 1; // cin >> t; while (t--) solve(); return 0; }

Compilation message (stderr)

doktor.cpp: In function 'void solve()':
doktor.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < vec.size(); i ++){
      |                     ~~^~~~~~~~~~~~
doktor.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for (int j = 0; j < at[i].size(); j ++){
      |                         ~~^~~~~~~~~~~~~~
#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...