답안 #31698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31698 2017-08-31T12:14:19 Z top34051 곤돌라 (IOI14_gondola) C++14
75 / 100
46 ms 7396 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define mod 1000000009LL

int n,m,mx;
int a[maxn], vis[250005];
map<int,int> s;

int valid(int N, int p[]) {
    int i, x = 0, val;
    n = N;
    //Build
    for(i=0;i<n;i++) if(p[i]<=n) x = i;
    val = p[x];
    for(i=0;i<n;i++) a[x] = val, x = (x+1)%n, val = val%n+1;
    //Check
    for(i=0;i<n;i++) if(p[i]<=n && a[i]!=p[i]) return 0;
    //Rep
    memset(vis,0,sizeof(vis));
    for(i=0;i<n;i++) {
        if(vis[p[i]]) return 0;
        vis[p[i]] = 1;
    }
    return 1;
}

int replacement(int N, int p[], int res[]) {
    int i, x=-1, val;
    n = N;
    //Build
    for(i=0;i<n;i++) if(p[i]<=n) x = i;
    if(x==-1) val = 1, x = 0;
    else val = p[x];
    for(i=0;i<n;i++) a[x] = val, x = (x+1)%n, val = val%n+1;
    //Check
    for(i=0;i<n;i++) {
        mx = max(mx,p[i]);
        if(p[i]>n) s[p[i]] = i;
    }
    m = 0;
    for(i=n+1;i<=mx;i++) {
        if(s.find(i)!=s.end()) res[m++] = a[s[i]], a[s[i]] = i, s.erase(s.find(i));
        else if(s.size()>0) res[m++] = a[s.begin()->second], a[s.begin()->second] = i;
        else return 0;
    }
    return m;
}

int countReplacement(int N, int p[]) {
    int i, x=-1, val, cy;
    long long ans;
    n = N;
    //Build
    cy = 0;
    for(i=0;i<n;i++) if(p[i]<=n) x = i;
    if(x==-1) val = 1, x = 0, cy = 1;
    else val = p[x];
    for(i=0;i<n;i++) a[x] = val, x = (x+1)%n, val = val%n+1;
    //Check
    for(i=0;i<n;i++) if(p[i]<=n && a[i]!=p[i]) return 0;
    //Rep
    memset(vis,0,sizeof(vis));
    for(i=0;i<n;i++) {
        if(vis[p[i]]) return 0;
        vis[p[i]] = 1;
    }
    //Check
    for(i=0;i<n;i++) {
        mx = max(mx,p[i]);
        if(p[i]>n) s[p[i]] = i;
    }
    m = 0; ans = 1;
    for(i=n+1;i<=mx;i++) {
        if(s.find(i)!=s.end()) s.erase(s.find(i));
        else if(s.size()>0) ans = ((ans*s.size())%mod + mod)%mod;//, printf("%d: s.size() = %d\n",i,s.size());
        else return 0;
    }
    if(cy) {
        for(i=1;i<=n;i++) ans = ((ans*i)%mod + mod)%mod;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 6 ms 4756 KB Output is correct
7 Correct 16 ms 4756 KB Output is correct
8 Correct 9 ms 4756 KB Output is correct
9 Correct 3 ms 4756 KB Output is correct
10 Correct 16 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 6 ms 4756 KB Output is correct
7 Correct 13 ms 4756 KB Output is correct
8 Correct 13 ms 4756 KB Output is correct
9 Correct 3 ms 4756 KB Output is correct
10 Correct 9 ms 4756 KB Output is correct
11 Correct 0 ms 4756 KB Output is correct
12 Correct 0 ms 4756 KB Output is correct
13 Correct 6 ms 4756 KB Output is correct
14 Correct 0 ms 4756 KB Output is correct
15 Correct 19 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 0 ms 4756 KB Output is correct
7 Correct 0 ms 4756 KB Output is correct
8 Correct 0 ms 4756 KB Output is correct
9 Correct 0 ms 4756 KB Output is correct
10 Correct 0 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 0 ms 4756 KB Output is correct
7 Correct 0 ms 4756 KB Output is correct
8 Correct 0 ms 4756 KB Output is correct
9 Correct 0 ms 4756 KB Output is correct
10 Correct 0 ms 4756 KB Output is correct
11 Correct 0 ms 4756 KB Output is correct
12 Correct 26 ms 4756 KB Output is correct
13 Correct 29 ms 6208 KB Output is correct
14 Correct 9 ms 4756 KB Output is correct
15 Correct 26 ms 5548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 0 ms 4756 KB Output is correct
7 Correct 0 ms 4756 KB Output is correct
8 Correct 0 ms 4756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 0 ms 4756 KB Output is correct
7 Correct 0 ms 4756 KB Output is correct
8 Correct 0 ms 4756 KB Output is correct
9 Correct 46 ms 7396 KB Output is correct
10 Correct 36 ms 6736 KB Output is correct
11 Correct 16 ms 5812 KB Output is correct
12 Correct 13 ms 6076 KB Output is correct
13 Incorrect 6 ms 5020 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4756 KB Output is correct
2 Correct 0 ms 4756 KB Output is correct
3 Correct 0 ms 4756 KB Output is correct
4 Correct 0 ms 4756 KB Output is correct
5 Correct 0 ms 4756 KB Output is correct
6 Correct 0 ms 4756 KB Output is correct
7 Correct 0 ms 4756 KB Output is correct
8 Correct 0 ms 4756 KB Output is correct
9 Correct 39 ms 7396 KB Output is correct
10 Correct 29 ms 6736 KB Output is correct
11 Correct 16 ms 5812 KB Output is correct
12 Correct 13 ms 6076 KB Output is correct
13 Incorrect 6 ms 5020 KB Output isn't correct
14 Halted 0 ms 0 KB -