Submission #164474

# Submission time Handle Problem Language Result Execution time Memory
164474 2019-11-21T02:32:19 Z dantoh000 Gondola (IOI14_gondola) C++14
100 / 100
78 ms 8808 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000009;
ll exp(int a, int x){
    if (x == 0) return 1ll;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1) p *= a;
    p %= mod;
    return p;
}
int valid(int n, int inputSeq[]) {
    int anchor[n];
    unordered_set<int> s;
    int last = -1;
    for (int i = 0; i < n; i++){
        s.insert(inputSeq[i]);
        if (inputSeq[i] > n) continue;
        anchor[i] = (i+n-inputSeq[i])%n;
        //printf("%d ",anchor[i]);
        if (last == -1){
            last = anchor[i];
        }
        else{
            if (last != anchor[i]) return 0;
        }
    }
    if (s.size() != n) return 0;
    return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    int l = 0;
    int maxpos = 1;
    unordered_map<int,int> pos;
    for (int i = 0; i < n; i++){
        if (gondolaSeq[maxpos-1] < gondolaSeq[i]) maxpos = i+1;
    }
    l = gondolaSeq[maxpos-1] - n;
    int curseq[n];
    bool can = false;
    for (int i = 0; i < n; i++){
        pos[gondolaSeq[i]] = i+1;
        if (gondolaSeq[i] <= n){
            can = true;
            curseq[i] = gondolaSeq[i];
        }
        else curseq[i] = (curseq[(n+i-1)%n]) % n +1 ;
    }
    for (int i = 0; i < n; i++){
        if (can) curseq[i] = (curseq[(n+i-1)%n]) % n + 1;
        else curseq[i] = i+1;
        pos[curseq[i]] = i+1;
        //printf("%d ",curseq[i]);
    }
    for (int i = 0; i < l; i++){
        if (pos[i+n+1] == 0) pos[i+n+1] = maxpos;
        //printf("replacing %d %d\n",i+n+1,pos[i+n+1]);
        replacementSeq[i] = curseq[pos[i+n+1]-1];
        curseq[pos[i+n+1]-1] = i+n+1;
        pos[replacementSeq[i]] = pos[i+n+1];
    }
    return l;
}

int countReplacement(int n, int inputSeq[]) {
    if (!valid(n,inputSeq)) return 0;
    int mx = *max_element(inputSeq,inputSeq+n);
    ll ans = 1;
    int ct = n;
    vector<int> v;
    for (int i = 0; i < n; i++){
        if (inputSeq[i] <= n) ct--;
        else v.push_back(inputSeq[i]);
    }
    if (ct == n) ans = n;
    v.push_back(n);
    sort(v.begin(),v.end());
    for (int i = 1; i < (int)v.size(); i++){
        ans *= exp(ct,v[i]-v[i-1]-1);
        ans %= mod;
        ct--;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (s.size() != n) return 0;
         ~~~~~~~~~^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:71:9: warning: unused variable 'mx' [-Wunused-variable]
     int mx = *max_element(inputSeq,inputSeq+n);
         ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 12 ms 2212 KB Output is correct
7 Correct 13 ms 632 KB Output is correct
8 Correct 22 ms 4000 KB Output is correct
9 Correct 8 ms 1400 KB Output is correct
10 Correct 24 ms 4360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 12 ms 2216 KB Output is correct
7 Correct 14 ms 632 KB Output is correct
8 Correct 22 ms 3972 KB Output is correct
9 Correct 8 ms 1400 KB Output is correct
10 Correct 25 ms 4484 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 7 ms 504 KB Output is correct
14 Correct 15 ms 376 KB Output is correct
15 Correct 14 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 632 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 27 ms 4232 KB Output is correct
12 Correct 31 ms 4612 KB Output is correct
13 Correct 45 ms 5000 KB Output is correct
14 Correct 27 ms 4232 KB Output is correct
15 Correct 78 ms 8808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 35 ms 4104 KB Output is correct
10 Correct 30 ms 3752 KB Output is correct
11 Correct 12 ms 1400 KB Output is correct
12 Correct 15 ms 1912 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 36 ms 3976 KB Output is correct
10 Correct 30 ms 3752 KB Output is correct
11 Correct 12 ms 1400 KB Output is correct
12 Correct 15 ms 2040 KB Output is correct
13 Correct 5 ms 760 KB Output is correct
14 Correct 44 ms 4232 KB Output is correct
15 Correct 49 ms 5512 KB Output is correct
16 Correct 10 ms 1400 KB Output is correct
17 Correct 34 ms 4136 KB Output is correct
18 Correct 20 ms 2344 KB Output is correct