Submission #118081

# Submission time Handle Problem Language Result Execution time Memory
118081 2019-06-18T06:49:00 Z dragonslayerit Gondola (IOI14_gondola) C++14
100 / 100
139 ms 6008 KB
#include "gondola.h"
#include <set>
#include <vector>
#include <algorithm>
#include <cstdio>

const int MOD=1e9+9;

int modpow(int base,int exp){
  int ac=1;
  for(;exp>0;exp>>=1){
    if(exp&1){
      ac=1LL*ac*base%MOD;
    }
    base=1LL*base*base%MOD;
  }
  return ac;
}

int valid(int n, int inputSeq[])
{
  int shift=-1;
  std::set<int> used;
  for(int i=0;i<n;i++){
    if(used.count(inputSeq[i])) return 0;
    used.insert(inputSeq[i]);
    if(inputSeq[i]<=n){
      int new_shift=(inputSeq[i]-i+n)%n;
      if(shift!=-1&&shift!=new_shift) return 0;
      shift=new_shift;
    }
  }
  return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  for(int i=0;i<n;i++){
    gondolaSeq[i]--;
  }
  int shift=0;
  for(int i=0;i<n;i++){
    if(gondolaSeq[i]<n){
      shift=(gondolaSeq[i]-i+n)%n;
      break;
    }
  }
  std::vector<int> seq(n);
  for(int i=0;i<n;i++){
    seq[i]=(i+shift)%n;
  }
  auto max=std::max_element(gondolaSeq,gondolaSeq+n);
  std::vector<int> where(*max+1,max-gondolaSeq);
  for(int i=0;i<n;i++){
    where[gondolaSeq[i]]=i;
  }
  for(int x=n;x<=*max;x++){
    replacementSeq[x-n]=seq[where[x]];
    seq[where[x]]=x;
  }
  int l=*max+1-n;
  for(int i=0;i<l;i++){
    replacementSeq[i]++;
  }
  return l;
}

//----------------------

int countReplacement(int n, int inputSeq[])
{
  if(!valid(n,inputSeq)) return 0;
  for(int i=0;i<n;i++){
    inputSeq[i]--;
  }
  int shift=-1;
  for(int i=0;i<n;i++){
    if(inputSeq[i]<n){
      shift=(inputSeq[i]-i+n)%n;
      break;
    }
  }
  std::set<int> set;
  int cnt=(shift==-1)?n:1;
  int spots=n;
  for(int i=0;i<n;i++){
    if(inputSeq[i]<n){
      spots--;
    }else{
      set.insert(inputSeq[i]);
    }
  }
  int prev=n-1;
  for(int x:set){
    cnt=1LL*cnt*modpow(spots,x-1-prev)%MOD;
    prev=x;
    spots--;
  }
  return cnt;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 17 ms 2304 KB Output is correct
7 Correct 11 ms 768 KB Output is correct
8 Correct 30 ms 3960 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 39 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 17 ms 2304 KB Output is correct
7 Correct 12 ms 768 KB Output is correct
8 Correct 31 ms 4088 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 40 ms 4600 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 7 ms 512 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 12 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 300 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 11 ms 1380 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 15 ms 1408 KB Output is correct
14 Correct 10 ms 1280 KB Output is correct
15 Correct 18 ms 2332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 80 ms 4420 KB Output is correct
10 Correct 59 ms 3736 KB Output is correct
11 Correct 21 ms 1620 KB Output is correct
12 Correct 24 ms 1792 KB Output is correct
13 Correct 7 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 284 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 70 ms 4392 KB Output is correct
10 Correct 49 ms 3576 KB Output is correct
11 Correct 19 ms 1664 KB Output is correct
12 Correct 25 ms 1820 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 127 ms 5448 KB Output is correct
15 Correct 139 ms 6008 KB Output is correct
16 Correct 16 ms 1360 KB Output is correct
17 Correct 74 ms 4248 KB Output is correct
18 Correct 34 ms 2424 KB Output is correct