Submission #793879

#TimeUsernameProblemLanguageResultExecution timeMemory
793879Ronin13곤돌라 (IOI14_gondola)C++17
75 / 100
34 ms5264 KiB
#include "gondola.h" #include <bits/stdc++.h> #define ll long long #define ull unsigned ll #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back using namespace std; const ll mod = 1e9 + 9; int valid(int n, int a[]){ vector <pii> vv; set <int> st; for(int i = 0; i < n; i++){ if(st.find(a[i]) != st.end()) return 0; st.insert(a[i]); if(a[i] <= n) vv.pb({a[i], i}); } sort(vv.begin(), vv.end()); for(int i = 1; i < vv.size(); i++){ int x = vv[i].s, y = vv[i - 1].s; int dist = vv[i].f - vv[i - 1].f; if((x - y + n) % n != dist) return 0; } return 1; } //---------------------- int replacement(int n, int a[], int b[]) { int c[n]; int cur = n + 1; int ind = 0; vector <pii> vv; int x, y; for(int i = 0; i < n; i++){ if(a[i] > n) vv.pb({a[i], i}); else x = a[i], y = i; } if(vv.size() == n){ for(int i = 0; i < n; i++) c[i] = i + 1; } else{ for(int i = 0; i < n; i++){ int dist = (i - y + n) % n; c[i] = (x + dist - 1) % n + 1; } } sort(vv.begin(), vv.end()); for(int i = 0; i < vv.size(); i++){ while(cur <= vv[i].f) b[ind] = c[vv[i].s], c[vv[i].s] = cur, ind++, cur++; } return ind; } //---------------------- ll logpow(ll a, ll p){ if(p == 0) return 1; ll x = logpow(a, p / 2); x *= x, x %= mod; if(p & 1) x *= a, x %= mod; return x; } int countReplacement(int n, int a[]) { if(!valid(n, a)) return 0; vector <int> vv; int cnt = 0; for(int i = 1; i <= n; i++){ if(a[i] > n) cnt++, vv.pb(a[i]); } bool x = (cnt == n); sort(vv.begin(), vv.end()); int last = n; ll ans = 1; for(int i = 0; i < vv.size(); i++){ int c = vv[i] - last - 1; ans *= logpow(cnt, c); cnt--; ans %= mod; last = vv[i]; } if(x) ans *= (ll)n, ans %= mod; return ans; }

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 1; i < vv.size(); i++){
      |                    ~~^~~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:49:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |   if(vv.size() == n){
      |      ~~~~~~~~~~^~~~
gondola.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i = 0; i < vv.size(); i++){
      |                  ~~^~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |   for(int i = 0; i < vv.size(); i++){
      |                  ~~^~~~~~~~~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:44:10: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |   int x, y;
      |          ^
gondola.cpp:55:19: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |         c[i] = (x + dist - 1) % n + 1;
      |                 ~~^~~~~~
#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...