Submission #16215

# Submission time Handle Problem Language Result Execution time Memory
16215 2015-08-18T05:05:15 Z CodingBug Gondola (IOI14_gondola) C++
35 / 100
18 ms 2972 KB
#include "gondola.h"
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <set>
#define LMT 1000000009
using namespace std;

int valid(int n, int inputSeq[])
{
    int i,p;
    set<int> ch;

    for(i=0;i<n;i++){
        if(ch.find(inputSeq[i])==ch.end()) return 0;
        ch.insert(inputSeq[i]);
    }

    for(i=0;i<n;i++) if(inputSeq[i]<=n) break;
    p=inputSeq[i];
    for(;i<n;i++,p++) if(inputSeq[i]<=n && inputSeq[i]!=(p-1)%n+1) return 0;
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int i,p,l;
    vector<pair<int,int> > v;
    for(i=0;i<n;i++) if(gondolaSeq[i]>n) v.push_back(make_pair(gondolaSeq[i],i));
    sort(v.begin(),v.end());
    for(i=0;i<n;i++) if(gondolaSeq[i]<=n) break;
    if(i==n) gondolaSeq[i=0]=1;
    for(p=1;p<n;p++) gondolaSeq[(p+i)%n]=(gondolaSeq[i]+p-1)%n+1;
    for(i=n+1,p=0,l=0;p<v.size();i++){
        replacementSeq[l++]=gondolaSeq[v[p].second];
        gondolaSeq[v[p].second]=i;
        if(v[p].first==i) p++;
    }
    return l;
}

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

int mpow(int x,int y){
    if(!y) return 1;
    int k=mpow(x,y/2);
    if(y&1) return (long long)((long long)k*k%LMT)*x%LMT;
    else return (long long)k*k%LMT;
}

int countReplacement(int n, int inputSeq[])
{
    if(!valid(n,inputSeq)) return 0;
    int i,p,s=1;
    vector<int> v;
    for(i=0;i<n;i++) if(inputSeq[i]>n) v.push_back(inputSeq[i]);
    v.push_back(n);
    sort(v.begin(),v.end());
    for(i=1;i<v.size();i++) s=(long long)s*mpow(((int)v.size()-i),(v[i]-v[i-1]-1))%LMT;
    return s;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 0 ms 2584 KB Output is correct
10 Correct 0 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2584 KB Output is correct
2 Correct 0 ms 2584 KB Output is correct
3 Correct 0 ms 2584 KB Output is correct
4 Correct 0 ms 2584 KB Output is correct
5 Correct 0 ms 2584 KB Output is correct
6 Correct 0 ms 2584 KB Output is correct
7 Correct 0 ms 2584 KB Output is correct
8 Correct 0 ms 2584 KB Output is correct
9 Correct 0 ms 2584 KB Output is correct
10 Correct 0 ms 2584 KB Output is correct
11 Correct 10 ms 2584 KB Output is correct
12 Correct 6 ms 2584 KB Output is correct
13 Correct 18 ms 2972 KB Output is correct
14 Correct 11 ms 2584 KB Output is correct
15 Correct 16 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -