Submission #615761

# Submission time Handle Problem Language Result Execution time Memory
615761 2022-07-31T12:23:16 Z nohaxjustsoflo Gondola (IOI14_gondola) C++17
100 / 100
19 ms 3156 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN=1e6+5;
const int mod=1e9+9;
const int mxlogN=40;
const int mxK=26;
const int inf=2e9;
const int K=600;
#include "gondola.h"

int valid(int n, int a[])
{
    for(int i=0; i<n; i++)
    {
        if(a[i]<=n)
        {
            for(int j=i+1; j-i<n; j++) if(a[j%n]<=n&&a[j%n]!=(a[i]+j-i-1)%n+1) return 0;
            break;
        }
    }
    sort(a,a+n);
    for(int i=0; i+1<n; i++) if(a[i]==a[i+1]) return 0;
    return 1;
}

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

int replacement(int n, int a[], int b[])
{
    int c[n];
    iota(c,c+n,1);
    for(int i=0; i<n; i++)
    {
        if(a[i]<=n)
        {
            for(int j=i; j-i<n; j++) c[j%n]=(a[i]+j-i-1)%n+1;
            break;
        }
    }
    int w[250001];
    for(int i=1; i<=250000; i++) w[i]=-1;
    for(int i=0; i<n; i++) w[a[i]]=c[i];
    for(int i=249999; i>n; i--) if(!~w[i]) w[i]=w[i+1];
    int j=0;
    for(int i=n+1; i<=250000; i++)
    {
        if(!~w[i]) break;
        if(w[i]==w[i-1]) b[j++]=i-1;
        else b[j++]=w[i];
    }
    return j;
}

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

ll powb(ll a, ll x)
{
    ll ret=1;
    a%=mod;
    while(x)
    {
        if(x&1)ret=ret*a%mod;
        x>>=1;
        a=a*a%mod;
    }
    return ret;
}

int countReplacement(int n, int a[])
{
    if(!valid(n, a)) return 0;
    sort(a,a+n);

    ll ways=1;
    bool ok=1;
    for(int i=0; i<n; i++)
    {
        if(a[i]>n)
        {
            int sz;
            if(i) sz=a[i]-max(n,a[i-1]);
            else sz=a[i]-n;
            ways=ways*powb(n-i,sz-1)%mod;
        }
        else ok=0;
    }
    if(ok) ways=ways*n%mod;
    return ways;
}
/*
int countReplacement(int n, int a[])
{
    if(!valid(n, a)) return 0;

    int c[n];
    iota(c,c+n,1);
    bool ok=1;
    for(int i=0; i<n; i++)
    {
        if(a[i]<=n)
        {
            for(int j=i; j-i<n; j++) c[j%n]=(a[i]+j-i-1)%n+1;
            ok=0;
            break;
        }
    }
    int w[250001];
    for(int i=1; i<=250000; i++) w[i]=-1;
    for(int i=0; i<n; i++) w[a[i]]=c[i];
    set<int> s;
    for(int i=249999; i>n; i--)
    {
        if(!~w[i]) w[i]=w[i+1];
        else s.insert(w[i]);
    }
    ll ways=1;
    for(int i=n+1; i<=250000; i++)
    {
        if(!~w[i]) break;
        if(w[i]==w[i-1]) ways=ways*(ll)s.size()%mod;
        else s.erase(w[i-1]);
    }
    if(ok) for(int i=2; i<=n; i++) ways=ways*i%mod;
    return ways;
}

int main()
{
    int n; cin >> n;
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    cout << countReplacement(n,a);
}
*/
/*
5 4 3
0 1 2
0 2 3
3 2 1
2 4 4
1 3 4
*/
# 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 256 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 1 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 0 ms 212 KB Output is correct
6 Correct 9 ms 456 KB Output is correct
7 Correct 7 ms 596 KB Output is correct
8 Correct 16 ms 596 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 14 ms 572 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 0 ms 212 KB Output is correct
6 Correct 7 ms 452 KB Output is correct
7 Correct 10 ms 592 KB Output is correct
8 Correct 9 ms 468 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 12 ms 612 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 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 7 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 2 ms 1236 KB Output is correct
3 Correct 2 ms 1288 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 1 ms 1236 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 2 ms 1220 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1236 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 1 ms 1236 KB Output is correct
4 Correct 2 ms 1236 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 2 ms 1236 KB Output is correct
7 Correct 2 ms 1236 KB Output is correct
8 Correct 3 ms 1236 KB Output is correct
9 Correct 2 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 9 ms 1876 KB Output is correct
12 Correct 10 ms 1884 KB Output is correct
13 Correct 12 ms 2260 KB Output is correct
14 Correct 8 ms 1876 KB Output is correct
15 Correct 19 ms 3156 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
# 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 1 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
# 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 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 14 ms 600 KB Output is correct
10 Correct 11 ms 468 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 6 ms 340 KB Output is correct
13 Correct 2 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 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 14 ms 596 KB Output is correct
10 Correct 12 ms 468 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 6 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 17 ms 1460 KB Output is correct
15 Correct 19 ms 1576 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 13 ms 1096 KB Output is correct
18 Correct 7 ms 724 KB Output is correct