Submission #147783

# Submission time Handle Problem Language Result Execution time Memory
147783 2019-08-30T16:07:27 Z karma Gondola (IOI14_gondola) C++14
100 / 100
37 ms 2552 KB
#include <bits/stdc++.h>
#include "gondola.h"
#define pb      emplace_back
#define fi      first
#define se      second

using namespace std;

const int N = int(3e5) + 2;
const int M = int(1e6) + 1;
const int mod = int(1e9) + 9;

int dem[N];

int valid(int n, int p[])
{
    int mn = 0;
    vector<int> v(p, p + n);
    sort(v.begin(), v.end());
    for(int i = 1; i < n; ++i) {
        if(v[i] == v[i - 1]) return 0;
        if(p[mn] > p[i]) mn = i;
    }
    if(p[mn] > n) return 1;
    for(int i = mn, lim = mn + n; i < lim; ++i)
        if(p[i % n] <= n && p[i % n] - p[mn] != i - mn) return 0;
    return 1;
}

typedef pair<int, int> pii;
int replacement(int n, int p[], int res[])
{
    int mn = 0, cnt = 0;
    vector<int> org(n);
    vector<pii> v;
    for(int i = 0; i < n; ++i) {
       if(p[mn] > p[i]) mn = i;
       if(p[i] > n) v.pb(i, p[i]);
    }
    sort(v.begin(), v.end(), [](const pii& x, const pii& y){
            return x.se < y.se;
         });
    for(int i = mn, lim = mn + n; i < lim; ++i) {
       if(p[mn] > n) org[i - mn] = i - mn + 1;
       else org[i % n] = (p[mn] + i - mn - 1) % n + 1;
    }
    mn = n + 1;
    for(pii x: v) {
        res[cnt ++] = org[x.fi];
        while(mn < x.se) res[cnt ++] = mn ++;
        mn = x.se + 1;
    }
    return cnt;
}

int Power(int x, int y)
{
    int res = 1;
    while(y) {
        if(y & 1) res = 1ll * res * x % mod;
        x = 1ll * x * x % mod;
        y >>= 1;
    }
    return res;
}

int countReplacement(int n, int p[])
{
    if(!valid(n, p)) return 0;
    int mn = n + 1, pre, res;
    vector<int> v;
    for(int i = 0; i < n; ++i) {
        mn = min(mn, p[i]);
        if(p[i] > n) v.pb(p[i]);
    }
    sort(v.begin(), v.end(), greater<int>());
    res = mn > n? n: 1;
    pre = n + 1;
    while(!v.empty()) {
        res = 1ll * res * Power(v.size(), v.back() - pre) % mod;
        pre = v.back() + 1; v.pop_back();
    }
    return res;
}
//
//int n, a[N], cmd, res[N];
//
//int main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//    if(fopen("test.inp", "r")) {
//        freopen("test.inp", "r", stdin);
//        freopen("test.out", "w", stdout);
//    }
//    int nTest;
//    cin >> nTest;
//    while(nTest --) {
//        cin >> cmd >> n;
//        for(int i = 0; i < n; ++i) cin >> a[i];
//        if(cmd == 1) cout << valid(n, a) << '\n';
//        else if(cmd == 2) {
//            int sz = replacement(n, a, res);
//            for(int i = 0; i < sz; ++i) cout << res[i] << ' ';
//            cout << '\n';
//        } else cout << countReplacement(n, a) << '\n';
//    }
//}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 10 ms 888 KB Output is correct
7 Correct 20 ms 1528 KB Output is correct
8 Correct 15 ms 1244 KB Output is correct
9 Correct 7 ms 644 KB Output is correct
10 Correct 21 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 10 ms 888 KB Output is correct
7 Correct 20 ms 1528 KB Output is correct
8 Correct 14 ms 1272 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 20 ms 1400 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 10 ms 888 KB Output is correct
14 Correct 2 ms 252 KB Output is correct
15 Correct 23 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 13 ms 1400 KB Output is correct
12 Correct 14 ms 1528 KB Output is correct
13 Correct 18 ms 1512 KB Output is correct
14 Correct 13 ms 1400 KB Output is correct
15 Correct 24 ms 2408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 27 ms 1580 KB Output is correct
10 Correct 21 ms 1404 KB Output is correct
11 Correct 9 ms 760 KB Output is correct
12 Correct 12 ms 888 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 26 ms 1608 KB Output is correct
10 Correct 21 ms 1404 KB Output is correct
11 Correct 10 ms 760 KB Output is correct
12 Correct 11 ms 888 KB Output is correct
13 Correct 4 ms 508 KB Output is correct
14 Correct 33 ms 2340 KB Output is correct
15 Correct 37 ms 2552 KB Output is correct
16 Correct 8 ms 760 KB Output is correct
17 Correct 25 ms 1644 KB Output is correct
18 Correct 15 ms 1248 KB Output is correct