답안 #836798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836798 2023-08-24T15:53:59 Z Jarif_Rahman 곤돌라 (IOI14_gondola) C++17
75 / 100
41 ms 10232 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

const ll md = 1e9+9;

ll pw(ll x, ll p){
    if(!p) return 1;
    if(p&1) return (pw(x, p^1)*x)%md;
    return pw((x*x)%md, p>>1);
}

bool distinct(deque<int> S){
    sort(S.begin(), S.end());
    for(int i = 1; i < S.size(); i++) if(S[i] == S[i-1]) return 0;
    return 1;
}

int valid(int n, int _S[]){
    deque<int> S;
    for(int i = 0; i < n; i++) S.pb(_S[i]);
    int mn = *min_element(S.begin(), S.end());
    while(S[0] != mn) S.pb(S[0]), S.pop_front();

    if(!distinct(S)) return 0;

    for(int i = 1; i < n; i++) if(S[i] <= n){
        if(S[i] != (mn+i-1)%n+1) return 0;
    }

    return 1;
}

int replacement(int n, int _S[], int R[]){
    deque<int> S;
    for(int i = 0; i < n; i++) S.pb(_S[i]);
    int mn = *min_element(S.begin(), S.end());
    while(S[0] != mn) S.pb(S[0]), S.pop_front();

    int mx = *max_element(S.begin(), S.end());
    if(mx == n) return 0;
    int x = (max_element(S.begin(), S.end())-S.begin()+mn-1)%n+1;

    map<int, int> mp;
    for(int i = 0; i < n; i++){
        if(S[i] > n && S[i] != mx) mp[S[i]] = (mn+i-1)%n+1;
    }

    for(int i = n+1; i <= mx; i++){
        if(mp[i] == 0) R[i-n-1] = x, x = i;
        else R[i-n-1] = mp[i];
    }
    return mx-n;
}

int countReplacement(int n, int S[]){
    if(!valid(n, S)) return 0;

    int ans = 1, ls = n;
    vector<int> s;
    for(int i = 0; i < n; i++) if(S[i] > n) s.pb(S[i]);

    sort(s.begin(), s.end());
    for(int i = 0; i < s.size(); i++){
        ans = (ll(ans)*pw(int(s.size())-i, s[i]-ls-1))%md;
        ls = s[i];
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'bool distinct(std::deque<int>)':
gondola.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i = 1; i < S.size(); i++) if(S[i] == S[i-1]) return 0;
      |                    ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:69:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 312 KB Output is correct
6 Correct 4 ms 940 KB Output is correct
7 Correct 12 ms 1840 KB Output is correct
8 Correct 11 ms 1580 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 9 ms 1724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 4 ms 852 KB Output is correct
7 Correct 13 ms 1876 KB Output is correct
8 Correct 8 ms 1468 KB Output is correct
9 Correct 4 ms 700 KB Output is correct
10 Correct 9 ms 1728 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 308 KB Output is correct
13 Correct 6 ms 972 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 14 ms 1852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 312 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 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 432 KB Output is correct
10 Correct 2 ms 468 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 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 6 ms 1364 KB Output is correct
12 Correct 7 ms 1492 KB Output is correct
13 Correct 25 ms 4736 KB Output is correct
14 Correct 9 ms 1340 KB Output is correct
15 Correct 41 ms 10232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 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 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 0 ms 312 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 19 ms 1688 KB Output is correct
10 Correct 13 ms 1468 KB Output is correct
11 Correct 8 ms 832 KB Output is correct
12 Correct 7 ms 868 KB Output is correct
13 Incorrect 2 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 308 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 16 ms 1652 KB Output is correct
10 Correct 13 ms 1376 KB Output is correct
11 Correct 5 ms 724 KB Output is correct
12 Correct 6 ms 828 KB Output is correct
13 Incorrect 2 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -