Submission #722592

#TimeUsernameProblemLanguageResultExecution timeMemory
722592cig32Doktor (COCI17_doktor)C++17
100 / 100
255 ms48800 KiB
#include "bits/stdc++.h" using namespace std; #define int long long const int MAXN = 2e5 + 10; const int MOD = 998244353; mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count()); int rnd(int x, int y) { int u = uniform_int_distribution<int>(x, y)(rng); return u; } int bm(int b, int p) { if(p==0) return 1 % MOD; int r = bm(b, p >> 1); if(p&1) return (((r*r) % MOD) * b) % MOD; return (r*r) % MOD; } int inv(int b) { return bm(b, MOD-2); } int fastlog(int x) { return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1); } void printcase(int i) { cout << "Case #" << i << ": "; } int bruh; bool cmp(int x, int y) { return abs(bruh - x * 2) < abs(bruh - y * 2); } void solve(int tc) { int n; cin >> n; int p[n+1]; for(int i=1; i<=n; i++) cin >> p[i]; vector<int> v[2*n+1]; for(int i=1; i<=n; i++) v[p[i]+i].push_back(i); int ps[n+1]; ps[0] = 0; for(int i=1; i<=n; i++) ps[i] = ps[i-1] + (p[i] == i); int ans = 0; int optl, optr; for(int i=1; i<=2*n; i++) { bruh = i; sort(v[i].begin(), v[i].end(), cmp); for(int j=0; j<v[i].size(); j++) { int l = v[i][j]; int r = (i < v[i][j] * 2 ? i - (v[i][j] * 2 - i) : i + (i - v[i][j] * 2)) / 2; if(l > r) swap(l, r); if(ps[l-1] + ps[n] - ps[r] + j+1 > ans) { ans = ps[l-1] + ps[n] - ps[r] + j+1; optl = p[l], optr = p[r]; } } } cout << optl << ' ' << optr << '\n'; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; for(int i=1; i<=t; i++) solve(i); }

Compilation message (stderr)

doktor.cpp: In function 'void solve(long long int)':
doktor.cpp:42:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int j=0; j<v[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...