답안 #428262

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428262 2021-06-15T09:15:28 Z Dakto 곤돌라 (IOI14_gondola) C++17
100 / 100
95 ms 6084 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

int valid(int n, int inputSeq[])
{
    int begind=-1;
    map<int,int> m;
    for(int i=0; i<n; i++){
        if(m[inputSeq[i]]) return 0;
        m[inputSeq[i]]++;
        if(inputSeq[i]<=n){
            if(begind==-1){
                begind=(n+i-inputSeq[i]+1)%n;
            }
            else if((n+i-begind)%n+1!=inputSeq[i]) return 0;
        }
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int begind=0;
    map<int,int> m;
    for(int i=0; i<n; i++){
        if(gondolaSeq[i]>n){
            m[gondolaSeq[i]]=i;
        }
        else begind=(n+i-gondolaSeq[i]+1)%n;
    }
    int c=n+1;
    for(auto i:m){
        int curr=(n+i.second-begind)%n+1;
        while(curr!=i.first){
            replacementSeq[c-n-1]=curr;
            curr=c;
            c++;
        }
    }
    return c-n-1;
}

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


const int mod=1e9+9;

int ipow(long long b,long long p){
    long long res=1;
    while(p){
        if(p&1) res=(res*b)%mod;
        b=(b*b)%mod;
        p>>=1;
    }
    return res;
}

int countReplacement(int n, int inputSeq[])
{
    if(!valid(n,inputSeq)) return 0;
    vector<int> v={n};
    bool setpos=0;
    for(int i=0; i<n; i++){
        if(inputSeq[i]>n){
            v.push_back(inputSeq[i]);
        }
        else setpos=1;
    }
    sort(v.begin(),v.end());
    long long res=setpos?1:n;
    for(int i=1; i<v.size(); i++){
        res=(res*ipow(v.size()-i,v[i]-v[i-1]-1))%mod;
    }
    return res;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i=1; i<v.size(); i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 15 ms 2304 KB Output is correct
7 Correct 13 ms 872 KB Output is correct
8 Correct 38 ms 4096 KB Output is correct
9 Correct 11 ms 1512 KB Output is correct
10 Correct 37 ms 4768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 15 ms 2352 KB Output is correct
7 Correct 11 ms 844 KB Output is correct
8 Correct 38 ms 4116 KB Output is correct
9 Correct 9 ms 1584 KB Output is correct
10 Correct 36 ms 4748 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 11 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 11 ms 716 KB Output is correct
12 Correct 12 ms 824 KB Output is correct
13 Correct 23 ms 2636 KB Output is correct
14 Correct 10 ms 668 KB Output is correct
15 Correct 26 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 50 ms 4444 KB Output is correct
10 Correct 56 ms 3728 KB Output is correct
11 Correct 14 ms 1592 KB Output is correct
12 Correct 18 ms 1868 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 55 ms 4412 KB Output is correct
10 Correct 38 ms 3724 KB Output is correct
11 Correct 14 ms 1484 KB Output is correct
12 Correct 18 ms 1868 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 66 ms 5312 KB Output is correct
15 Correct 95 ms 6084 KB Output is correct
16 Correct 11 ms 1344 KB Output is correct
17 Correct 43 ms 4148 KB Output is correct
18 Correct 24 ms 2380 KB Output is correct