Submission #827605

# Submission time Handle Problem Language Result Execution time Memory
827605 2023-08-16T15:17:12 Z bachhoangxuan Gondola (IOI14_gondola) C++17
100 / 100
48 ms 6632 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int maxn = 250005;
const int mod=1e9+9;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=1LL*res*a%mod;
        a=1LL*a*a%mod;n>>=1;
    }
    return res;
}

map<int,int> cnt;

int valid(int n, int p[])
{
    int del=-1;
    for(int i=0;i<n;i++){
        if(cnt[p[i]]) return 0;
        cnt[p[i]]++;
        if(p[i]<=n){
            int cur=(i-p[i]+n)%n;
            if(del==-1) del=cur;
            else if(del!=cur) return 0;
        }
    }
    return 1;
}

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

int replacement(int n, int p[], int res[])
{
    int del=0,sz=0;
    for(int i=0;i<n;i++) if(p[i]<=n) del=(i-p[i]+1+n)%n;
    deque<int> dq(n);
    for(int i=0;i<n;i++) dq[i]=p[i];
    while(del){
        del--;
        dq.push_back(dq.front());
        dq.pop_front();
    }
    vector<pii> pp;
    for(int i=0;i<n;i++) if(dq[i]>n) pp.push_back({dq[i],i});
    sort(pp.begin(),pp.end());
    int pre=n;
    for(auto &[x,id]:pp){
        res[sz++]=id+1;pre++;
        while(pre<x) res[sz++]=pre++;
    }
    return sz;
}

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

int countReplacement(int n, int p[])
{
    if(!valid(n,p)) return 0;
    vector<int> pp;
    int res=n,cnt=n;
    for(int i=0;i<n;i++){
        if(p[i]<=n) res=1,cnt--;
        else pp.push_back(p[i]);
    }
    int pre=n;
    sort(pp.begin(),pp.end());
    for(int x:pp){
        res=1LL*res*power(cnt,x-pre-1)%mod;
        pre=x;cnt--;
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 2372 KB Output is correct
7 Correct 6 ms 1092 KB Output is correct
8 Correct 25 ms 4304 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 22 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 9 ms 2388 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 18 ms 4332 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 22 ms 4968 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 3 ms 616 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 6 ms 1060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 7 ms 1388 KB Output is correct
12 Correct 8 ms 1456 KB Output is correct
13 Correct 11 ms 1532 KB Output is correct
14 Correct 7 ms 1272 KB Output is correct
15 Correct 16 ms 2348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 304 KB Output is correct
9 Correct 34 ms 4796 KB Output is correct
10 Correct 25 ms 4132 KB Output is correct
11 Correct 9 ms 1756 KB Output is correct
12 Correct 12 ms 2004 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 31 ms 4812 KB Output is correct
10 Correct 25 ms 4116 KB Output is correct
11 Correct 9 ms 1748 KB Output is correct
12 Correct 14 ms 2004 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 44 ms 6024 KB Output is correct
15 Correct 48 ms 6632 KB Output is correct
16 Correct 8 ms 1576 KB Output is correct
17 Correct 30 ms 4496 KB Output is correct
18 Correct 16 ms 2840 KB Output is correct