Submission #219146

# Submission time Handle Problem Language Result Execution time Memory
219146 2020-04-03T20:52:59 Z summitwei Gondola (IOI14_gondola) C++17
100 / 100
101 ms 10360 KB
#include <bits/stdc++.h>
#include <gondola.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 1000000009LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (ll i=(a); i >= b; i--)

#define MN 100005
int rep[MN*2];
int valid(int n, int inputSeq[]){
    F0R(i, n) rep[i] = rep[i+n] = inputSeq[i];
    int loc = min_element(rep, rep+2*n)-rep;
    F0R(i, n) inputSeq[i] = rep[i+loc];
    set<int> hmm;
    int v = -1;
    if(inputSeq[0] <= n) v = inputSeq[0];
    F0R(i, n){
        if(hmm.count(rep[i])) return 0;
        hmm.insert(rep[i]);
        if(inputSeq[i]<=n && inputSeq[i]-i != v) return 0;
    }
    return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    //return 0;
    valid(n, gondolaSeq);
    map<int, int> ree;
    int v = 1;
    if(gondolaSeq[0] <= n) v = gondolaSeq[0];
    F0R(i, n){
        if(gondolaSeq[i] > n) ree[gondolaSeq[i]] = i+v>n?i+v-n:i+v;
    }
    if(ree.empty()){
        return 0;
    }
    int mx = (--ree.end())->f;
    int cur = (--ree.end())->s;
    FOR(i, n+1, mx){
        if(ree[i] == 0){
            replacementSeq[i-n-1] = cur;
            cur = i;
        } else if(i == mx){
            replacementSeq[i-n-1] = cur;
        } else{
            replacementSeq[i-n-1] = ree[i];
        }
    }
    return mx-n;
}
ll modExp(ll b, ll ex){
    ll prod = 1;
    while(ex > 0){
        if(ex % 2 == 0){
            b = (b * b) % MOD;
            ex /= 2;
        } else{
            prod = (prod*b) % MOD;
            ex--;
        }
    }
    
    return prod;
}
int countReplacement(int n, int inputSeq[]){
    if(!valid(n, inputSeq)) return 0;
    map<int, int> ree;
    int v = 1;
    if(inputSeq[0] <= n) v = inputSeq[0];
    F0R(i, n){
        if(inputSeq[i] > n) ree[inputSeq[i]] = i+v>n?i+v-n:i+v;
    }
    if(ree.empty()) return 1;
    int mx = (--ree.end())->f;
    int amt = ree.size();
    ll ans = 1;
    /*if(inputSeq[0] > n){
        FOR(i, 1, n) ans = (ans*i)%MOD;
    }*/
    if(inputSeq[0] > n) ans = n;
    /*FOR(i, n+1, mx){
        if(ree[i] == 0){
            ans = (ans*amt)%MOD;
        } else{
            --amt;
        }
    }*/
    int prev = n;
    for(auto u : ree){
        ans = (ans*modExp(amt, u.f-prev-1))%MOD;
        prev = u.f;
        --amt;
    }
    return (int)ans;
}

/*int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    int a[n];
    F0R(i, n) cin >> a[i];
    cout << countReplacement(n, a) << "\n";
    
    return 0;
}*/

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:88:9: warning: unused variable 'mx' [-Wunused-variable]
     int mx = (--ree.end())->f;
         ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 18 ms 2688 KB Output is correct
7 Correct 17 ms 1792 KB Output is correct
8 Correct 31 ms 4864 KB Output is correct
9 Correct 12 ms 1792 KB Output is correct
10 Correct 38 ms 5624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 19 ms 2808 KB Output is correct
7 Correct 17 ms 1792 KB Output is correct
8 Correct 31 ms 4864 KB Output is correct
9 Correct 13 ms 1792 KB Output is correct
10 Correct 38 ms 5624 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 10 ms 1024 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 20 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 5 ms 512 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 640 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 640 KB Output is correct
11 Correct 40 ms 5240 KB Output is correct
12 Correct 40 ms 5884 KB Output is correct
13 Correct 50 ms 4984 KB Output is correct
14 Correct 37 ms 5240 KB Output is correct
15 Correct 65 ms 10360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 66 ms 4984 KB Output is correct
10 Correct 51 ms 4220 KB Output is correct
11 Correct 23 ms 1792 KB Output is correct
12 Correct 27 ms 2048 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 65 ms 4984 KB Output is correct
10 Correct 51 ms 4256 KB Output is correct
11 Correct 22 ms 1792 KB Output is correct
12 Correct 27 ms 2048 KB Output is correct
13 Correct 9 ms 768 KB Output is correct
14 Correct 85 ms 6008 KB Output is correct
15 Correct 101 ms 6776 KB Output is correct
16 Correct 20 ms 1536 KB Output is correct
17 Correct 63 ms 4728 KB Output is correct
18 Correct 36 ms 2816 KB Output is correct