Submission #308134

# Submission time Handle Problem Language Result Execution time Memory
308134 2020-09-30T05:00:14 Z juggernaut Gondola (IOI14_gondola) C++14
100 / 100
29 ms 2296 KB
#include"gondola.h"
#include<bits/stdc++.h>
//#include"grader.cpp"
#define mod 1000000009
using namespace std;
typedef long long int ll;
int valid(int n,int a[]){
    int i=0,need;
    while(i<n&&a[i]>n)i++;
    need=a[i];
    while(i<n){
        if(a[i]<=n&&a[i]!=need)return 0;
        if(need==n)need=1;
        else need++;
        i++;
    }
    sort(a,a+n);
    for(i=1;i<n;i++)if(a[i]==a[i-1])return 0;
    return 1;
}
int replacement(int n,int a[],int res[]){
    vector<pair<int,int>>b;
    int i=0,ind=n,need=1,len=0,x;
    while(i<n&&a[i]>n)i++;
    if(i!=n)need=a[i]-i;
    if(need<1)need+=n;
    for(i=0;i<n;i++,need=need%n+1)b.push_back({a[i],need});
    sort(b.begin(),b.end());
    i=0;
    while(i<n){
        if(b[i].first<=n){
            i++;
            continue;
        }
        res[len++]=b[i].second;
        x=++ind;
        while(x!=b[i].first){
            res[len++]=x;
            x=++ind;
        }
        i++;
    }
    return len;
}
int pw(int x,int y)
{
  if(y==0)return 1;
  if(y&1)return 1LL*x*pw(x,y-1)%mod;
  x=pw(x,y>>1);
  return 1LL*x*x%mod;
}
int countReplacement(int n, int inputSeq[])
{
  if(!valid(n,inputSeq))return 0;
  int i,r=1;
  sort(inputSeq,inputSeq+n);
  for(i=0;i<n;i++)
  {
    if(inputSeq[i]<=n)continue;
    r=1LL*r*pw(n-i,inputSeq[i]-(i>0?max(inputSeq[i-1],n):n)-1)%mod;
  }
  return 1LL*r*(inputSeq[0]>n?n:1)%mod;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 13 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 18 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 13 ms 640 KB Output is correct
8 Correct 13 ms 640 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 18 ms 640 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 13 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 15 ms 1784 KB Output is correct
12 Correct 17 ms 1784 KB Output is correct
13 Correct 18 ms 1316 KB Output is correct
14 Correct 14 ms 1784 KB Output is correct
15 Correct 26 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 20 ms 1024 KB Output is correct
10 Correct 16 ms 896 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 20 ms 1024 KB Output is correct
10 Correct 16 ms 896 KB Output is correct
11 Correct 7 ms 512 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 25 ms 1408 KB Output is correct
15 Correct 29 ms 1664 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 19 ms 1152 KB Output is correct
18 Correct 11 ms 768 KB Output is correct