답안 #796797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796797 2023-07-28T18:26:39 Z kirakaminski968 곤돌라 (IOI14_gondola) C++17
100 / 100
47 ms 5696 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+9;
int valid(int n, int inputSeq[]){
    set<int> s;
    for(int i = 0;i<n;++i){
        if(s.find(inputSeq[i]) != s.end()){
            return 0;
        }
        s.insert(inputSeq[i]);
    }
    int pos = -1;
    for(int i = 0;i<n;++i){
        if(inputSeq[i] <= n){
            if(pos == -1){
                pos = i;
            }
            else{
                int ch = i+inputSeq[pos]-pos+n;
                ch %= n;
                if(ch == 0) ch = n;
                if(inputSeq[i] != ch) return 0;
            }
        }
    }
    return 1;
}
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int shift = -1;
    for(int i = 0;i<n;++i){
        if(gondolaSeq[i] <= n){
            shift = gondolaSeq[i]-i-1+n;
            shift %= n;
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    for(int i = 0;i<n;++i){
        int realpos = (i-shift+n)%n;
        if(gondolaSeq[realpos] > n){
            pq.push({gondolaSeq[realpos],i+1});
        }
    }
    int l = 0, cur = n+1; //length of the replacement sequence
    while(!pq.empty()){
        pair<int,int> p = pq.top(); pq.pop();
        replacementSeq[l++] = p.second;
        for(int i = cur;i<p.first;++i){
            replacementSeq[l++] = i;
        }
        cur = p.first+1;
    }
    return l;
}
ll pow(int a, int x){
    ll res = 1, cur = a;
    while(x != 0){
        if(x & 1) res *= cur;
        cur *= cur;
        cur %= MOD;
        res %= MOD;
        x /= 2;
    }
    return res;
}
int countReplacement(int n, int inputSeq[]){
    if(!valid(n,inputSeq)) return 0;
    int num = 0;
    int newseq[100005] = {};
    for(int i = 0;i<n;++i){
        if(inputSeq[i] > n){
            newseq[num++] = inputSeq[i];
        }
    }
    if(num == 0) return 1;
    sort(newseq,newseq+num);
    long long ans = 1; int cnt = num;
    if(num == n) ans = num;
    int last = n;
    for(int i = 0;i<num;++i){
        ans *= pow(cnt,newseq[i]-last-1);
        ans %= MOD;
        last = newseq[i];
        cnt--;
    }
    return (int)ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 10 ms 2384 KB Output is correct
7 Correct 7 ms 956 KB Output is correct
8 Correct 20 ms 4208 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 24 ms 4832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 264 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2360 KB Output is correct
7 Correct 7 ms 960 KB Output is correct
8 Correct 22 ms 4160 KB Output is correct
9 Correct 6 ms 1492 KB Output is correct
10 Correct 24 ms 4804 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 12 ms 2220 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 30 ms 4868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 308 KB Output is correct
5 Correct 0 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 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 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 304 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 308 KB Output is correct
11 Correct 7 ms 980 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 12 ms 1488 KB Output is correct
14 Correct 6 ms 980 KB Output is correct
15 Correct 16 ms 2360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 688 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 688 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 692 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 0 ms 596 KB Output is correct
5 Correct 1 ms 692 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 34 ms 4744 KB Output is correct
10 Correct 24 ms 4008 KB Output is correct
11 Correct 9 ms 1952 KB Output is correct
12 Correct 11 ms 2260 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 692 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 692 KB Output is correct
6 Correct 1 ms 688 KB Output is correct
7 Correct 1 ms 692 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 31 ms 4548 KB Output is correct
10 Correct 24 ms 3896 KB Output is correct
11 Correct 9 ms 1964 KB Output is correct
12 Correct 11 ms 2196 KB Output is correct
13 Correct 3 ms 980 KB Output is correct
14 Correct 38 ms 5020 KB Output is correct
15 Correct 47 ms 5696 KB Output is correct
16 Correct 7 ms 1660 KB Output is correct
17 Correct 28 ms 3972 KB Output is correct
18 Correct 15 ms 2676 KB Output is correct