답안 #422426

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422426 2021-06-10T06:30:30 Z Andyvanh1 곤돌라 (IOI14_gondola) C++14
100 / 100
28 ms 3016 KB
#include <bits/stdc++.h>
#include "gondola.h"
 
using namespace std;
 
#define vt vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
 
typedef long long ll;
typedef long double ld;
typedef vt<int> vi;
typedef pair<int,int> pii;
 
int x[100005];
 
int valid(int n, int inputSeq[]){
    int at = -1;
    rep(i,n)x[i] = inputSeq[i];
    sort(x,x+n);
    for(int i = 1; i < n; i++){
        if(x[i]==x[i-1])return 0;
    }
    for(int i = 0; i < n; i++){
        if(inputSeq[i]>n){
            inputSeq[i] = -1;
        }else{
            at = i;
        }
    }
    if(at==-1)return 1;
    bool bol = true;
 
    for(int i = at; i < n; i++){
        if(inputSeq[i]!=-1&&inputSeq[i]!=(inputSeq[at]+i-at-1)%n+1){
            return 0;
        }
    }
    for(int i = 0; i < at; i++){
        if(inputSeq[i]!=-1&&inputSeq[i]!=(inputSeq[at]-at+i+n-1)%n+1){
            return 0;
        }
    }
    return 1;
}
 
bool taken[100005];
int cur[100005];
int matr[250010];
 
int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    int Max = 0;
    rep(i,n){
        Max = max(Max,gondolaSeq[i]);
    }
    rep(i,Max+1){
        matr[i] = -1;
    }
    int at = -1;
    for(int i = 0; i < n; i++){
        if(gondolaSeq[i]<=n){
            at = i;
            break;
        }
    }
    if(at==-1){
        rep(i,n){
            cur[i] = i+1;
        }
    }else{
        for(int i = 0; i < n; i++){
            cur[i] = (gondolaSeq[at]-at+i+n-1)%n+1;
            if(gondolaSeq[i] <= n)taken[i] = true;
        }
    }
    for(int i = 0; i < n; i++){
        matr[gondolaSeq[i]] = i;
    }
    for(int j = n+1; j <= Max; j++){
        if(matr[j]!=-1){
            replacementSeq[j-n-1] = cur[matr[j]];
            cur[matr[j]] = j;
            taken[matr[j]] = true;
        }else{
 
           for(int i = 0; i < n; i++){
                if(taken[i]==false){
 
                    replacementSeq[j-n-1] = cur[i];
                    cur[i] = j;
                    break;
                }
            }
        }
    }
    return Max-n;
 
}
 
#define MOD 1000000009
 
ll exp(ll x, int k){
    if(k==0)return 1ll;
    ll ans = exp(x,k/2);
    ans*=ans;
    ans%=MOD;
    if(k&1){
        ans*=x;
        ans%=MOD;
    }
    return ans;
}
 
 
int countReplacement(int n, int inputSeq[]){
    int at = -1;
    for(int i = 0; i < n; i++){
        if(inputSeq[i]<=n){
            at = i;
            break;
        }
    }
    ll cur = n;
    ll ans = 1;
    sort(inputSeq, inputSeq+n);
    for(int i = 0; i < n; i++){
        if(inputSeq[i]<=n){
            cur--;
        }else{
            if(i==0){
                ans*=exp(cur,inputSeq[i]-n-1);
                ans*=n;
                ans%=MOD;
            }else{
                if(inputSeq[i-1]<=n){
                    ans*=exp(cur,inputSeq[i]-n-1);
                    ans%=MOD;
                }else{
                    ans*=exp(cur,inputSeq[i]-inputSeq[i-1]-1);
                    ans%=MOD;
                }
            }
            cur--;
        }
    }
    return ans;
}
 

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:20:5: note: in expansion of macro 'rep'
   20 |     rep(i,n)x[i] = inputSeq[i];
      |     ^~~
gondola.cpp:33:10: warning: unused variable 'bol' [-Wunused-variable]
   33 |     bool bol = true;
      |          ^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:54:5: note: in expansion of macro 'rep'
   54 |     rep(i,n){
      |     ^~~
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:57:5: note: in expansion of macro 'rep'
   57 |     rep(i,Max+1){
      |     ^~~
gondola.cpp:9:26: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i,x) for(int (i) = 0; (i) < (x); (i)++ )
      |                          ^
gondola.cpp:68:9: note: in expansion of macro 'rep'
   68 |         rep(i,n){
      |         ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:117:9: warning: variable 'at' set but not used [-Wunused-but-set-variable]
  117 |     int at = -1;
      |         ^~
# 결과 실행 시간 메모리 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 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 8 ms 716 KB Output is correct
7 Correct 19 ms 1472 KB Output is correct
8 Correct 14 ms 1236 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 18 ms 1352 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 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 812 KB Output is correct
7 Correct 17 ms 1484 KB Output is correct
8 Correct 12 ms 1280 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 18 ms 1332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 9 ms 716 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 18 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 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
# 결과 실행 시간 메모리 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 300 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 300 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 300 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 0 ms 296 KB Output is correct
7 Correct 1 ms 332 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 1668 KB Output is correct
12 Correct 12 ms 1864 KB Output is correct
13 Correct 16 ms 1856 KB Output is correct
14 Correct 10 ms 1740 KB Output is correct
15 Correct 28 ms 3016 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
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 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 16 ms 972 KB Output is correct
10 Correct 13 ms 828 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 9 ms 564 KB Output is correct
13 Correct 2 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 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 20 ms 1072 KB Output is correct
10 Correct 17 ms 844 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 8 ms 460 KB Output is correct
13 Correct 3 ms 308 KB Output is correct
14 Correct 20 ms 1424 KB Output is correct
15 Correct 23 ms 1592 KB Output is correct
16 Correct 4 ms 460 KB Output is correct
17 Correct 15 ms 1168 KB Output is correct
18 Correct 9 ms 796 KB Output is correct