Submission #1092076

# Submission time Handle Problem Language Result Execution time Memory
1092076 2024-09-23T04:44:33 Z huyngo Gondola (IOI14_gondola) C++17
100 / 100
47 ms 5968 KB
#include "gondola.h"
#include <bits/stdc++.h>  
using namespace std;
using ll = long long;
using i64 = long long;
void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char* x) { cerr << '"' << x << '"'; } void __print(const string& x) { cerr << '"' << x << '"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template<typename T, typename V> void __print(const pair<T, V>& x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template<typename T> void __print(const T& x) { int f = 0; cerr << '{'; for (auto& i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#define ln "\n"
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define ar array
int Bit(int mask, int b) { return (mask >> b) & 1; }
const ll base = 311, MOD = 998244353, M = 1e9 + 9, INF = 1e18;

int valid(int n, int inputSeq[]) {
    rep(i, 0, n - 1) inputSeq[i]--;
    int x = -1;
    rep(i, 0, n - 1)
        if (inputSeq[i] < n) {
            x = (inputSeq[i] - i + n) % n;
            break;
        }
    map<int, int> mp;
    rep(i, 0, n - 1) {
        mp[inputSeq[i]]++;
        if (mp[inputSeq[i]] > 1) return 0;
    }
    if (x == -1)
        return 1;
    rep(i, 0, n - 1)
        if (inputSeq[i] < n &&
            x != (inputSeq[i] - i + n) % n)
            return 0;
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    vector<int> a(n);
    rep(i, 0, n - 1)
        a[i] = gondolaSeq[i] - 1;
    int x = 0;
    rep(i, 0, n - 1) if (a[i] < n)
        x = (a[i] - i + n) % n;
    vector<ar<int, 2>> f(n);
    rep(i, 0, n - 1)
        f[i] = { a[i], (i + x) % n };
    sort(all(f));

    int l = 0, cur = n - 1;
    rep(i, 0, n - 1) {
        if (f[i][0] >= n) {
            rep(j, cur + 1, f[i][0]) {
                replacementSeq[l++] = f[i][1] + 1;
                f[i][1] = j;
            }
            cur = f[i][0];
        }
    }
    return l;
}

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

ll power(ll x, ll n) {
    ll res = 1;
    for (; n > 0; n >>= 1) {
        if (n & 1)
            res = (res * x) % M;
        x = (x * x) % M;
    }
    return res;
}

int countReplacement(int n, int inputSeq[]) {
    if (!valid(n, inputSeq)) return 0;
    vector<int> a(n);
    rep(i, 0, n - 1)
        a[i] = inputSeq[i];
    int x = -1;
    rep(i, 0, n - 1) if (a[i] < n)
        x = (a[i] - i + n) % n;
    ll res = 1;
    if (x == -1) {
        res = n;
        x = 0;
    }
    vector<ar<int, 2>> f(n);
    rep(i, 0, n - 1)
        f[i] = { a[i], (i + x) % n };
    sort(all(f));

    int cur = n - 1;
    ll count = 0;
    rep(i, 0, n - 1)
        count += (f[i][0] > f[i][1]);

    rep(i, 0, n - 1) {
        if (f[i][0] >= n) {
            // res *= 'count (f[i][1] < f[i][0])' ^ (f[i][0]-cur-1)
            // rep(j, cur + 1, f[i][0]) {
                // replacementSeq[l++] = f[i][1] + 1;
                // f[i][1] = j;
            // }
            res = (res * power(count, f[i][0] - cur - 1)) % M;
            f[i][1] = f[i][0];
            --count;
            cur = f[i][0];
        }
    }
    return res;
}

// int main() {
//     return 0;
// }
# 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 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 9 ms 2360 KB Output is correct
7 Correct 6 ms 1112 KB Output is correct
8 Correct 17 ms 4448 KB Output is correct
9 Correct 5 ms 1592 KB Output is correct
10 Correct 22 ms 4956 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 1 ms 348 KB Output is correct
6 Correct 9 ms 2384 KB Output is correct
7 Correct 6 ms 1116 KB Output is correct
8 Correct 18 ms 4444 KB Output is correct
9 Correct 6 ms 1624 KB Output is correct
10 Correct 22 ms 5160 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 15 ms 2268 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 32 ms 5212 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 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 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 444 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 1 ms 604 KB Output is correct
9 Correct 0 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 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 348 KB Output is correct
11 Correct 9 ms 2136 KB Output is correct
12 Correct 10 ms 2136 KB Output is correct
13 Correct 11 ms 1476 KB Output is correct
14 Correct 9 ms 1884 KB Output is correct
15 Correct 12 ms 2264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 452 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 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
# 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 44 ms 4620 KB Output is correct
10 Correct 28 ms 3676 KB Output is correct
11 Correct 10 ms 1624 KB Output is correct
12 Correct 16 ms 2056 KB Output is correct
13 Correct 3 ms 600 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 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
9 Correct 34 ms 4440 KB Output is correct
10 Correct 28 ms 3676 KB Output is correct
11 Correct 10 ms 1628 KB Output is correct
12 Correct 12 ms 1968 KB Output is correct
13 Correct 3 ms 604 KB Output is correct
14 Correct 44 ms 5460 KB Output is correct
15 Correct 47 ms 5968 KB Output is correct
16 Correct 8 ms 1368 KB Output is correct
17 Correct 32 ms 4284 KB Output is correct
18 Correct 17 ms 2396 KB Output is correct