Submission #297805

# Submission time Handle Problem Language Result Execution time Memory
297805 2020-09-12T01:14:39 Z juckter Gondola (IOI14_gondola) C++14
100 / 100
75 ms 5112 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXV = 3e5 + 10;
const ll MOD = 1e9 + 9;

ll mpow(ll b, ll e) {
    ll res = 1;
    for(ll k = 1; k <= e; k *= 2) {
        if(k & e) res = (res * b) % MOD;
        b = (b * b) % MOD;
    }
    return res;
}

int valid(int n, int inputSeq[]) {
    set<int> seen;
    int rot = -1;
    for(int i = 0; i < n; i++) {
        if(seen.count(inputSeq[i]))
            return 0;
        seen.insert(inputSeq[i]);
        if(inputSeq[i] <= n) {
            int nr = (inputSeq[i] - i + n) % n;
            if(rot != -1 && rot != nr)
                return 0;
            rot = nr;
        }
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    if(*min_element(gondolaSeq, gondolaSeq + n) <= n) {
        int rot;

        for(int i = 0; i < n; i++)
            if(gondolaSeq[i] <= n)
                rot = (gondolaSeq[i] - i + n - 1) % n;

        rotate(gondolaSeq, gondolaSeq + (n - rot) % n, gondolaSeq + n);
    }
    //for(int i = 0; i < n; i++)
    //    cerr << gondolaSeq[i] << " ";
    //cerr << '\n';
    int mx = *max_element(gondolaSeq, gondolaSeq + n);
    int mpos = -1;
    vector<int> pos(300000);
    for(int i = 0; i < n; i++) {
        pos[gondolaSeq[i]] = i + 1;
        if(gondolaSeq[i] == mx)
            mpos = i;
    }
    int st = 0, len = mx - n;
    int pv = mpos + 1;
    for(int i = n + 1; i <= mx; i++) {
        if(i != mx && pos[i])
            replacementSeq[st++] = pos[i];
        else {
            replacementSeq[st++] = pv;
            pv = i;
        }
    }
    return len;
}

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

int countReplacement(int n, int inputSeq[]) {
    if(!valid(n, inputSeq))
        return 0;
    ll cntBig = 0;
    vector<ll> bigs;
    for(int i = 0; i < n; i++)
        if(inputSeq[i] > n) {
            cntBig++;
            bigs.push_back(inputSeq[i]);
        }

    ll cntSmall = n - cntBig;
    bigs.push_back(n);
    sort(bigs.begin(), bigs.end());
    ll ways = 1, cur = cntBig;
    for(int i = 1; i < bigs.size(); i++) {
        ways = (ways * mpow(cur, bigs[i] - bigs[i - 1] - 1)) % MOD;
        cur--;
    }

    if(cntBig == n)
        ways = (ways * (ll)n) % MOD;
    return ways;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i = 1; i < bigs.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
gondola.cpp:84:8: warning: unused variable 'cntSmall' [-Wunused-variable]
   84 |     ll cntSmall = n - cntBig;
      |        ^~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:45:44: warning: 'rot' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |         rotate(gondolaSeq, gondolaSeq + (n - rot) % n, gondolaSeq + n);
      |                                         ~~~^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 15 ms 2176 KB Output is correct
7 Correct 14 ms 640 KB Output is correct
8 Correct 30 ms 3960 KB Output is correct
9 Correct 8 ms 1536 KB Output is correct
10 Correct 36 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 15 ms 2176 KB Output is correct
7 Correct 12 ms 640 KB Output is correct
8 Correct 29 ms 3896 KB Output is correct
9 Correct 9 ms 1536 KB Output is correct
10 Correct 34 ms 4600 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 13 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1664 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 1 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1536 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1536 KB Output is correct
2 Correct 1 ms 1536 KB Output is correct
3 Correct 1 ms 1536 KB Output is correct
4 Correct 1 ms 1536 KB Output is correct
5 Correct 2 ms 1536 KB Output is correct
6 Correct 1 ms 1536 KB Output is correct
7 Correct 1 ms 1536 KB Output is correct
8 Correct 2 ms 1536 KB Output is correct
9 Correct 2 ms 1664 KB Output is correct
10 Correct 2 ms 1536 KB Output is correct
11 Correct 12 ms 1792 KB Output is correct
12 Correct 13 ms 1792 KB Output is correct
13 Correct 15 ms 1920 KB Output is correct
14 Correct 12 ms 1792 KB Output is correct
15 Correct 23 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 49 ms 4088 KB Output is correct
10 Correct 39 ms 3448 KB Output is correct
11 Correct 14 ms 1408 KB Output is correct
12 Correct 17 ms 1664 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 51 ms 4092 KB Output is correct
10 Correct 40 ms 3448 KB Output is correct
11 Correct 15 ms 1408 KB Output is correct
12 Correct 17 ms 1664 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 63 ms 4600 KB Output is correct
15 Correct 75 ms 5112 KB Output is correct
16 Correct 11 ms 1152 KB Output is correct
17 Correct 45 ms 4216 KB Output is correct
18 Correct 25 ms 2424 KB Output is correct