Submission #1064391

# Submission time Handle Problem Language Result Execution time Memory
1064391 2024-08-18T12:06:54 Z anango Gondola (IOI14_gondola) C++17
90 / 100
270 ms 262144 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000009;

signed valid(signed n, signed inputSeq[]) {
    vector<int> pos(n,-1);
    set<int> seen;
    for (int i=0; i<n; i++) {
        if (inputSeq[i]<=n) {
            pos[inputSeq[i]-1] = i;
        }
        if (seen.count(inputSeq[i]-1)) {
            return 0;   
        }
        seen.insert(inputSeq[i]-1);
    }
    set<int> S;
    for (int i=0; i<n; i++) {
        if (pos[i]!=-1) {
            S.insert((pos[i]-i+n)%n);
        }
    }
    return S.size()<=1;
}

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

signed replacement(signed n, signed gondolaSeq[], signed replacementSeq[]) {
    vector<pair<int,int>> posindex;
    vector<int> actual(n,-1);
    for (int i=0; i<n; i++) {
        if (gondolaSeq[i]<=n) {
            for (int j=0; j<n; j++) {
                actual[j] = (gondolaSeq[i]-1+j-i+3*n)%n;
            }
            break;
        }
    }
    if (actual[0]==-1) {
        for (int i=0; i<n; i++) actual[i] = i;
    }
    for (int i=0; i<n; i++) {
        //cout << actual[i] <<" ";
    }
    //cout << endl;
    for (int i=0; i<n; i++) {
        posindex.push_back({gondolaSeq[i]-1,i});
    }
    sort(posindex.begin(), posindex.end());
    vector<int> repl;
    int cur = n;
    for (int i=0; i<posindex.size(); i++) {
        while (posindex[i].first>=cur) {
            repl.push_back(actual[posindex[i].second]);
            actual[posindex[i].second] = cur;
            cur++;
        }
    }
    for (int i=0; i<repl.size(); i++) {
        replacementSeq[i] = repl[i]+1;
    }
    //cout << "done " << repl.size() << endl;
    return repl.size();
}

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

signed countReplacement(signed n, signed inputSeq[]) {
    vector<int> pos(n,-1);
    set<int> seen;
    for (int i=0; i<n; i++) {
        if (inputSeq[i]<=n) {
            pos[inputSeq[i]-1] = i;
        }
        if (seen.count(inputSeq[i]-1)) {
            return 0;   
        }
        seen.insert(inputSeq[i]-1);
    }
    set<int> S;
    for (int i=0; i<n; i++) {
        if (pos[i]!=-1) {
            S.insert((pos[i]-i+n)%n);
        }
    }
    if (S.size()>1) {
        return 0;
    }

    int prod = 1;
    vector<pair<int,int>> posindex;
    vector<int> actual(n,-1);
    for (int i=0; i<n; i++) {
        if (inputSeq[i]<=n) {
            for (int j=0; j<n; j++) {
                actual[j] = (inputSeq[i]-1+j-i+3*n)%n;
            }
            break;
        }
    }
    if (actual[0]==-1) {
        prod = n; //multiply by n at the end
        for (int i=0; i<n; i++) actual[i] = i;
    }
    for (int i=0; i<n; i++) {
        //cout << actual[i] <<" ";
    }
    //cout << endl;
    for (int i=0; i<n; i++) {
        posindex.push_back({inputSeq[i]-1,i});
    }
    sort(posindex.begin(), posindex.end());
    vector<int> repl;
    int cur = n;
    for (int i=0; i<posindex.size(); i++) {
        while (posindex[i].first>=cur) {
            repl.push_back(actual[posindex[i].second]);
            actual[posindex[i].second] = cur;
            if (posindex[i].first>cur) {
                prod*=n-i;
                prod%=MOD;
            }
            cur++;
        }
    }
    //cout << "done " << repl.size() << endl;
    return (signed)prod;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:54:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i=0; i<posindex.size(); i++) {
      |                   ~^~~~~~~~~~~~~~~~
gondola.cpp:61:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for (int i=0; i<repl.size(); i++) {
      |                   ~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     for (int i=0; i<posindex.size(); i++) {
      |                   ~^~~~~~~~~~~~~~~~
# 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 1 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 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 0 ms 348 KB Output is correct
6 Correct 9 ms 2760 KB Output is correct
7 Correct 6 ms 1928 KB Output is correct
8 Correct 22 ms 4956 KB Output is correct
9 Correct 6 ms 1728 KB Output is correct
10 Correct 23 ms 5680 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 10 ms 2628 KB Output is correct
7 Correct 6 ms 1984 KB Output is correct
8 Correct 18 ms 4984 KB Output is correct
9 Correct 7 ms 1868 KB Output is correct
10 Correct 24 ms 5676 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 12 ms 2612 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 37 ms 7376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 452 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 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 440 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 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 396 KB Output is correct
11 Correct 9 ms 3792 KB Output is correct
12 Correct 11 ms 4048 KB Output is correct
13 Correct 10 ms 3024 KB Output is correct
14 Correct 8 ms 3788 KB Output is correct
15 Correct 14 ms 3088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 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 376 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 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 348 KB Output is correct
2 Correct 0 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 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
9 Correct 34 ms 8768 KB Output is correct
10 Correct 28 ms 7332 KB Output is correct
11 Correct 11 ms 4444 KB Output is correct
12 Correct 13 ms 4020 KB Output is correct
13 Correct 5 ms 3024 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 604 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 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 34 ms 8652 KB Output is correct
10 Correct 27 ms 7380 KB Output is correct
11 Correct 11 ms 4444 KB Output is correct
12 Correct 12 ms 3928 KB Output is correct
13 Correct 5 ms 3020 KB Output is correct
14 Runtime error 270 ms 262144 KB Execution killed with signal 9
15 Halted 0 ms 0 KB -