Submission #138742

# Submission time Handle Problem Language Result Execution time Memory
138742 2019-07-30T09:27:42 Z zoooma13 Gondola (IOI14_gondola) C++14
100 / 100
82 ms 6008 KB
#include "bits/stdc++.h"
#include "gondola.h"
using namespace std;

int valid(int n, int inputSeq[]){
    int mi_idx = min_element(inputSeq ,inputSeq+n)-inputSeq;
    set <int> ss;
    for(int i=0; i<n; i++)
        ss.insert(inputSeq[i]);
    if(ss.size() != n)
        return 0;
    if(inputSeq[mi_idx] >= n)
        return 1;
    int nxt = inputSeq[mi_idx];
    for(int i=mi_idx; nxt<=n; i++){
        if(inputSeq[i%n] != nxt && inputSeq[i%n] <= n)
            return 0;
        nxt++;
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    vector <pair<int ,int>> vii;
    int mi_idx = min_element(gondolaSeq ,gondolaSeq+n)-gondolaSeq;
    int nxt = gondolaSeq[mi_idx];
    if(nxt > n)
        nxt = 1;
    for(int i=mi_idx; i<mi_idx+n; i++){
        vii.push_back({gondolaSeq[i%n] ,nxt});
        //cout << gondolaSeq[i%n]  << ' ' << nxt << endl;
        nxt = (nxt == n ? 1 : nxt+1);
    }
    sort(vii.begin() ,vii.end());
    nxt = n;
    vector <int> ret;
    for(auto&p : vii){
        if(p.first <= n)
            continue;
        ret.push_back(p.second);
        for(nxt++; nxt != p.first; nxt++)
            ret.push_back(nxt);
    }
    for(int i=0; i<ret.size(); i++)
        replacementSeq[i] = ret[i];
    return ret.size();
}

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

const int mod = 1e9+9;
int powmod(int a ,int p){
    int x = 1;
    for( ; p; p>>=1){
        if(p&1)
            x = 1LL*x*a%mod;
        a = 1LL*a*a%mod;
    }
    return x;
}

int countReplacement(int n, int inputSeq[])
{
    if(!valid(n ,inputSeq))
        return 0;

    int mi_idx = min_element(inputSeq ,inputSeq+n)-inputSeq;
    int nxt = inputSeq[mi_idx];
    if(nxt > n)
        nxt = 1;
    vector <int> to;
    for(int i=mi_idx; i<mi_idx+n; i++){
        if(inputSeq[i%n] != nxt)
            to.push_back(inputSeq[i%n]);
        nxt = (nxt == n ? 1 : nxt+1);
    }
    sort(to.begin() ,to.end());
    int ans = 1 ,to_ptr = 0 ,lst = n;
    for(int i:to){
        ans = 1LL*ans*powmod(to.size()-to_ptr ,i-lst-1)%mod;
        lst = i;
        to_ptr++;
    }
    if(inputSeq[mi_idx] <= n)
        return ans;
    else
        return 1LL*ans*n%mod;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:10:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(ss.size() != n)
        ~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:47:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<ret.size(); i++)
                  ~^~~~~~~~~~~
# 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 376 KB Output is correct
5 Correct 2 ms 376 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 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 16 ms 2168 KB Output is correct
7 Correct 38 ms 3704 KB Output is correct
8 Correct 29 ms 3960 KB Output is correct
9 Correct 10 ms 1528 KB Output is correct
10 Correct 37 ms 4472 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 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 17 ms 2296 KB Output is correct
7 Correct 41 ms 3704 KB Output is correct
8 Correct 29 ms 3960 KB Output is correct
9 Correct 11 ms 1528 KB Output is correct
10 Correct 36 ms 4600 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 21 ms 2168 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 49 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 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 380 KB Output is correct
# 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 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 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 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 256 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 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 15 ms 1772 KB Output is correct
12 Correct 17 ms 1904 KB Output is correct
13 Correct 19 ms 1516 KB Output is correct
14 Correct 15 ms 1776 KB Output is correct
15 Correct 25 ms 2240 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 252 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 2 ms 252 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
# 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 256 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 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 52 ms 4088 KB Output is correct
10 Correct 41 ms 3576 KB Output is correct
11 Correct 15 ms 1400 KB Output is correct
12 Correct 19 ms 1656 KB Output is correct
13 Correct 5 ms 632 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 2 ms 376 KB Output is correct
5 Correct 2 ms 404 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
9 Correct 53 ms 4088 KB Output is correct
10 Correct 42 ms 3448 KB Output is correct
11 Correct 15 ms 1532 KB Output is correct
12 Correct 19 ms 1656 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 65 ms 5396 KB Output is correct
15 Correct 82 ms 6008 KB Output is correct
16 Correct 12 ms 1400 KB Output is correct
17 Correct 46 ms 4216 KB Output is correct
18 Correct 26 ms 2424 KB Output is correct