제출 #637307

#제출 시각아이디문제언어결과실행 시간메모리
637307ghostwriter곤돌라 (IOI14_gondola)C++14
100 / 100
58 ms5964 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ bool checkdistinct(int n, int inputSeq[]) { map<int, int> c; FOR(i, 0, n - 1) { ++c[inputSeq[i]]; if (c[inputSeq[i]] > 1) return 0; } return 1; } int getoriginalpos(int n, int inputSeq[]) { FOR(i, 0, n - 1) if (inputSeq[i] <= n) return i; return -1; } int valid(int n, int inputSeq[]) { if (!checkdistinct(n, inputSeq)) return 0; int pos = getoriginalpos(n, inputSeq); if (pos == -1) return 1; FOR(i, 0, n - 1) { if (inputSeq[i] > n || i == pos) continue; int val = (i - pos + inputSeq[pos] - 1 + n) % n + 1; if (inputSeq[i] != val) return 0; } return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vpi a; int pos = getoriginalpos(n, gondolaSeq); if (pos == -1) pos = 0; FOR(i, 0, n - 1) { if (gondolaSeq[i] <= n) continue; int val = (i - pos + gondolaSeq[pos] - 1 + n) % n + 1; a.pb({gondolaSeq[i], val}); } sort(all(a)); int cur = n, l = 0; EACH(i, a) { replacementSeq[l++] = i.nd; ++cur; WHILE(cur < i.st) replacementSeq[l++] = cur++; } return l; } //---------------------- const int M = 1e9 + 9; int fpow(int a, int b, int M) { if (b == 0) return 1; int tmp = fpow(a, b >> 1, M); if (b & 1) return 1LL * tmp * tmp % M * a % M; return 1LL * tmp * tmp % M; } int countReplacement(int n, int inputSeq[]) { if (!valid(n, inputSeq)) return 0; vi a; FOR(i, 0, n - 1) { if (inputSeq[i] <= n) continue; a.pb(inputSeq[i]); } if (a.empty()) return 1; sort(all(a)); int pre = n, total = sz(a), rs = 1; EACH(i, a) { int cnt = i - pre - 1; rs = 1LL * rs * fpow(total, cnt, M) % M; pre = i; --total; } int pos = getoriginalpos(n, inputSeq); if (pos == -1) rs = 1LL * rs * n % M; return rs; } /* 10 4 4 7 4 7 */

컴파일 시 표준 에러 (stderr) 메시지

gondola.cpp: In function 'bool checkdistinct(int, int*)':
gondola.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
gondola.cpp:40:5: note: in expansion of macro 'FOR'
   40 |     FOR(i, 0, n - 1) {
      |     ^~~
gondola.cpp: In function 'int getoriginalpos(int, int*)':
gondola.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
gondola.cpp:47:5: note: in expansion of macro 'FOR'
   47 |     FOR(i, 0, n - 1)
      |     ^~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
gondola.cpp:56:5: note: in expansion of macro 'FOR'
   56 |     FOR(i, 0, n - 1) {
      |     ^~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
gondola.cpp:70:5: note: in expansion of macro 'FOR'
   70 |     FOR(i, 0, n - 1) {
      |     ^~~
gondola.cpp:28:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   28 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
gondola.cpp:77:5: note: in expansion of macro 'EACH'
   77 |     EACH(i, a) {
      |     ^~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
gondola.cpp:96:5: note: in expansion of macro 'FOR'
   96 |     FOR(i, 0, n - 1) {
      |     ^~~
gondola.cpp:28:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   28 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
gondola.cpp:103:5: note: in expansion of macro 'EACH'
  103 |     EACH(i, a) {
      |     ^~~~
#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...