Submission #573541

# Submission time Handle Problem Language Result Execution time Memory
573541 2022-06-06T19:21:11 Z Valaki2 Gondola (IOI14_gondola) C++14
100 / 100
43 ms 6016 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

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

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

signed replacement(signed n, signed gondolaSeq[], signed replacementSeq[]) {
    vector<pair<int, int> > v(n, mp(0, 0));
    for(int i = 0; i < n; i++) {
        v[i] = mp(gondolaSeq[i], i);
    }
    sort(v.begin(), v.end());
    vector<int> lab(n, 0);
    int pos = 0, val = 1;
    for(int i = 0; i < n; i++) {
        if(gondolaSeq[i] <= n) {
            pos = i;
            val = gondolaSeq[i];
        }
    }
    for(int i = pos; i < pos + n; i++) {
        lab[i % n] = val;
        val++;
        while(val > n) {
            val -= n;
        }
    }
    int last = n;
    vector<int> ans;
    for(int i = 0; i < n; i++) {
        if(v[i].fi > n) {
            for(int j = last + 1; j <= v[i].fi; j++) {
                ans.pb(lab[v[i].se]);
                lab[v[i].se] = n + ans.size();
            }
            last = v[i].fi;
        }
    }
    int l = ans.size();
    for(int i = 0; i < l; i++) {
        replacementSeq[i] = ans[i];
    }
    return l;
}

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

const int mod = 1e9 + 9;

int add(int a, int b) {
    return (a + b) % mod;
}

int subt(int a, int b) {
    return (a - b + mod) % mod;
}

int mult(int a, int b) {
    return (a * b) % mod;
}

int sq(int a) {
    return mult(a, a);
}

int power(int a, int b) {
    if(b == 0) {
        return 1;
    }
    if(b % 2 == 1) {
        return mult(a, power(a, b - 1));
    } else {
        return sq(power(a, b / 2));
    }
}

signed countReplacement(signed n, signed inputSeq[]) {
    bool factorial = false;
    if(true) {
        set<int> nums;
        for(int i = 0; i < n; i++) {
            nums.insert(inputSeq[i]);
        }
        if(nums.size() < n) {
            return 0;
        }
        int pos = -1;
        for(int i = 0; i < n; i++) {
            if(inputSeq[i] <= n) {
                pos = i;
            }
        }
        if(pos != -1) {
            for(int i = 0; i < pos; i++) {
                if(inputSeq[i] <= n) {
                    if(pos - i != (inputSeq[pos] - inputSeq[i] + n) % n) {
                        return 0;
                    }
                }
            }
        } else {
            factorial = true;
        }
    }
    sort(inputSeq, inputSeq + n);
    int ans = 1;
    if(factorial) {
        // old code
        /*for(int i = 1; i <= n; i++) {
            ans = mult(ans, i);
        }*/
        ans = mult(ans, n);
    }
    for(int i = 1; i < n; i++) {
        if(inputSeq[i] > n) {
            ans = mult(ans, power(n - i, inputSeq[i] - max(n, inputSeq[i - 1]) - 1));
        }
    }
    if(inputSeq[0] > n) {
        ans = mult(ans, power(n, inputSeq[0] - n - 1));
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:16:20: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     if(nums.size() < n) {
      |        ~~~~~~~~~~~~^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:24: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  117 |         if(nums.size() < n) {
      |            ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 13 ms 2384 KB Output is correct
7 Correct 32 ms 4148 KB Output is correct
8 Correct 20 ms 4316 KB Output is correct
9 Correct 8 ms 1564 KB Output is correct
10 Correct 23 ms 4980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 2340 KB Output is correct
7 Correct 26 ms 4052 KB Output is correct
8 Correct 21 ms 4324 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 23 ms 4920 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 12 ms 2260 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 30 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 432 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 0 ms 304 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 436 KB Output is correct
11 Correct 11 ms 2888 KB Output is correct
12 Correct 11 ms 3260 KB Output is correct
13 Correct 15 ms 2636 KB Output is correct
14 Correct 13 ms 2856 KB Output is correct
15 Correct 22 ms 3032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 32 ms 4416 KB Output is correct
10 Correct 25 ms 3724 KB Output is correct
11 Correct 9 ms 1492 KB Output is correct
12 Correct 11 ms 1876 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 300 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 39 ms 4544 KB Output is correct
10 Correct 26 ms 3668 KB Output is correct
11 Correct 10 ms 1596 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 42 ms 5368 KB Output is correct
15 Correct 43 ms 6016 KB Output is correct
16 Correct 7 ms 1364 KB Output is correct
17 Correct 28 ms 4152 KB Output is correct
18 Correct 19 ms 2364 KB Output is correct