Submission #921180

# Submission time Handle Problem Language Result Execution time Memory
921180 2024-02-03T12:06:37 Z Macker Gondola (IOI14_gondola) C++17
100 / 100
19 ms 2396 KB
#include "gondola.h"
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()

ll mod = 1000000009;

ll power(ll n, ll k){
    ll res = 1;
    n %= mod;
    while(k > 0){
        if(k & 1) res = (res * n) % mod;
        n = (n * n) % mod;
        k /= 2;
    }
    return res;
}

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

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        v[i] = {gondolaSeq[i], i};
    }
    sort(all(v));

    ll strt = -1;
    for (auto &i : v) {
        if(i.first <= n){
            strt = (i.second - i.first + 1 + n) % n;
            break;
        }
    }
    if(strt == -1) strt = 0;
    for (int i = 0; i < n; i++) {
        gondolaSeq[i] = (i - strt + n) % n + 1;
    }
    
    
    int ls = n;
    int j = 0;
    for (auto &i : v) {
        while(ls < i.first){
            replacementSeq[j++] = gondolaSeq[i.second];
            ls++;
            gondolaSeq[i.second] = ls;
        }
    }
    return j;
}

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


int countReplacement(int n, int inputSeq[])
{
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
        v[i] = {inputSeq[i], i};
    }
    sort(all(v));
    for (int i = 1; i < v.size(); i++) {
        if(v[i].first == v[i - 1].first) return 0;
    }
    
    ll strt = -1;
    ll fin = 0;
    bool m = true;
    ll res = 1;
    for (int j = 0; j < v.size(); j++) {
        auto i = v[j];
        if(i.first <= n){
            if(strt == -1){
                strt = (i.second - i.first + 1 + n) % n;
            }
            else{
                if((i.second - i.first + 1 + n) % n != strt) return 0;
            }
            m = false;
        }
        else{
            ll ls;
            if(j == 0 || v[j - 1].first <= n){
                ls = n + 1;
            }
            else ls = v[j - 1].first + 1;
            res = (res * power(n - fin, i.first - ls)) % mod;
        }
        fin++;
    }
    if(m) res = (res * n) % mod;
    return res;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i = 1; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
gondola.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for (int j = 0; j < v.size(); j++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 5 ms 860 KB Output is correct
7 Correct 12 ms 1528 KB Output is correct
8 Correct 8 ms 1116 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
10 Correct 11 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 5 ms 704 KB Output is correct
7 Correct 12 ms 1232 KB Output is correct
8 Correct 8 ms 1116 KB Output is correct
9 Correct 4 ms 496 KB Output is correct
10 Correct 12 ms 1372 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 5 ms 1112 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 12 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 8 ms 1372 KB Output is correct
12 Correct 9 ms 1372 KB Output is correct
13 Correct 10 ms 1116 KB Output is correct
14 Correct 7 ms 1368 KB Output is correct
15 Correct 15 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 444 KB Output is correct
9 Correct 11 ms 1880 KB Output is correct
10 Correct 9 ms 1372 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 11 ms 1628 KB Output is correct
10 Correct 9 ms 1388 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 5 ms 860 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 17 ms 2004 KB Output is correct
15 Correct 19 ms 2396 KB Output is correct
16 Correct 3 ms 608 KB Output is correct
17 Correct 11 ms 1732 KB Output is correct
18 Correct 7 ms 1128 KB Output is correct