Submission #8537

# Submission time Handle Problem Language Result Execution time Memory
8537 2014-09-16T06:09:45 Z gs14004 Gondola (IOI14_gondola) C++
Compilation error
0 ms 0 KB
#include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#include <cstdlib>
using namespace std;
typedef pair<int,int> pi;

int valid(int n, int inputSeq[]){
    int v[250005]={};
    for (int i=0; i<n; i++) {
        if(v[inputSeq[i]]) return 0;
        v[inputSeq[i]] = 1;
    }
    int piv = -1;
    for (int i=0; i<n; i++) {
        if(inputSeq[i] <= n){
            if(piv == -1){
                piv = i;
            }
            else{
                int res = i + (inputSeq[piv] - piv) + n;
                res %= n;
                if(res == 0) res = n;
                if(inputSeq[i] != res) return 0;
            }
        }
    }
    return 1;
}

priority_queue<pi,vector<pi>,greater<pi> > pq, pq2;

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int piv = 0, piv2 = n+1, piv3 = 0;
    for (int i=0; i<n; i++) {
        if(gondolaSeq[i] <= n){
            piv = gondolaSeq[i] - i - 1+ n;
            piv %= n;
        }
    }
    int newSeq[100005] = {};
    for (int i=0; i<n; i++) {
        newSeq[i] = gondolaSeq[(i + n - piv)%n];
        if(newSeq[i] > n) pq.push(pi(newSeq[i],i+1));
    }
    while (!pq.empty()) {
        pi x = pq.top();
        pq.pop();
        replacementSeq[piv3++] = x.second;
        for (int i=piv2; i<x.first; i++) {
            replacementSeq[piv3++] = i;
        }
        piv2 = x.first + 1;
    }
    return piv3;
}

long long pow(int x, int time){
    if(time < 0) return 1ll;
    long long res = 1, piv = x;
    while (time) {
        if(time&1) res *= piv;
        piv *= piv;
        res %= 1000000009ll;
        piv %= 1000000009ll;
        time >>= 1;
    }
    return res;
}

int newSeq[100005];
long long countReplacement(int n, int inputSeq[]){
    if(!valid(n,inputSeq)) return 0;
    int piv = 0, piv2 = n, cnt = 0;
    long long res = 1;
    for (int i=0; i<n; i++) {
        if(inputSeq[i] > n) newSeq[piv++] = inputSeq[i];
    }
    if(piv == n) res = piv;
    if(piv == 0) return 1;
    cnt = piv;
    sort(newSeq,newSeq+piv);
    for (int i=0; i<piv; i++) {
        res *= pow(cnt,newSeq[i] - piv2 - 1);
        piv2 = newSeq[i];
        cnt--;
        res %= 1000000009ll;
    }
    if(newSeq[piv-1] > 987654321 && n == 100000){
        puts("sex");
        exit(0);
    }
    return res;
}

int main(){
    int a[100005],n;
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    printf("%lld",countReplacement(n,a));
}

Compilation message

gondola.cpp: In function 'int main()':
gondola.cpp:99:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
gondola.cpp:101:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
/tmp/cctKu6BT.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccjbGPkp.o:gondola.cpp:(.text.startup+0x0): first defined here
/tmp/cctKu6BT.o: In function `main':
grader.cpp:(.text.startup+0xb1): undefined reference to `replacement'
grader.cpp:(.text.startup+0x141): undefined reference to `countReplacement'
grader.cpp:(.text.startup+0x164): undefined reference to `valid'
collect2: ld returned 1 exit status