Submission #706468

#TimeUsernameProblemLanguageResultExecution timeMemory
706468Hacv16Gondola (IOI14_gondola)C++17
55 / 100
31 ms5100 KiB
#include <bits/stdc++.h> #include "gondola.h" using namespace std; typedef long long ll; const int MOD = 1e9 + 9; const int INF = 0x3f3f3f3f; ll fexp(ll b, ll e){ if(e == 0) return 1; if(e % 2 == 0) return fexp((b * b) % MOD, e >> 1); return (b * fexp(b, e - 1)) % MOD; } int valid(int n, int v[]){ set<int> s(v, v + n); if((int) s.size() != n) return 0; for(int i = 0; i < n; i++){ if(v[i] > n) continue; int left = (v[i] == 1 ? n : v[i] - 1), right = (v[i] == n ? 1 : v[i] + 1); int lefViz = (i == 0 ? v[n - 1] : v[i - 1]); int rigViz = (i == n - 1 ? v[0] : v[i + 1]); if((lefViz != left && lefViz <= n) || (rigViz != right && rigViz <= n)) return 0; } return 1; } int countReplacement(int n, int v[]){ if(!valid(n, v)) return 0; set<ll> s; for(int i = 0; i < n; i++) if(v[i] > n) s.insert(v[i]); ll ans = (((int) s.size() != n) ? 1 : n); ll cnt = s.size(), cur = n + 1; for(auto x : s){ ll exp = x - cur; ans = (ans * fexp(cnt, exp)) % MOD; cur = x + 1; cnt--; } return (int) cnt; } int replacement(int n, int v[], int answer[]){ vector<int> order(n); vector<pair<int, int>> aux; int mn = INF, mnidx = 0; for(int i = 0; i < n; i++) if(v[i] < mn){ mn = v[i]; mnidx = i; } if(mn > n) mnidx = 0, mn = 1; for(int i = 0; i < n; i++){ order[(i + mnidx) % n] = mn; mn = (mn == n ? 1 : mn + 1); } for(int i = 0; i < n; i++) if(v[i] > n) aux.push_back({v[i], order[i]}); sort(aux.begin(), aux.end()); int numOp = 0; for(int i = 0, val = n; i < aux.size(); i++){ answer[numOp++] = aux[i].second; val++; while(val < aux[i].first) answer[numOp++] = val++; } return numOp; }

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:76:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for(int i = 0, val = n; i < aux.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...