Submission #722591

# Submission time Handle Problem Language Result Execution time Memory
722591 2023-04-12T12:06:55 Z cig32 Doktor (COCI17_doktor) C++17
0 / 100
238 ms 45840 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;
  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);
      ans = max(ans, ps[l-1] + ps[n] - ps[r] + j+1);
    }
  }
  cout << ans << '\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:41: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]
   41 |     for(int j=0; j<v[i].size(); j++) {
      |                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 740 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 712 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1228 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 8648 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 238 ms 45840 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 115 ms 26988 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -