제출 #336840

#제출 시각아이디문제언어결과실행 시간메모리
336840arwaeystoamneg곤돌라 (IOI14_gondola)C++17
100 / 100
84 ms6124 KiB
#include "gondola.h" /* ID: awesome35 LANG: C++14 TASK: vans */ #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include<unordered_set> #include<unordered_map> #include<chrono> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef pair<ll, ll> pll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(),x.end() #define f first #define s second #define cont continue #define endl '\n' #define ednl '\n' #define test int testc;cin>>testc;while(testc--) #define pr(a, b) trav(x,a)cerr << x << b; cerr << endl; #define message cout << "Hello World" << endl; const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!! const ll linf = 4000000000000000000LL; const ll inf = 1000000009;//998244353 const ld pi = 3.1415926535; void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; } }void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; } int valid(int n, int* a) { set<int>t; F0R(i, n)t.insert(a[i]); if (sz(t) != n)return 0; int index = 0; for (; index < n; index++) { if (a[index] <= n)break; } if (index == n)return 1; vi b(n); F0R(i, n) { b[(i - index + a[index] - 1 + n) % n] = a[i]; } F0R(i, n) { if (b[i] <= n) { if (b[i] - i != 1)return 0; } } return 1; } int replacement(int n, int* a, int* ans) { int index = 0; for (; index < n; index++) { if (a[index] <= n)break; } vi b(n); F0R(i, n)b[i] = a[i]; if (index != n) { F0R(i, n) { b[(i - index + a[index] - 1 + n) % n] = a[i]; } } F0R(i, n)a[i] = b[i]; vi cur(n); iota(all(cur), 1); set<int>next; map<int, int>last; F0R(i, n)last.insert({ a[i],i }); F0R(i, n)if (a[i] != i + 1)next.insert(i); index = 0;// ptr in ans int t = *max_element(a, a + n); FOR(i, n + 1, t + 1) { if (last.count(i)) { ans[index++] = cur[last[i]]; next.erase(last[i]); } else { ans[index++] = cur[*next.begin()]; cur[*next.begin()] = i; } } return t - n; } ll power(ll x, ll y) { ll k = 1LL << 60; ll z = 1; while (k != 0) { z *= z; z %= inf; if (y >= k) { z *= x; z %= inf; y -= k; } k >>= 1; } return z; } int countReplacement(int n, int* a) { if (!valid(n, a))return 0; int index = 0; for (; index < n; index++) { if (a[index] <= n)break; } vi b(n); F0R(i, n)b[i] = a[i]; if (index != n) { F0R(i, n) { b[(i - index + a[index] - 1 + n) % n] = a[i]; } } F0R(i, n)a[i] = b[i]; vi cur(n); iota(all(cur), 1); int next = 0; vi last; F0R(i, n)last.pb(a[i]); sort(all(last)); F0R(i, n)if (a[i] != i + 1)next++; ll ans = 1; int i = lower_bound(all(last), n + 1) - last.begin(); if (i == n)return 1; ans = power(next, last[i] - n - 1); next--; for (; i < n - 1; i++) { int j = i + 1; ans *= power(next, last[j] - last[i] - 1); ans %= inf; next--; } if (index == n) { ans *= n; ans %= inf; } return ans; }
#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...