Submission #445804

# Submission time Handle Problem Language Result Execution time Memory
445804 2021-07-19T15:55:46 Z JovanB Gondola (IOI14_gondola) C++17
100 / 100
79 ms 10448 KB
#include "gondola.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
ll niz[100005];
ll niz1[100005];
map <ll, bool> bio;
 
const int MOD = 1000000009;
 
ll mul(ll a, ll b){
    return (a*b)%MOD;
}
 
int pw(int a, int b){
    if(b == 0) return 1;
    int res = pw(a, b/2);
    res = mul(res, res);
    if(b%2) res = mul(res, a);
    return res;
}
 
void shiftuj(int n, int k){
    for(int i=1; i<=n; i++) niz1[i] = niz[i];
    if(k < 0) k += n;
    for(int i=k+1; i<=n; i++){
        niz[i] = niz1[i-k];
    }
    for(int i=1; i<=k; i++){
        niz[i] = niz1[n-k+i];
    }
}
 
int valid(int n, int inputSeq[]){
    for(int i=1; i<=n; i++){
        niz[i] = inputSeq[i-1];
    }
    for(int i=1; i<=n; i++){
        if(niz[i] <= n){
            shiftuj(n, niz[i]-i);
            break;
        }
    }
    for(int i=1; i<=n; i++){
        if(niz[i] <= n && niz[i] != i) return 0;
        if(bio[niz[i]]) return 0;
        bio[niz[i]] = 1;
    }
    return 1;
}
 
//----------------------
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    for(int i=1; i<=n; i++) niz[i] = gondolaSeq[i-1];
    for(int i=1; i<=n; i++){
        if(niz[i] <= n){
            shiftuj(n, niz[i]-i);
            break;
        }
    }
    vector <pair <int, int>> vec;
    for(int i=1; i<=n; i++){
        if(niz[i] != i){
            vec.push_back({niz[i], i});
        }
    }
    sort(vec.begin(), vec.end());
    int prosli = n+1;
    int l = 0;
    for(auto par : vec){
        int a = par.first;
        int b = par.second;
        replacementSeq[l++] = b;
        while(prosli < a){
            replacementSeq[l++] = prosli;
            prosli++;
        }
        prosli++;
    }
    return l;
}
 
//----------------------
 
int countReplacement(int n, int inputSeq[]){
    if(!valid(n, inputSeq)) return 0;
    vector <pair <ll, ll>> vec;
    for(ll i=1; i<=n; i++){
        if(niz[i] != i){
            vec.push_back({niz[i], i});
        }
    }
    sort(vec.begin(), vec.end());
    ll prosli = n+1;
    ll g = vec.size();
    ll sol = 1;
    for(auto par : vec){
        ll a = par.first;
        ll b = par.second;
        sol = mul(sol, pw(g, max(0LL, a-prosli)));
        prosli = a+1;
        g--;
    }
    if(vec.size() == n) sol = mul(sol, n);
    return sol;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:103:12: warning: unused variable 'b' [-Wunused-variable]
  103 |         ll b = par.second;
      |            ^
gondola.cpp:108:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |     if(vec.size() == n) sol = mul(sol, n);
      |        ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 17 ms 3516 KB Output is correct
7 Correct 11 ms 2476 KB Output is correct
8 Correct 32 ms 6536 KB Output is correct
9 Correct 10 ms 2284 KB Output is correct
10 Correct 39 ms 7624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 18 ms 3520 KB Output is correct
7 Correct 11 ms 2488 KB Output is correct
8 Correct 33 ms 6532 KB Output is correct
9 Correct 10 ms 2252 KB Output is correct
10 Correct 38 ms 7604 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 5 ms 1228 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 11 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 10 ms 2188 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 1980 KB Output is correct
14 Correct 10 ms 2252 KB Output is correct
15 Correct 23 ms 2600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 53 ms 7964 KB Output is correct
10 Correct 39 ms 6760 KB Output is correct
11 Correct 14 ms 2920 KB Output is correct
12 Correct 18 ms 3276 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 59 ms 7884 KB Output is correct
10 Correct 39 ms 6844 KB Output is correct
11 Correct 15 ms 2896 KB Output is correct
12 Correct 18 ms 3300 KB Output is correct
13 Correct 5 ms 988 KB Output is correct
14 Correct 79 ms 9548 KB Output is correct
15 Correct 73 ms 10448 KB Output is correct
16 Correct 11 ms 2376 KB Output is correct
17 Correct 51 ms 6756 KB Output is correct
18 Correct 24 ms 4428 KB Output is correct