답안 #374170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
374170 2021-03-06T19:37:46 Z ritul_kr_singh 곤돌라 (IOI14_gondola) C++17
100 / 100
79 ms 9068 KB
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define sp << " " <<
#define nl << "\n"
#define ll long long
 
int valid(int n, int a[]){
    ll least = n+1, ind = -1;
    map<ll, ll> m;
    for(ll i=0; i<n; ++i){
        if(a[i] < least) least = a[i], ind = i;
        if(m[a[i]]) return 0;
        ++m[a[i]];
    }
    if(least<=n){
        for(ll ii=0, i=ind; ii<n; ++ii, i=(i+1)%n){
            if(a[i]<=n and a[i]!=ii+least) return 0;
        }
    }
    return 1;
}

int replacement(int n, int* inp, int* ans){
    ll least = n+1, ind = 0;
    for(ll i=0; i<n; ++i){
        if(inp[i] < least) least = inp[i], ind = i;
    }
    if(least>n) least = 1;
    ll inp0[n];
    for(ll ii=0, i=ind; ii<n; ++ii, i=(i+1)%n) inp0[i] = ii+least;
    for(int i=0; i<n; ++i){
        if(inp0[i]>n) inp0[i] -= n;
    }

    vector<pair<ll, ll>> b;
    for(ll i=0; i<n; ++i) b.emplace_back(inp[i], i);
    sort(b.begin(), b.end());

    vector<vector<ll>> a(n);
    ll toPut = 0, extra = n+1;
    for(auto ii : b){
        ll i = ii.second;
        if(inp[i]>n){
            ans[toPut++] = inp0[i];
            for(ll j=extra; j<inp[i]; ++j){
                ans[toPut++] = j;
            }
            extra = inp[i] + 1;
        }
    }
    return toPut;
}

ll modExpo(ll x, ll p){
    ll m = 1e9 + 9;
    ll res = 1, toMul = x % m;
    while(p){
        if(p&1){
            res = (res * toMul) % m;
        }
        toMul = (toMul * toMul) % m;
        p /= 2;
    }
    return res;
}

int countReplacement(int n, int inp[]){
    const ll MOD = 1e9 + 9;
    if(!valid(n, inp)) return 0;
    ll res = 1;
    if(*min_element(inp, inp+n)>n) res = n;

    vector<pair<ll, ll>> b;
    for(ll i=0; i<n; ++i) b.emplace_back(inp[i], i);
    sort(b.begin(), b.end());

    ll extra = n+1, left = 0;
    for(ll i=0; i<n; ++i) left += (inp[i]>n);

    for(auto ii : b){
        ll i = ii.second;
        if(inp[i]<=n) continue;
        ll possible = inp[i] - extra;
        res = (res*modExpo(left, possible));
        res %= MOD;
        --left;
        extra = inp[i] + 1;
    }
    res += MOD;
    res %= MOD;
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 16 ms 2796 KB Output is correct
7 Correct 11 ms 748 KB Output is correct
8 Correct 35 ms 5100 KB Output is correct
9 Correct 10 ms 1900 KB Output is correct
10 Correct 38 ms 5868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 17 ms 2796 KB Output is correct
7 Correct 10 ms 748 KB Output is correct
8 Correct 37 ms 5100 KB Output is correct
9 Correct 10 ms 1900 KB Output is correct
10 Correct 38 ms 6016 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 19 ms 2668 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 52 ms 5996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 376 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 16 ms 4956 KB Output is correct
12 Correct 18 ms 5596 KB Output is correct
13 Correct 18 ms 2656 KB Output is correct
14 Correct 15 ms 4828 KB Output is correct
15 Correct 25 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 51 ms 6380 KB Output is correct
10 Correct 42 ms 4844 KB Output is correct
11 Correct 15 ms 2284 KB Output is correct
12 Correct 18 ms 2284 KB Output is correct
13 Correct 4 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 380 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 54 ms 6380 KB Output is correct
10 Correct 42 ms 4716 KB Output is correct
11 Correct 15 ms 2284 KB Output is correct
12 Correct 18 ms 2284 KB Output is correct
13 Correct 4 ms 876 KB Output is correct
14 Correct 71 ms 8172 KB Output is correct
15 Correct 79 ms 9068 KB Output is correct
16 Correct 14 ms 1900 KB Output is correct
17 Correct 51 ms 6252 KB Output is correct
18 Correct 24 ms 3564 KB Output is correct