Submission #599510

# Submission time Handle Problem Language Result Execution time Memory
599510 2022-07-19T14:59:17 Z Bench0310 Gondola (IOI14_gondola) C++17
100 / 100
56 ms 6516 KB
#include <bits/stdc++.h>
#include "gondola.h"

using namespace std;
typedef long long ll;

int valid(int n,int inputSeq[])
{
    vector<int> v(n);
    for(int i=0;i<n;i++) v[i]=inputSeq[i];
    for(int i=0;i<n;i++)
    {
        if(v[i]<=n)
        {
            int one=(i-(v[i]-1)+n)%n;
            rotate(v.begin(),v.begin()+one,v.end());
            break;
        }
    }
    set<int> s;
    for(int i=0;i<n;i++)
    {
        if(s.find(v[i])!=s.end()) return 0;
        s.insert(v[i]);
        if(v[i]<=n&&v[i]!=i+1) return 0;
    }
    return 1;
}

int replacement(int n,int gondolaSeq[],int replacementSeq[])
{
    vector<int> v(n);
    for(int i=0;i<n;i++) v[i]=gondolaSeq[i];
    for(int i=0;i<n;i++)
    {
        if(v[i]<=n)
        {
            int one=(i-(v[i]-1)+n)%n;
            rotate(v.begin(),v.begin()+one,v.end());
            break;
        }
    }
    vector<int> trains[n];
    for(int i=0;i<n;i++) trains[i].push_back(i+1);
    int mx=0;
    for(int i=1;i<n;i++) if(v[i]>v[mx]) mx=i;
    vector<int> vis(v[mx]+1,0);
    for(int i=0;i<n;i++) vis[v[i]]=1;
    for(int i=n+1;i<=v[mx];i++) if(vis[i]==0) trains[mx].push_back(i);
    for(int i=0;i<n;i++) trains[i].push_back(v[i]);
    vector<int> res(v[mx]+1,0);
    for(int i=0;i<n;i++) for(int j=1;j<(int)trains[i].size();j++) res[trains[i][j]]=trains[i][j-1];
    for(int i=n+1;i<=v[mx];i++) replacementSeq[i-n-1]=res[i];
    return v[mx]-n;
}

int countReplacement(int n,int inputSeq[])
{
    if(valid(n,inputSeq)==0) return 0;
    const ll mod=1000000009;
    auto mul=[&](ll a,ll b)->ll{return (a*b)%mod;};
    auto fpow=[&](ll b,ll e)->ll
    {
        ll r=1;
        while(e)
        {
            if(e&1) r=mul(r,b);
            b=mul(b,b);
            e/=2;
        }
        return r;
    };
    vector<int> v={n};
    for(int i=0;i<n;i++) if(inputSeq[i]>=n+1) v.push_back(inputSeq[i]);
    sort(v.begin(),v.end());
    int sz=v.size();
    ll res=(sz<=n?1:n);
    for(int i=1;i<sz;i++) res=mul(res,fpow(sz-i,v[i]-v[i-1]-1));
    return int(res);
}
# 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 212 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 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 18 ms 2288 KB Output is correct
7 Correct 8 ms 892 KB Output is correct
8 Correct 28 ms 4112 KB Output is correct
9 Correct 7 ms 1560 KB Output is correct
10 Correct 30 ms 4804 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 2348 KB Output is correct
7 Correct 8 ms 980 KB Output is correct
8 Correct 32 ms 4140 KB Output is correct
9 Correct 8 ms 1492 KB Output is correct
10 Correct 31 ms 4760 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 7 ms 928 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 212 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
4 Correct 1 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 1 ms 340 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 236 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 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 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
11 Correct 15 ms 5824 KB Output is correct
12 Correct 23 ms 6516 KB Output is correct
13 Correct 20 ms 3792 KB Output is correct
14 Correct 17 ms 5776 KB Output is correct
15 Correct 25 ms 4140 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 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 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 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 37 ms 4228 KB Output is correct
10 Correct 29 ms 3544 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 15 ms 1780 KB Output is correct
13 Correct 5 ms 596 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 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 35 ms 4248 KB Output is correct
10 Correct 35 ms 3532 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 12 ms 1748 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 54 ms 4868 KB Output is correct
15 Correct 56 ms 5452 KB Output is correct
16 Correct 8 ms 1180 KB Output is correct
17 Correct 33 ms 3680 KB Output is correct
18 Correct 17 ms 2260 KB Output is correct