답안 #584930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
584930 2022-06-28T07:03:25 Z Mazaalai 곤돌라 (IOI14_gondola) C++17
100 / 100
27 ms 3800 KB
#include <bits/stdc++.h>
#include "gondola.h"
#define ALL(x) x.begin(),x.end()
#define LLA(x) x.rbegin(),x.rend()
#define pb push_back
using namespace std;
using PII = pair <int, int>;
using ll = long long;
int valid(int n, int nums[]) {
    int mini = 0;
    for (int i = 1; i < n; i++) 
        if (nums[i] < nums[mini]) mini = i;
    
    int st = nums[mini];
    vector <int> tmp;
    for (int i = 0; i < n; i++) {
        int j = (mini + i) % n;
        if (nums[j] == st+i) continue;
        if (nums[j] > n) tmp.pb(nums[j]);
        if (nums[j] <= n) return 0;
    }
    sort(ALL(tmp));
    for (int i = 1; i < tmp.size(); i++)
        if (tmp[i] == tmp[i-1]) return 0;
    return 1;
}
 
 
int replacement(int n, int nums[], int res[]) {
    int mini = 0, cp[n];
    for (int i = 0; i < n; i++) {
        if (nums[i] < nums[mini]) mini = i;
    }
    iota(cp, cp+n, 1);
    vector <PII> vals;
    if (nums[mini] <= n)
        mini = (mini - (nums[mini] - 1) + n) % n;
    else 
        mini = 0;
    for (int i = 0; i < n; i++) {
        vals.pb({nums[(mini+i)%n], i});
    }
    sort(ALL(vals));
    int ptr = 0, num = n+1;
    for (auto [a, b] : vals) {
        while (cp[b] != a) {
            res[ptr++] = cp[b];
            cp[b] = num++;
        }
    }
    return ptr;
}
 
const int MOD = 1e9 + 9;
ll Pow(ll a, ll b) {
    ll res = 1;
    while(b > 0) {
        if (b & 1) res = res * a % MOD;
        a = a * a % MOD;
        b /= 2;
    }
    return res;
}
int countReplacement(int n, int nums[]) {
    if (!valid(n, nums)) return 0;
    ll mini = 0, cp[n];
    for (int i = 0; i < n; i++) 
        if (nums[i] < nums[mini]) mini = i;
    
    iota(cp, cp+n, 1);
    vector <PII> vals;
    if (nums[mini] <= n) mini = (mini - (nums[mini] - 1) + n) % n;
    else mini = 0;

    for (int i = 0; i < n; i++) 
        if (cp[i] != nums[(mini+i)%n])
            vals.pb({nums[(mini+i)%n], i});
    
    sort(ALL(vals));
    ll num = n+1, sz = vals.size();
    ll ans = (vals.size() == n ? n : 1);
    for (auto [a, b] : vals) {
        ans = ans * Pow(sz, a - num) % MOD;
        num = a+1;
        sz--;
    }
    return ans;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for (int i = 1; i < tmp.size(); i++)
      |                     ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:81:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |     ll ans = (vals.size() == n ? n : 1);
      |               ~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 7 ms 548 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 7 ms 596 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 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 8 ms 640 KB Output is correct
8 Correct 6 ms 496 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 7 ms 608 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 7 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 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 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 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
# 결과 실행 시간 메모리 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 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 10 ms 1996 KB Output is correct
12 Correct 10 ms 2124 KB Output is correct
13 Correct 12 ms 1340 KB Output is correct
14 Correct 9 ms 2016 KB Output is correct
15 Correct 17 ms 2252 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
# 결과 실행 시간 메모리 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 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
# 결과 실행 시간 메모리 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 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 212 KB Output is correct
9 Correct 16 ms 1900 KB Output is correct
10 Correct 14 ms 1704 KB Output is correct
11 Correct 9 ms 896 KB Output is correct
12 Correct 8 ms 1004 KB Output is correct
13 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 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 212 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 18 ms 1884 KB Output is correct
10 Correct 16 ms 1800 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 7 ms 1004 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 25 ms 3600 KB Output is correct
15 Correct 27 ms 3800 KB Output is correct
16 Correct 6 ms 1012 KB Output is correct
17 Correct 19 ms 2372 KB Output is correct
18 Correct 11 ms 1860 KB Output is correct