Submission #336828

#TimeUsernameProblemLanguageResultExecution timeMemory
336828arwaeystoamneg곤돌라 (IOI14_gondola)C++17
90 / 100
56 ms17004 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; } const int MAX = 1e6 + 1; int last[MAX]; 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; F0R(i, MAX)last[i] = -1; F0R(i, n)last[a[i]] = i; F0R(i, n)if (a[i] != i + 1)next++; int t = *max_element(a, a + n); ll ans = 1; FOR(i, n + 1, t + 1) { if (last[i] != -1) { next--; } else { ans *= next; ans %= inf; } } 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...