답안 #397845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397845 2021-05-03T09:31:05 Z teehandsome 곤돌라 (IOI14_gondola) C++11
100 / 100
42 ms 4328 KB
#include "gondola.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define INF 1e9+7
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using pii=pair<int,int>;
using ppi=pair<int,pii>;
using oset=tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>;

template<typename T>
void _print(vector<T> x) {cerr<<"{"; for(auto e:x) cerr<<e<<","; cerr<<"}";}
void _print(pii x) {cerr<<"{"<<x.first<<","<<x.second<<"}";}
template<typename T>
void _print(T x) {cerr<<x;}

void dbg() {cerr<<endl;}
template<typename Head,typename... Tail>
void dbg(Head H,Tail... T) {
    _print(H);
    if(sizeof...(T)) cerr<<",";
    else cerr<<"\"]";
    dbg(T...);
}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:[\"",dbg(__VA_ARGS__)

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int valid(int n, int a[])
{
    vector<int> ar;
    vector<int> pos(n+1,-1);
    for(int i=0;i<n;i++) {
        if(a[i]<=n) pos[a[i]]=i;
        ar.push_back(a[i]);
    }
    sort(all(ar));
    ar.erase(unique(all(ar)),end(ar));
    if(ar.size()!=n) return 0;
    int start=-1;
    for(int i=1;i<=n;i++) {
        if(pos[i]!=-1) {
            start=i; break;
        }
    }
    if(start==-1) return 1;
    for(int i=start+1;i<=n;i++) {
        if(pos[i]==-1) continue;
        if((pos[i]+n-pos[start])%n!=i-start) return 0;
    }
    return 1;
}

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

int replacement(int n, int a[], int res[])
{

    vector<pii> ar;
    vector<int> org(n);
    vector<int> pos(n+1,-1);
    int startidx=-1,startval=1;
    for(int i=0;i<n;i++) {
        if(a[i]<=n) {
            pos[a[i]]=i;
        }
        else {
            ar.push_back({a[i],i});
        }
    }
    for(int i=1;i<=n;i++) {
        if(pos[i]!=-1) {
            startidx=pos[i],startval=i; break;
        }
    }
    if(startidx==-1) startidx=0;
    for(int i=startidx;i<startidx+n;i++) {

        org[i%n]=startval;
        startval++;
        if(startval>n) startval=1;
    }
//    debug(org);
//    return 0;
    sort(all(ar));
    int cur=n;
    int len=ar.size();
    int sz=0;
    for(int i=0;i<len;i++) {
        while(cur<ar[i].first) {
            res[sz++]=org[ar[i].second];
            org[ar[i].second]=++cur;
        }
    }
    return sz;
}

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

const int md=1e9+9;
const int mxn=250100;

ll f[mxn];

ll mypow(ll a,ll b) {
    ll res=1;
    while(b) {
        if(b&1) res=(res*a)%md;
        a=(a*a)%md; b=b>>1;
    }
    return res;
}

int countReplacement(int n, int a[])
{
    int temp=valid(n,a);
    if(temp==0) return 0;
    f[0]=f[1]=1;
    for(int i=2;i<mxn;i++) {
        f[i]=(i*f[i-1])%md;
    }
    vector<int> ar;
    bool ok=true;
    for(int i=0;i<n;i++) {
        if(a[i]<=n) {
            ok=false; continue;
        }
        ar.push_back(a[i]);
    }

    ar.push_back(n);
    sort(all(ar));
    int len=ar.size();
    ll ans=1;
    for(int i=1;i<len;i++) {
        if(ar[i]==ar[i-1]+1) continue;
        ll temp=mypow((len-i),ar[i]-ar[i-1]-1);
        ans=(ans*temp)%md;
    }
    if(ok) ans=(ans*n)%md;
//    debug(mypow(2,5),mypow(3,4));
    return int(ans);
}

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:43:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |     if(ar.size()!=n) return 0;
      |        ~~~~~~~~~^~~
# 결과 실행 시간 메모리 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 11 ms 972 KB Output is correct
7 Correct 23 ms 1524 KB Output is correct
8 Correct 14 ms 1480 KB Output is correct
9 Correct 5 ms 624 KB Output is correct
10 Correct 18 ms 1608 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 880 KB Output is correct
7 Correct 18 ms 1608 KB Output is correct
8 Correct 13 ms 1412 KB Output is correct
9 Correct 5 ms 624 KB Output is correct
10 Correct 23 ms 1608 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 8 ms 976 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 19 ms 1608 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
# 결과 실행 시간 메모리 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 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
# 결과 실행 시간 메모리 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 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 2 ms 336 KB Output is correct
11 Correct 13 ms 1228 KB Output is correct
12 Correct 12 ms 1356 KB Output is correct
13 Correct 21 ms 1324 KB Output is correct
14 Correct 14 ms 1228 KB Output is correct
15 Correct 25 ms 2272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2252 KB Output is correct
2 Correct 3 ms 2268 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2252 KB Output is correct
2 Correct 3 ms 2256 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 3 ms 2252 KB Output is correct
5 Correct 3 ms 2252 KB Output is correct
6 Correct 3 ms 2252 KB Output is correct
7 Correct 4 ms 2252 KB Output is correct
8 Correct 3 ms 2252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2252 KB Output is correct
2 Correct 3 ms 2252 KB Output is correct
3 Correct 3 ms 2232 KB Output is correct
4 Correct 3 ms 2252 KB Output is correct
5 Correct 3 ms 2252 KB Output is correct
6 Correct 3 ms 2224 KB Output is correct
7 Correct 3 ms 2228 KB Output is correct
8 Correct 3 ms 2252 KB Output is correct
9 Correct 24 ms 3460 KB Output is correct
10 Correct 19 ms 3308 KB Output is correct
11 Correct 9 ms 2676 KB Output is correct
12 Correct 11 ms 2812 KB Output is correct
13 Correct 6 ms 2380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2252 KB Output is correct
2 Correct 3 ms 2252 KB Output is correct
3 Correct 3 ms 2252 KB Output is correct
4 Correct 3 ms 2252 KB Output is correct
5 Correct 3 ms 2252 KB Output is correct
6 Correct 3 ms 2252 KB Output is correct
7 Correct 3 ms 2252 KB Output is correct
8 Correct 4 ms 2252 KB Output is correct
9 Correct 24 ms 3520 KB Output is correct
10 Correct 19 ms 3304 KB Output is correct
11 Correct 10 ms 2676 KB Output is correct
12 Correct 15 ms 2784 KB Output is correct
13 Correct 6 ms 2380 KB Output is correct
14 Correct 40 ms 4140 KB Output is correct
15 Correct 42 ms 4328 KB Output is correct
16 Correct 8 ms 2636 KB Output is correct
17 Correct 23 ms 3620 KB Output is correct
18 Correct 14 ms 3108 KB Output is correct