Submission #118073

# Submission time Handle Problem Language Result Execution time Memory
118073 2019-06-18T06:33:03 Z dragonslayerit Gondola (IOI14_gondola) C++14
90 / 100
290 ms 262144 KB
#include "gondola.h"
#include <set>
#include <vector>
#include <algorithm>
#include <cstdio>

const int MOD=1e9+9;

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::vector<int> seq(n);
  for(int i=0;i<n;i++){
    seq[i]=(i+shift+n)%n;
  }
  auto max=std::max_element(inputSeq,inputSeq+n);
  std::vector<int> where(*max+1,max-inputSeq);
  for(int i=0;i<n;i++){
    where[inputSeq[i]]=i;
  }
  int cnt=(shift==-1)?n:1;
  int spots=n;
  for(int x=0;x<=*max;x++){
    if(x==inputSeq[where[x]]){
      spots--;
    }else if(x>=n){
      cnt=1LL*cnt*spots%MOD;
    }
    seq[where[x]]=x;
  }
  return cnt;
}
# 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 384 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 16 ms 2304 KB Output is correct
7 Correct 11 ms 640 KB Output is correct
8 Correct 28 ms 3968 KB Output is correct
9 Correct 10 ms 1536 KB Output is correct
10 Correct 37 ms 4472 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 1 ms 384 KB Output is correct
6 Correct 15 ms 2304 KB Output is correct
7 Correct 11 ms 680 KB Output is correct
8 Correct 28 ms 3872 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 38 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 6 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 432 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 356 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 10 ms 1280 KB Output is correct
12 Correct 11 ms 1408 KB Output is correct
13 Correct 13 ms 1280 KB Output is correct
14 Correct 10 ms 1280 KB Output is correct
15 Correct 19 ms 2212 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 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 0 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 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 384 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 2 ms 256 KB Output is correct
9 Correct 44 ms 4600 KB Output is correct
10 Correct 37 ms 3968 KB Output is correct
11 Correct 14 ms 1536 KB Output is correct
12 Correct 17 ms 1920 KB Output is correct
13 Correct 7 ms 1536 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 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 49 ms 4600 KB Output is correct
10 Correct 39 ms 3832 KB Output is correct
11 Correct 15 ms 1664 KB Output is correct
12 Correct 18 ms 1920 KB Output is correct
13 Correct 8 ms 1536 KB Output is correct
14 Runtime error 290 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Halted 0 ms 0 KB -