Submission #932754

# Submission time Handle Problem Language Result Execution time Memory
932754 2024-02-24T06:38:13 Z vjudge1 Gondola (IOI14_gondola) C++17
100 / 100
20 ms 3664 KB
#include<bits/stdc++.h>
 
#pragma GCC optimize("Ofast")
 
using namespace std;
 
#define F first
#define S second
#define ll long long
// #define int ll
#define pb push_back
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define mem(a,i) memset(a,i,sizeof(a))
#define in insert
#define lb lower_bound
#define ub upper_bound
#define y1 yy
#define ppb pop_back
#define ull unsigned ll
 
const int MAX=3e6+55;
const int inf=1e9;
const int N=2e5;
const int C=331;
const int C1=431;
const int mod=1e9+9;
const int mod1=1e9+9;
#include "gondola.h"

int pos[MAX];

int valid(int n, int a[])
{
  int mn=0;
  for(int i=0;i<n;i++){
    if(a[i]<a[mn])mn=i;
    // pos[a[i]]=i;
  }
  vector<int> v;
  for(int i=mn;i<n;i++){
    if(a[i]<=n){
      v.pb(a[i]);
      pos[a[i]]=i-mn;
    }
  }
  for(int i=0;i<mn;i++){
    if(a[i]<=n){
      v.pb(a[i]);
      pos[a[i]]=n-mn+i;
    }
  }
  for(int i=1;i<sz(v);i++){
    if(v[i]<=v[i-1]||v[i]-v[i-1]!=pos[v[i]]-pos[v[i-1]])return 0;
  }
  sort(a,a+n);
  for(int i=1;i<n;i++){
    if(a[i]==a[i-1])return 0;
  }
  return 1;
}


int replacement(int n, int a[], int q[])
{
  vector<pii> v;
  bool ok=0;
  for(int i=0;i<n;i++){
    if(a[i]<=n){
      ok=1;
      int st=i-a[i]+1;
      if(st<0)st+=n;
      // cout<<st<<"\n";
      for(int j=st;j<n;j++)if(a[j]>n)v.pb({a[j],j-st+1});
      for(int j=0;j<st;j++)if(a[j]>n)v.pb({a[j],n-st+j+1});
      break;
    }
  }
  if(!ok){
    for(int i=0;i<n;i++){
      v.pb({a[i],i+1});
    }
  }
  sort(all(v));
  int pos=0;
  int r=n+1;
  // cout<<sz(v)<<"\n";
  for(int i=0;i<sz(v);i++){
    q[pos++]=v[i].S;
    // cout<<r<<" "<<v[i].F;
    while(r<v[i].F){
      q[pos++]=r++;
    }
    r++;
  }
  return pos;
}

int binpow(int a,int n){
  if(n==0)return 1;
  if(n%2==1)return a*1ll*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*1ll*k%mod;
}

//----------------------
int countReplacement(int n, int a[])
{
  ll ans=1;
  if(!valid(n,a))return 0;
  vector<int> v;
  for(int i=0;i<n;i++){
    if(a[i]>n){
      v.pb(a[i]);
    }
  }
  sort(all(v));
  int r=n+1;
  for(int i=0;i<sz(v);i++){
    // cout<<sz(v)-i<<" "<<v[i]-r<<" "<<binpow(sz(v)-i,v[i]-r)<<"\n";
    ans=ans*1ll*binpow(sz(v)-i,v[i]-r)%mod;
    r=v[i]+1;
  }
  if(sz(v)==n)ans=ans*1ll*n%mod;
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 7 ms 3544 KB Output is correct
8 Correct 8 ms 3544 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 12 ms 3544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 6 ms 1116 KB Output is correct
7 Correct 8 ms 3604 KB Output is correct
8 Correct 8 ms 3544 KB Output is correct
9 Correct 4 ms 600 KB Output is correct
10 Correct 12 ms 3520 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 7 ms 3288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2496 KB Output is correct
10 Correct 1 ms 2648 KB Output is correct
11 Correct 6 ms 1416 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 11 ms 3236 KB Output is correct
14 Correct 6 ms 1112 KB Output is correct
15 Correct 20 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 11 ms 3236 KB Output is correct
10 Correct 9 ms 3224 KB Output is correct
11 Correct 4 ms 600 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 14 ms 3288 KB Output is correct
10 Correct 10 ms 3224 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 15 ms 1236 KB Output is correct
15 Correct 16 ms 1448 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 11 ms 984 KB Output is correct
18 Correct 8 ms 860 KB Output is correct