답안 #787794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787794 2023-07-19T12:44:08 Z tolbi 곤돌라 (IOI14_gondola) C++17
100 / 100
51 ms 6012 KB
    #pragma optimize("Bismillahirrahmanirrahim")
    //█▀█─█──█──█▀█─█─█
    //█▄█─█──█──█▄█─█■█
    //█─█─█▄─█▄─█─█─█─█
    //Allahuekber
    //ahmet23 orz...
    //FatihSultanMehmedHan
    //YavuzSultanSelimHan
    //AbdulhamidHan
    //Sani buyuk Osman Pasa Plevneden cikmam diyor
    #define author tolbi
    #include <bits/stdc++.h>
    using namespace std;
    template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr) {return os<<pr.first<<" "<<pr.second;}
    template<typename X> ostream& operator<<(ostream& os, vector<X> v){for (auto &it : v) os<<it<<" ";return os;}
    template<typename X, size_t Y> ostream& operator<<(ostream& os, array<X,Y> v){for (auto &it : v) os<<it<<" ";return os;}
    ostream& operator<<(ostream& os, bool bl){return os<<(int32_t)bl;}
    #define endl '\n'
    #define deci(x) int x;cin>>x;
    #define decstr(x) string x;cin>>x;
    #define cinarr(x) for(auto &it : x) cin>>it;
    #define coutarr(x) for(auto &it : x) cout<<it<<" ";cout<<endl;
    #define sortarr(x) sort(x.begin(), x.end())
    #define sortrarr(x) sort(x.rbegin(), x.rend())
    #define rev(x) reverse(x.begin(), x.end())
    #define tol(bi) (1ll<<((int)(bi)))
    typedef long long ll;
    const ll INF = LONG_LONG_MAX;
    const ll MOD = 1e9+9;
    mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
     
    #include "gondola.h"
     
    int valid(int n, int inputSeq[])
    {
        map<int,bool> mp;
        int pos = -1;
        for (int i = 0; i < n; ++i)
        {
            if (mp[inputSeq[i]]) return 0;
            mp[inputSeq[i]]=true;
        }
        for (int i = 0; i < n; ++i)
        {
            if (inputSeq[i]<=n){
                pos=i;
                break;
            }
        }
        if (pos==-1) return 1;
        pos-=inputSeq[pos]-1;
        if (pos<0) pos+=n;
        for (int i = 0; i < n; i++){
            int pp = (pos+i)%n;
            if (inputSeq[pp]>n) continue;
            if (inputSeq[pp]!=i+1) return 0;
        }
        return 1;
    }
     
    //----------------------
     
    int replacement(int n, int gondolaSeq[], int replacementSeq[])
    {
        vector<int> arr(n);
        int start = 0;
        vector<pair<int,int>> gerek;
        for (int i = 0; i < n; ++i)
        {
            if (gondolaSeq[i]<=n) continue;
            gerek.push_back({gondolaSeq[i],i});
        }
        for (int i = 0; i < n; i++){
            if (gondolaSeq[i]<=n){
                start=i-gondolaSeq[i]+1;
                break;
            }
        }
        if (start<n) start+=n;
        for (int i = 0; i < n; i++){
            int ppos = (start+i)%n;
            arr[ppos]=i+1;
        }
        int crr = n+1;
        int res = 0;
        sortarr(gerek);
        for (int i = 0; i < gerek.size(); ++i)
        {
            int hedef = gerek[i].first;
            int node = gerek[i].second;
            while (arr[node]<hedef){
                replacementSeq[res]=arr[node];
                arr[node]=crr;
                crr++,res++;
            }
        }
        return res;
    }
     
    //----------------------
    ll fpow(ll base, ll pow){
        ll res = 1;
        base%=MOD;
        while (pow>0){
            if (pow&1){
                res*=base;
                res%=MOD;
            }
            base*=base;
            base%=MOD;
            pow>>=1;
        }
        return res;
    }
    int countReplacement(int n, int inputSeq[])
    {
        if (!valid(n,inputSeq)) return 0;
        vector<ll> kk;
        bool boolean=true;
        for (int i = 0; i < n; i++){
            if (inputSeq[i]>n) kk.push_back(inputSeq[i]);
            else boolean=false;
        }
        sortarr(kk);
        ll ans = 1;
        if (boolean) ans=n;
        ll lel = n+1;
        for (int i = 0; i < kk.size(); i++){
            ans*=fpow((ll)kk.size()-i,kk[i]-lel);
            ans%=MOD;
            lel=kk[i]+1;
        }
        return ans;
    }

Compilation message

gondola.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 |     #pragma optimize("Bismillahirrahmanirrahim")
      | 
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:87:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for (int i = 0; i < gerek.size(); ++i)
      |                         ~~^~~~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:128:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         for (int i = 0; i < kk.size(); i++){
      |                         ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 10 ms 2132 KB Output is correct
7 Correct 7 ms 620 KB Output is correct
8 Correct 21 ms 3912 KB Output is correct
9 Correct 6 ms 1596 KB Output is correct
10 Correct 25 ms 4428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 11 ms 2132 KB Output is correct
7 Correct 9 ms 596 KB Output is correct
8 Correct 21 ms 3924 KB Output is correct
9 Correct 6 ms 1440 KB Output is correct
10 Correct 24 ms 4472 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 14 ms 2248 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 36 ms 5060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 7 ms 844 KB Output is correct
12 Correct 8 ms 904 KB Output is correct
13 Correct 11 ms 1244 KB Output is correct
14 Correct 8 ms 868 KB Output is correct
15 Correct 15 ms 2272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 224 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 40 ms 4420 KB Output is correct
10 Correct 27 ms 3808 KB Output is correct
11 Correct 10 ms 1480 KB Output is correct
12 Correct 12 ms 1836 KB Output is correct
13 Correct 3 ms 580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 35 ms 4468 KB Output is correct
10 Correct 27 ms 3796 KB Output is correct
11 Correct 10 ms 1492 KB Output is correct
12 Correct 12 ms 1876 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 51 ms 5284 KB Output is correct
15 Correct 49 ms 6012 KB Output is correct
16 Correct 8 ms 1292 KB Output is correct
17 Correct 31 ms 4104 KB Output is correct
18 Correct 20 ms 2724 KB Output is correct