Submission #182568

# Submission time Handle Problem Language Result Execution time Memory
182568 2020-01-10T01:40:37 Z FieryPhoenix Gondola (IOI14_gondola) C++11
100 / 100
50 ms 5512 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
#include <deque>
#include <cassert>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <chrono>
#include <ctime>
#include <random>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <iterator>
#include <climits>
#include "gondola.h"
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000009


int valid(int N, int arr[]){
  unordered_set<int>st;
  int pos=-1;
  for (int i=0;i<N;i++){
    if (st.count(arr[i]))
      return 0;
    st.insert(arr[i]);
    if (arr[i]<=N)
      pos=i;
  }
  if (pos==-1)
    return 1;
  for (int i=0;i<N;i++){
    int j=(pos+i)%N;
    int target=arr[pos]+i;
    if (target>N)
      target-=N;
    if (arr[j]<=N && arr[j]!=target)
      return 0;
  }
  return 1;
}


bool used[250001];
int should[100001];
 
int replacement(int N, int g[], int repl[]){
  int nex=0;
  for (int i=0;i<N;i++){
    should[i]=i+1;
    nex=max(nex,g[i]);
  }
  int pos=-1;
  for (int i=0;i<N;i++)
    if (g[i]<=N)
      pos=i;
  for (int i=pos;i<pos+N;i++){
    int x=g[pos]+i-pos;
    if (x>N) x-=N;
    should[i%N]=x;
  }
  vector<int>v;
  for (int i=0;i<N;i++)
    used[g[i]]=true;
  priority_queue<pair<int,int>>pq;
  for (int i=0;i<N;i++)
    pq.push({g[i],i});
  while (!pq.empty()){
    int ind=pq.top().second;
    pq.pop();
    if (g[ind]<=N)
      continue;
    while (used[nex])
      nex--;
    if (nex<=N)
      nex=should[ind];
    v.push_back(nex);
    used[nex]=true;
    g[ind]=nex;
    pq.push({g[ind],ind});
  }
  reverse(v.begin(),v.end());
  for (int i=0;i<(int)v.size();i++)
    repl[i]=v[i];
  return (int)v.size();
}

ll fastexp(ll base, ll exp){
  if (exp==0)
    return 1;
  ll temp=fastexp(base,exp/2);
  temp=(temp*temp)%MOD;
  if (exp%2==1)
    temp=(temp*base)%MOD;
  return temp;
}

int countReplacement(int n, int a[]){
  if (valid(n,a)==0)
    return 0;
  ll ans=1;
  vector<int>v;
  int mx=0;
  for (int i=0;i<n;i++)
    if (a[i]>n){
      mx=max(mx,a[i]);
      v.push_back(a[i]);
    }
  sort(v.begin(),v.end());
  for (int i=(int)v.size()-1;i>=0;i--){
    ll r=v[i]-1;
    ll l=n+1;
    if (i>0)
      l=v[i-1]+1;
    if (r>=l){
      ll num=(int)v.size()-i;
      ans=(ans*fastexp(num,r-l+1))%MOD;
    }
  }
  int pos=-1;
  for (int i=0;i<n;i++)
    if (a[i]<=n)
      pos=i;
  if (pos==-1)
    ans=(ans*n)%MOD;
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 12 ms 2092 KB Output is correct
7 Correct 13 ms 624 KB Output is correct
8 Correct 21 ms 3720 KB Output is correct
9 Correct 8 ms 1404 KB Output is correct
10 Correct 25 ms 4104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 12 ms 2088 KB Output is correct
7 Correct 14 ms 736 KB Output is correct
8 Correct 22 ms 3848 KB Output is correct
9 Correct 8 ms 1272 KB Output is correct
10 Correct 24 ms 4080 KB Output is correct
11 Correct 1 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 15 ms 1960 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 32 ms 4232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 252 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 22 ms 2132 KB Output is correct
12 Correct 25 ms 2288 KB Output is correct
13 Correct 32 ms 1776 KB Output is correct
14 Correct 22 ms 2160 KB Output is correct
15 Correct 50 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 296 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 36 ms 3848 KB Output is correct
10 Correct 31 ms 3496 KB Output is correct
11 Correct 12 ms 1400 KB Output is correct
12 Correct 15 ms 1912 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 4 ms 424 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 38 ms 3852 KB Output is correct
10 Correct 30 ms 3496 KB Output is correct
11 Correct 12 ms 1272 KB Output is correct
12 Correct 13 ms 1912 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 43 ms 4100 KB Output is correct
15 Correct 42 ms 5512 KB Output is correct
16 Correct 10 ms 1404 KB Output is correct
17 Correct 35 ms 4168 KB Output is correct
18 Correct 19 ms 2344 KB Output is correct