답안 #243911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
243911 2020-07-02T06:34:03 Z aloo123 곤돌라 (IOI14_gondola) C++14
100 / 100
64 ms 6008 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
 #include <gondola.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
// #define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
 
 
const ll INF = 1e18;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+9;
    ll power(ll a, ll b)    //a is base, b is exponent
    {
        if(b==0)
            return 1;
        if(b==1)
            return a;
        if(b%2 == 1)
            return (power(a,b-1)*a)%MOD;
        ll q = power(a,b/2);
        return (q*q)%MOD;
    }

int valid(int n, int a[]){
    
    
    ll idx = 0;
    bool original = 0;
    for(int i =0;i<n;i++){
        if(a[i] <= n){
            idx =i;
            original = true;
            break;
        }   
   }
    if(original == false){
        set<ll> se;
        for(int i = 0;i<n;i++) se.in(a[i]);
        if(sz(se) == n){
            return 1;
        }
        else return 0;
    }
    int b[n];
    vector<int> ans;
    vector<pair<int,int>> gg;
    ll count = 1;
    ll nxt = a[idx];
    if(original == false) nxt = 1; 
    // cout << idx << endl;
    while(count <= n){
        
            b[idx] = nxt;
            nxt++;
            idx++;
            if(nxt > n) nxt = 1;
            if(idx >= n) idx = 0;
            count++;
        
    }
    set<ll> se;
    for(int i =0;i<n;i++){
        if(a[i] <= n && b[i] != a[i]){
            return 0;
        }
        else
            se.in(a[i]);
    }
    if(sz(se) != n) return 0;
    return 1;
}
int replacement(int n, int a[], int replacementSeq[]) {
    ll idx = 0;
    bool original = 0;
    for(int i =0;i<n;i++){
        if(a[i] <= n){
            idx =i;
            original = true;
            break;
        }
    }
 
    int b[n];
    vector<int> ans;
    vector<pair<int,int>> gg;
    ll count = 1;
    ll nxt = a[idx];
    if(original == false) nxt = 1; 
    // cout << idx << endl;
    while(count <= n){
        
            b[idx] = nxt;
            nxt++;
            idx++;
            if(nxt > n) nxt = 1;
            if(idx >= n) idx = 0;
            count++;
        
    }
    ll sp = n+1;
    // for(int i =0;i<n;i++) cout << b[i] << " ";cout<<endl;
    for(int i =0;i<n;i++){
        if(a[i] > n)
            gg.pb({a[i],b[i]});
    }
    sort(gg.begin(),gg.end());
    for(int i = 0;i<sz(gg);i++){
        ans.pb(gg[i].s);
        ll x = sp;
        while(x != gg[i].f){
            ans.pb(x);
            x++;
        }
        sp = gg[i].f+1;
        
    }
    // for(int i = 0;i<sz(ans);i++) cout<<ans[i]<<" ";cout<<endl;
    for(int i = 0;i<sz(ans);i++) replacementSeq[i] = ans[i];
    return sz(ans);

}
int countReplacement(int n, int inputSeq[]) {
    //cout << "QQA\n";
    if(!valid(n,inputSeq)) return 0;
    //cout<<"QQA\n";
    ll special = 0;
    vll v;
    for(int i =0;i<n;i++){
        if(inputSeq[i] > n){
            special += 1;
            v.pb(inputSeq[i]);
        }
    }
    if(special == 0) return 1;
    ll ans = n;
    if(special != n) ans = 1;
    sort(v.begin(),v.end());
    ll maxi = n+1;
    ll r = sz(v);
    for(int i = 0;i<sz(v);i++){
      ans = (ans * power(r,v[i]-maxi))%MOD;
        // maxi = v[i];
        r--;
        maxi = v[i]+1;
    }
    return ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 16 ms 2560 KB Output is correct
7 Correct 17 ms 1412 KB Output is correct
8 Correct 27 ms 4472 KB Output is correct
9 Correct 13 ms 1664 KB Output is correct
10 Correct 34 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 17 ms 2560 KB Output is correct
7 Correct 16 ms 1400 KB Output is correct
8 Correct 27 ms 4480 KB Output is correct
9 Correct 11 ms 1664 KB Output is correct
10 Correct 31 ms 5240 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 10 ms 768 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 17 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 15 ms 1280 KB Output is correct
12 Correct 16 ms 1408 KB Output is correct
13 Correct 20 ms 1784 KB Output is correct
14 Correct 15 ms 1280 KB Output is correct
15 Correct 26 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 288 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 45 ms 4736 KB Output is correct
10 Correct 36 ms 4088 KB Output is correct
11 Correct 16 ms 1664 KB Output is correct
12 Correct 19 ms 1920 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 45 ms 4728 KB Output is correct
10 Correct 36 ms 4096 KB Output is correct
11 Correct 16 ms 1664 KB Output is correct
12 Correct 19 ms 1920 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 57 ms 5368 KB Output is correct
15 Correct 64 ms 6008 KB Output is correct
16 Correct 14 ms 1408 KB Output is correct
17 Correct 46 ms 4344 KB Output is correct
18 Correct 24 ms 2560 KB Output is correct