답안 #763644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763644 2023-06-22T14:48:06 Z Ahmed57 곤돌라 (IOI14_gondola) C++17
60 / 100
16 ms 2196 KB
#include "gondola.h"

#include <bits/stdc++.h>

using namespace std;

int valid(int n, int inputSeq[]){
    bool ss = 0;
    int ind = 0 , val = 0;
    map<int,int> mp;
    for(int i = 0;i<n;i++){
        if(inputSeq[i]<=n){
            ss = 1;
            val = inputSeq[i]-1;
            ind = i;
        }else{
            if(mp[inputSeq[i]]==1){
                return 0;
            }mp[inputSeq[i]] = 1;
        }
    }
    if(!ss)return 1;
    for(int i = ind+1;i<n;i++){
        val++;
        val%=n;
        if(inputSeq[i]<=n){
            if((inputSeq[i]-1)!=val)return 0;
        }
    }
    for(int i = 0;i<ind;i++){
        val++;val%=n;
        if(inputSeq[i]<=n){
            if((inputSeq[i]-1)!=val)return 0;
        }
    }
    return 1;
}int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    vector<pair<int,int>> v;
    int ind = 0, val = 0;bool ss = 0;
    for(int i = 0;i<n;i++){
        if(gondolaSeq[i]<=n){
            ind = i;val = gondolaSeq[i]-1;
            ss = 1;
        }
    }
    int lol[n];
    if(ss){
        lol[ind] = val;
        for(int i = ind+1;i<n;i++){
            val++;
            val%=n;
            lol[i] = val;
        }
        for(int i = 0;i<ind;i++){
            val++;val%=n;
            lol[i] = val;
        }
    }
    for(int i = 0;i<n;i++){
        if(gondolaSeq[i]>n){
            v.push_back({gondolaSeq[i],(ss==0?i+1:lol[i]+1)});
        }
    }
    sort(v.begin(),v.end());
    int l = n+1;
    int st =0;
    for(int i = 0;i<v.size();i++){
        replacementSeq[st++] = v[i].second;
        ++l;
        while(l<=v[i].first){
            replacementSeq[st++] = l-1;
            l++;
        }
    }
    return st;
}
long long mod = 1000000007;
//Fast
long long fast(long long a,long long b){
    if(b==0)return 1;
    if(b==1)return a%mod;
    long long ha = fast(a,b/2)%mod;
    if(b%2==0)return (ha*ha)%mod;
    else return (((ha*ha)%mod)*a)%mod;
}
int countReplacement(int n, int inputSeq[]){
    bool ss = 0;
    int ind = 0 , val = 0;
    map<int,int> mp;
    for(int i = 0;i<n;i++){
        if(inputSeq[i]<=n){
            ss = 1;
            val = inputSeq[i]-1;
            ind = i;
        }else{
            if(mp[inputSeq[i]]==1){
                return 0;
            }mp[inputSeq[i]] = 1;
        }
    }
    long long mul = 1;
    if(!ss){
        mul = n;
    }
    for(int i = ind+1;i<n;i++){
        val++;
        val%=n;
        if(inputSeq[i]<=n){
            if((inputSeq[i]-1)!=val)return 0;
        }
    }
    for(int i = 0;i<ind;i++){
        val++;val%=n;
        if(inputSeq[i]<=n){
            if((inputSeq[i]-1)!=val)return 0;
        }
    }
    vector<long long> v;
    for(int i = 0;i<n;i++){
        if(inputSeq[i]>n){
            v.push_back(inputSeq[i]);
        }
    }
    sort(v.begin(),v.end());
    long long all = mul;
    long long la = n+1;
    for(int i = 0;i<v.size();i++){
        long long diff = v[i]-la , rem = v.size()-i;
        all*=fast(rem,diff);
        la = v[i]+1;
    }
    return all;
}
/*
int main(){
    int S[] = {3,4};
    cout<<countReplacement(2,S);
}*/

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int i = 0;i<v.size();i++){
      |                   ~^~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:127:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |     for(int i = 0;i<v.size();i++){
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 6 ms 616 KB Output is correct
8 Correct 6 ms 596 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 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 3 ms 340 KB Output is correct
7 Correct 6 ms 560 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 13 ms 2020 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 15 ms 1672 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 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 0 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 1 ms 228 KB Output is correct
7 Correct 0 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 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 232 KB Output is correct
4 Correct 1 ms 260 KB Output is correct
5 Correct 1 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 340 KB Output is correct
11 Correct 6 ms 864 KB Output is correct
12 Correct 7 ms 980 KB Output is correct
13 Correct 11 ms 1352 KB Output is correct
14 Correct 6 ms 852 KB Output is correct
15 Correct 16 ms 2196 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 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 0 ms 212 KB Integer 1478020098 violates the range [0, 1000000008]
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 304 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Incorrect 1 ms 212 KB Integer 1478020098 violates the range [0, 1000000008]
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 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 1 ms 212 KB Output is correct
7 Incorrect 1 ms 304 KB Integer 1478020098 violates the range [0, 1000000008]
8 Halted 0 ms 0 KB -