답안 #500766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
500766 2022-01-01T08:25:56 Z InternetPerson10 곤돌라 (IOI14_gondola) C++17
100 / 100
27 ms 3352 KB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const ll MOD = 1000000009;

int valid(int n, int inputSeq[]) {
    vector<int> nums(n);
    for(int i = 0; i < n; i++) {
        nums[i] = inputSeq[i];
    }
    sort(nums.begin(), nums.end());
    int mi = nums[n-1];
    for(int i = 0; i < n-1; i++) {
        if(nums[i] == nums[i+1]) return 0;
        mi = min(mi, nums[i]);
    }
    if(mi > n) return 1;
    int k = 0;
    for(int i = 0; i < n; i++) {
        if(mi == inputSeq[i]) k = i;
    }
    k -= mi;
    k += (n+1);
    k %= n;
    for(int i = 0; i < n; i++) {
        nums[i] = inputSeq[(k+i)%n];
    }
    for(int i = 0; i < n; i++) {
        if(nums[i] <= n && nums[i] != i+1) return 0;
    }
    return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    vector<int> nums(n);
    int mi = MOD;
    for(int i = 0; i < n; i++) nums[i] = gondolaSeq[i];
    for(int i = 0; i < n; i++) {
        mi = min(mi, nums[i]);
    }
    ll k = 0;
    for(int i = 0; i < n; i++) {
        if(mi == gondolaSeq[i]) k = i;
    }
    k -= mi;
    k += (n+1);
    k += (ll)(mi) * (ll)(n);
    k %= n;
    for(int i = 0; i < n; i++) {
        nums[i] = gondolaSeq[(k+i)%n];
    }
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++) {
        v.push_back({nums[i], i+1});
    }
    sort(v.begin(), v.end());
    int g = 0;
    for(int i = 0; i < v.size(); i++) {
        while(v[i].second != v[i].first) {
            replacementSeq[g] = v[i].second;
            v[i].second = g+n+1;
            g++;
        }
    }
    return g;
}

ll modpow(ll n, ll e) {
    if(e == 0) return 1;
    ll x = modpow(n, e/2);
    x *= x;
    x %= MOD;
    if(e%2) {
        x *= n;
        x %= MOD;
    }
    return x;
}

int countReplacement(int n, int inputSeq[]) {
    if(!valid(n, inputSeq)) return 0;
    vector<int> nums(n);
    int mi = MOD;
    for(int i = 0; i < n; i++) nums[i] = inputSeq[i];
    for(int i = 0; i < n; i++) {
        mi = min(mi, nums[i]);
    }
    ll k = 0;
    for(int i = 0; i < n; i++) {
        if(mi == inputSeq[i]) k = i;
    }
    k -= mi;
    k += (n+1);
    k += (ll)(mi) * (ll)(n);
    k %= n;
    for(int i = 0; i < n; i++) {
        nums[i] = inputSeq[(k+i)%n];
    }
    vector<pair<int, int>> v;
    for(int i = 0; i < n; i++) {
        v.push_back({nums[i], i+1});
    }
    sort(v.begin(), v.end());
    ll ans = 1;
    if(mi > n) ans = n;
    int g = 0;
    for(int i = 0; i < v.size(); i++) {
        if(v[i].first == v[i].second) continue;
        v[i].second = g+n+1;
        ans *= modpow(v.size() - i, v[i].first - v[i].second);
        ans %= MOD;
        g = v[i].first-n;
    }
    return ans;
}

Compilation message

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i = 0; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:110:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |     for(int i = 0; i < v.size(); i++) {
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 6 ms 588 KB Output is correct
7 Correct 12 ms 972 KB Output is correct
8 Correct 9 ms 844 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 14 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 6 ms 588 KB Output is correct
7 Correct 13 ms 972 KB Output is correct
8 Correct 9 ms 844 KB Output is correct
9 Correct 4 ms 460 KB Output is correct
10 Correct 13 ms 844 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 6 ms 460 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 13 ms 956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 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 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 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
11 Correct 10 ms 2012 KB Output is correct
12 Correct 11 ms 2116 KB Output is correct
13 Correct 13 ms 1260 KB Output is correct
14 Correct 9 ms 1988 KB Output is correct
15 Correct 18 ms 2216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 2 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 21 ms 1964 KB Output is correct
10 Correct 15 ms 1520 KB Output is correct
11 Correct 6 ms 788 KB Output is correct
12 Correct 7 ms 844 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 20 ms 1940 KB Output is correct
10 Correct 16 ms 1500 KB Output is correct
11 Correct 6 ms 844 KB Output is correct
12 Correct 8 ms 844 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 24 ms 2452 KB Output is correct
15 Correct 27 ms 3352 KB Output is correct
16 Correct 5 ms 940 KB Output is correct
17 Correct 19 ms 1976 KB Output is correct
18 Correct 11 ms 1524 KB Output is correct