답안 #29380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29380 2017-07-19T08:07:05 Z cki86201 곤돌라 (IOI14_gondola) C++11
60 / 100
23 ms 5344 KB
#include "gondola.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> Pll;
typedef long double ldouble;

int vchk[250050] = {};
int valid(int n, int inputSeq[])
{
    int L = *max_element(inputSeq, inputSeq + n);
    rep(i, L+1) vchk[i] = -1;
    rep(i, n) {
        if(vchk[inputSeq[i]] != -1) return 0;
        vchk[ inputSeq[i] ] = i;
    }
    pii f = pii(-1, -1);
    for(int i=0;i<n;i++) if(inputSeq[i] <= n) f = pii(inputSeq[i], i);
    if(f == pii(-1, -1)) return 1;
    for(int i=0;i<n;i++) if(inputSeq[i] <= n) {
        int exp = (i - f.Se) + f.Fi;
        if(exp > n) exp -= n;
        if(exp <= 0) exp += n;
        if(exp != inputSeq[i]) return 0;
    }
    return 1;
}

//----------------------

int ep[250050];

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
    int L = *max_element(gondolaSeq, gondolaSeq + n);
    rep(i, L+1) vchk[i] = -1;
    rep(i, n) vchk[ gondolaSeq[i] ] = i;
    int ret = L - n;
    
    pii f = pii(-1, -1);
    for(int i=0;i<n;i++) if(gondolaSeq[i] <= n) f = pii(gondolaSeq[i], i);
    if(f == pii(-1, -1)) f = pii(1, 0);
    for(int i=0;i<n;i++) {
        int exp = (i - f.Se) + f.Fi;
        if(exp > n) exp -= n;
        if(exp <= 0) exp += n;
        ep[i] = exp;
    }
    
    int now = ret;
    for(int i=L, j=L;i>n;i--) {
        while(vchk[j] != -1) --j;
        if(j > n || ep[vchk[i]] == j) vchk[j] = vchk[i], replacementSeq[--now] = j;
        else {
            int t = ep[vchk[i]];
            vchk[t] = vchk[i], replacementSeq[--now] = t;
        }
        
    }
    
    return ret;
}

//----------------------

int pw(int x, int y, int MOD) {
    int res = 1;
    while(y) {
        if(y & 1) res = (ll)res * x % MOD;
        x = (ll)x * x % MOD;
        y >>= 1;
    }
    return res;
}

int countReplacement(int n, int inputSeq[])
{
    const int MOD = 1e9 + 9;
    int L = *max_element(inputSeq, inputSeq + n);
    
    vector <int> T; rep(i, n) T.pb(inputSeq[i]); sort(all(T));
    for(int i=1;i<sz(T);i++) if(T[i] == T[i-1]) return 0;
    
    pii f = pii(-1, -1);
    for(int i=0;i<n;i++) if(inputSeq[i] <= n) f = pii(inputSeq[i], i);
    int flag = 1;
    int cc = 0;
    if(f != pii(-1, -1)) {
        flag = 0;
        for(int i=0;i<n;i++) {
            int exp = (i - f.Se) + f.Fi;
            if(exp > n) exp -= n;
            if(exp <= 0) exp += n;
            if(inputSeq[i] <= n && inputSeq[i] != exp) return 0;
            if(inputSeq[i] > n) ++cc;
        }
    }
    ll ans = 1;
    if(flag) for(int i=2;i<=n;i++) ans = ans * i % MOD;
    ans = ans * pw(cc, L - n - cc, MOD) % MOD;
    return (int)ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Correct 0 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Correct 0 ms 5344 KB Output is correct
6 Correct 3 ms 5344 KB Output is correct
7 Correct 6 ms 5344 KB Output is correct
8 Correct 9 ms 5344 KB Output is correct
9 Correct 3 ms 5344 KB Output is correct
10 Correct 9 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Correct 0 ms 5344 KB Output is correct
6 Correct 3 ms 5344 KB Output is correct
7 Correct 13 ms 5344 KB Output is correct
8 Correct 6 ms 5344 KB Output is correct
9 Correct 0 ms 5344 KB Output is correct
10 Correct 6 ms 5344 KB Output is correct
11 Correct 0 ms 5344 KB Output is correct
12 Correct 0 ms 5344 KB Output is correct
13 Correct 3 ms 5344 KB Output is correct
14 Correct 0 ms 5344 KB Output is correct
15 Correct 9 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Correct 0 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Correct 0 ms 5344 KB Output is correct
6 Correct 0 ms 5344 KB Output is correct
7 Correct 0 ms 5344 KB Output is correct
8 Correct 0 ms 5344 KB Output is correct
9 Correct 0 ms 5344 KB Output is correct
10 Correct 0 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Correct 0 ms 5344 KB Output is correct
6 Correct 0 ms 5344 KB Output is correct
7 Correct 0 ms 5344 KB Output is correct
8 Correct 0 ms 5344 KB Output is correct
9 Correct 0 ms 5344 KB Output is correct
10 Correct 0 ms 5344 KB Output is correct
11 Correct 9 ms 5344 KB Output is correct
12 Correct 13 ms 5344 KB Output is correct
13 Correct 9 ms 5344 KB Output is correct
14 Correct 9 ms 5344 KB Output is correct
15 Correct 23 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Incorrect 0 ms 5344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Incorrect 0 ms 5344 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5344 KB Output is correct
2 Correct 0 ms 5344 KB Output is correct
3 Correct 0 ms 5344 KB Output is correct
4 Correct 0 ms 5344 KB Output is correct
5 Incorrect 0 ms 5344 KB Output isn't correct
6 Halted 0 ms 0 KB -