Submission #297955

#TimeUsernameProblemLanguageResultExecution timeMemory
297955mieszko11bGondola (IOI14_gondola)C++14
100 / 100
78 ms6776 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; using ii = pair<int, int>; using ll = long long; const ll MOD = ll(1e9) + 9; #define X first #define Y second vector<int> S; int valid(int n, int inputSeq[]) { vector<int> S(n); for(int i = 0 ; i < n ; i++) S[i] = inputSeq[i]; set<int> hlp; for(int x : S) { if(hlp.count(x)) return 0; hlp.insert(x); } for(int i = 0 ; i < n ; i++) { if(S[i] <= n) { rotate(S.begin(), S.begin() + (i - S[i] + 1 + n) % n, S.end()); break; } } for(int i = 0 ; i < n ; i++) if(S[i] <= n && S[i] != i + 1) return 0; ::S = S; return 1; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { valid(n, gondolaSeq); vector<int> res; vector<ii> V; for(int i = 0 ; i < n ; i++) if(S[i] > n) V.emplace_back(S[i], i + 1); sort(V.begin(), V.end()); int nxt = n + 1; for(auto p : V) { res.push_back(p.Y); nxt++; for( ; nxt <= p.X ; nxt++) res.push_back(nxt - 1); } for(int i = 0 ; i < res.size() ; i++) replacementSeq[i] = res[i]; return res.size(); } //---------------------- ll pot(ll a, ll b) { if(b == 0) return 1; if(b % 2) return pot(a, b - 1) * a % MOD; ll tmp = pot(a, b / 2); return tmp * tmp % MOD; } int countReplacement(int n, int inputSeq[]) { if(!valid(n, inputSeq)) return 0; ll res = 1; vector<int> V; bool any = false; for(int x : S) if(x > n) V.push_back(x); else any = true; V.push_back(n); sort(V.begin(), V.end()); for(int i = 0 ; i + 1 < V.size() ; i++) { int a = V[i]; int b = V[i + 1]; //~ cout << V.size() - i - 1 << " " << b - a << endl; res = res * pot(V.size() - i - 1, b - a - 1) % MOD; } if(!any) res = res * n % MOD; return res; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int i = 0 ; i < res.size() ; i++)
      |                  ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:94:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i = 0 ; i + 1 < V.size() ; i++) {
      |                  ~~~~~~^~~~~~~~~~
#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...