제출 #195589

#제출 시각아이디문제언어결과실행 시간메모리
195589oscarsierra12곤돌라 (IOI14_gondola)C++14
25 / 100
55 ms5616 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std ; typedef pair<int,int> pii ; int arr[300000] ; const int MOD = 1e9+7 ; int valid(int n, int inputSeq[]) { int x = min_element ( inputSeq, inputSeq+n ) - inputSeq ; vector <int> nwSeq ; set <int> rep ; for ( int i = x ; i < n ; ++i ) nwSeq.push_back ( inputSeq[i] ), rep.insert ( inputSeq[i] ) ; for ( int i = 0 ; i < x ; ++i ) nwSeq.push_back ( inputSeq[i] ), rep.insert ( inputSeq[i] ) ; int expected = inputSeq[x] ; int posible = ( (int)rep.size()==n ) ; for ( int i = 0 ; i < n ; ++i ) { if ( nwSeq[i] <= n ) { if ( nwSeq[i] != expected ) posible = 0 ; expected = nwSeq[i]+1 ; } else expected++ ; } return posible; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int x = min_element ( gondolaSeq, gondolaSeq+n ) - gondolaSeq ; int beg = 1 ; if ( gondolaSeq[x] <= n ) beg = gondolaSeq[x] ; if ( *max_element(gondolaSeq, gondolaSeq+n) > n ) return 1 ; vector <int> nwSeq ; for ( int i = x ; i < n ; ++i ) nwSeq.push_back ( gondolaSeq[i] ) ; for ( int i = 0 ; i < x ; ++i ) nwSeq.push_back ( gondolaSeq[i] ) ; // cout << beg << '\n' ; vector <pii> posib ; for ( int i = 0 ; i < n ; ++i ) { if ( nwSeq[i] != beg ) posib.push_back ( {nwSeq[i], beg} ) ; beg++ ; if ( beg > n ) beg = 1; } sort ( posib.begin(), posib.end() ) ; int ans = 0, id = 0; for ( auto i:posib ) { // cout << i.first << ' ' << i.second << '\n' ; replacementSeq[id] = i.second ; n++ ; ++ans ; while ( n < i.first ) { ++id ; replacementSeq[id] = n ; ++n ; ++ans ; } ++id ; } return ans; } long long fpow( long long q, long long cur ) { if ( cur == 1 ) return q ; if ( cur == 0 ) return 1 ; long long izq = fpow(q, cur/2) ; long long ot = max(1ll,(cur%2)*q) ; return (((izq*izq)%MOD)*ot)%MOD ; } //---------------------- int countReplacement(int n, int inputSeq[]) { if ( valid(n, inputSeq) == 0 ) return 0 ; if ( replacement (n,inputSeq,arr) == 0 ) return 1 ; sort ( inputSeq, inputSeq + n ) ; long long ans = 1 ; if ( inputSeq[0] > n ) ans = n ; int nRep = n ; for ( int i = 0 ; i < nRep ; ++i ) { long long cur = inputSeq[i] - n ; if ( cur <= 0 ) continue ; cur-- ; long long q = nRep-i ; n = inputSeq[i] ; ans *= (fpow(q,cur)%MOD) ; ans %= MOD; } return ans ; } /* 10 10 1 2 5644898 4 8489426 6 898894 8 948945 8946521*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...