제출 #582943

#제출 시각아이디문제언어결과실행 시간메모리
582943thezomb1e곤돌라 (IOI14_gondola)C++17
75 / 100
46 ms5180 KiB
#include "gondola.h" #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define eb emplace_back #define pb push_back #define ft first #define sd second #define pi pair<int, int> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define dbg(...) dbg_out(__VA_ARGS__) using ll = long long; using ld = long double; using namespace std; using namespace __gnu_pbds; //Constants const ll INF = 5 * 1e18; const int IINF = 2 * 1e9; const ll MOD = 1e9 + 9; // const ll MOD = 998244353; const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ld PI = 3.14159265359; //Templates template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';} template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';} void dbg_out() {cerr << endl;} template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); } template<typename T> void mins(T& x, T y) {x = min(x, y);} template<typename T> void maxs(T& x, T y) {x = max(x, y);} template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; int valid(int n, int inputSeq[]) { set<int> st; int mini = 0; for (int i = 0; i < n; i++) { st.insert(inputSeq[i]); if (inputSeq[i] < inputSeq[mini]) mini = i; } if (n != (int) st.size()) return 0; if (inputSeq[mini] > n) return 1; for (int i = 0; i < n; i++) { int pos = (mini + i) % n; if (inputSeq[pos] > n) continue; if (inputSeq[pos] != inputSeq[mini] + i) return 0; } return 1; } int replacement(int n, int gondolaSeq[], int replacementSeq[]) { int mini = 0; for (int i = 0; i < n; i++) { if (gondolaSeq[i] < gondolaSeq[mini]) mini = i; } int val = gondolaSeq[mini]; if (val > n) mini = 0, val = 1; vector<pi> ar(n); for (int i = 0; i < n; i++) { int pos = (mini + i) % n; ar[pos] = {gondolaSeq[pos], val}; val++; if (val > n) val = 1; } sort(all(ar)); int pp = 0; int z = n + 1; for (int i = 0; i < n; i++) { if (ar[i].ft <= n) continue; int cur = ar[i].sd; while (cur < ar[i].ft) { replacementSeq[pp++] = cur; cur = z++; } } return pp; } ll bp(ll a, ll n) { if (n == 0) return 1ll; if (n & 1) return a * bp(a, n - 1) % MOD; ll h = bp(a, n / 2); return h * h % MOD; } int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; int bad = 0; for (int i = 0; i < n; i++) { if (inputSeq[i] > n) bad++; } sort(inputSeq, inputSeq + n); ll ans = 1; int cur = n + 1; for (int i = 0; i < n; i++) { if (inputSeq[i] <= n) continue; int k = inputSeq[i] - cur; (ans *= bp(bad, k)) %= MOD; cur = inputSeq[i] + 1; bad--; } 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...