# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
722592 |
2023-04-12T12:08:24 Z |
cig32 |
Doktor (COCI17_doktor) |
C++17 |
|
255 ms |
48800 KB |
#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
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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
724 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1108 KB |
Output is correct |
2 |
Correct |
106 ms |
23660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
8068 KB |
Output is correct |
2 |
Correct |
33 ms |
7948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
255 ms |
42652 KB |
Output is correct |
2 |
Correct |
155 ms |
38976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
25024 KB |
Output is correct |
2 |
Correct |
90 ms |
48800 KB |
Output is correct |