답안 #835725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835725 2023-08-23T18:28:01 Z 7mody 곤돌라 (IOI14_gondola) C++17
컴파일 오류
0 ms 0 KB
#include "gondola.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 250005;
const int mod=1e9+9;

ll power(ll a,ll n){
    ll res=1;
    while(n){
        if(n&1) res=(1LL*res*a)%mod;
        a=(a*a)%mod;
        n>>=1;
    }
    return res;
}
 
map<int,int> mp;
 
int valid(int n, vector<int> p){
    int start=-1;
    for(int i=0;i<n;i++){
        if(mp[p[i]]) return 0;
        mp[p[i]]=1;
        if(p[i]<=n){
            int cur=(i-p[i]+n)%n;
            if(start==-1) start=cur; 
            else if(start!=cur) return 0;
        }
    }
    return 1;
}
 
// --------------------------------------------------------------

int replacement(int n, vector<int> p, vector<int> res){
    int start=0;
    deque<int> arr(n);
    for(int i=0; i < n;i++){
        if(p[i]<=n) start=(i-p[i]+n)%n;
        arr[i]=p[i];
    }
    while(start){
        start--;
        int temp=arr.front();
        arr.pop_front();
        arr.push_back(temp);
    }
    vector<pair<int,int>> curr;
    for(int i=0; i < n;i++){
        if(arr[i]>n) curr.push_back({arr[i],i});
    }
    int size=0;
    sort(curr.begin(),curr.end());
    res.resize(curr.size());
    int del=n;
    for(auto [val,i] : curr){
        res[size++]=i+1;del++;
        while(del<val) res[size++]=del++;
    }
    return size;
}

// --------------------------------------------------------------
 
int countReplacement(int n, vector<int> p){
    if(!valid(n,p)) return 0;
    vector<int> arr;
    int res=1,a=n;
    for(int i=0;i<n;i++){
        if(p[i]<=n) a--;
        else arr.push_back(p[i]);
    }
    if(a==n) res=n;
    int pre=n;
    sort(arr.begin(),arr.end());
    for(int x:arr){
        res=ll(res)*power(a,x-pre-1)%mod;
        pre=x;a--;
    }
    return res;
}

// void solve(){

// }

// int main(){
//     ios::sync_with_stdio(false);cout.tie();cin.tie();
//     int t=1;
//     cin >> t;
//     while(t--) solve();
// }

Compilation message

/usr/bin/ld: /tmp/cckJDK90.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status