# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
707142 | 2023-03-08T13:53:16 Z | Alihan_8 | 곤돌라 (IOI14_gondola) | C++17 | 55 ms | 5712 KB |
#include <bits/stdc++.h> #include "gondola.h" // include <ext/pb_ds/assoc_container.hpp> // include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define all(x) x.begin(), x.end() #define pb push_back // define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #define mpr make_pair #define ln '\n' void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} //#define int long long int valid(int n, int inputSeq[]){ map <int,int> mp; for ( int i = 0; i < n; i++ ){ if ( mp.count(inputSeq[i]) ) return false; mp[inputSeq[i]] = true; } vector <pair<int,int>> res; for ( int i = 0; i < n; i++ ){ if ( inputSeq[i] <= n ) res.pb({inputSeq[i], i}); } sort(all(res)); for ( int i = 1; i < (int)res.size(); i++ ){ auto [x, y] = res[i-1]; auto [l, r] = res[i]; r = (r+n-y)%n; if ( l-x != r ) return false; } return true; } int replacement(int n, int gondolaSeq[], int ans[]){ vector <int> p; for ( int i = 0; i < n; i++ ){ p.pb(gondolaSeq[i]); } int it = -1; for ( int i = 0; i < n; i++ ){ if ( p[i] <= n ) it = i; } auto F = [&](int x){ return x%n == 0 ? n : x%n; }; vector <int> res(n); if ( it == -1 ) iota(all(res), 1); else{ for ( int j = it; j < n; j++ ) res[j] = F(p[it]+j-it); for ( int j = 0; j < it; j++ ) res[j] = F(p[it]+n-it+j); } vector <pair<int,int>> cur; for ( int i = 0; i < n; i++ ){ cur.pb({p[i], i}); } sort(all(cur)); int _i = 0, last = n+1; for ( auto [val, it]: cur ){ while ( res[it] < val ){ ans[_i++] = res[it]; res[it] = last++; } } return _i; } typedef long long ll; int countReplacement(int n, int inputSeq[]){ if ( !valid(n, inputSeq) ) return 0; const ll Mod = 1e9+9; vector <int> p; for ( int i = 0; i < n; i++ ){ if ( inputSeq[i] > n ) p.pb(inputSeq[i]); } ll cnt = 1; if ( (int)p.size() == n ) cnt = n; auto bin_pow = [&](ll x, int y){ ll res = 1; while ( y ){ if ( y & 1 ) res = res*x%Mod; x = x*x%Mod; y >>= 1; } return res; }; sort(all(p)); int last = n+1, sz = (int)p.size(); for ( int i = 0; i < sz; i++ ){ cnt = cnt*bin_pow(sz-i, p[i]-last)%Mod; last = p[i]+1; } return cnt; } #if false signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int sub_task, n; cin >> n; int p[n] = {0}; for ( int i = 0; i < n; i++ ) cin >> p[i]; cout << countReplacement(n, p); cout << '\n'; /* 4 1 2 7 6 answer: 2 7 2 3 4 12 6 7 1 answer: 1 2 3 4 answer: 2 */ } #endif
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 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 | 14 ms | 2768 KB | Output is correct |
7 | Correct | 8 ms | 596 KB | Output is correct |
8 | Correct | 27 ms | 5020 KB | Output is correct |
9 | Correct | 9 ms | 1860 KB | Output is correct |
10 | Correct | 34 ms | 5712 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 | 1 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 | 16 ms | 2824 KB | Output is correct |
7 | Correct | 9 ms | 596 KB | Output is correct |
8 | Correct | 33 ms | 5068 KB | Output is correct |
9 | Correct | 8 ms | 1748 KB | Output is correct |
10 | Correct | 35 ms | 5704 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 304 KB | Output is correct |
13 | Correct | 16 ms | 2236 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 45 ms | 5444 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 1 ms | 340 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 | 1 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 | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 304 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 13 ms | 2640 KB | Output is correct |
12 | Correct | 14 ms | 2776 KB | Output is correct |
13 | Correct | 15 ms | 1608 KB | Output is correct |
14 | Correct | 12 ms | 2544 KB | Output is correct |
15 | Correct | 20 ms | 2320 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 | 0 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 | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 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 | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 39 ms | 4540 KB | Output is correct |
10 | Correct | 35 ms | 4024 KB | Output is correct |
11 | Correct | 15 ms | 1492 KB | Output is correct |
12 | Correct | 14 ms | 1884 KB | Output is correct |
13 | Correct | 4 ms | 596 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 | 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 | 212 KB | Output is correct |
9 | Correct | 40 ms | 4456 KB | Output is correct |
10 | Correct | 31 ms | 3884 KB | Output is correct |
11 | Correct | 12 ms | 1592 KB | Output is correct |
12 | Correct | 15 ms | 1820 KB | Output is correct |
13 | Correct | 4 ms | 596 KB | Output is correct |
14 | Correct | 49 ms | 4832 KB | Output is correct |
15 | Correct | 55 ms | 5452 KB | Output is correct |
16 | Correct | 10 ms | 1268 KB | Output is correct |
17 | Correct | 36 ms | 4032 KB | Output is correct |
18 | Correct | 21 ms | 2436 KB | Output is correct |