Submission #469599

#TimeUsernameProblemLanguageResultExecution timeMemory
469599Soumya1Gondola (IOI14_gondola)C++17
100 / 100
68 ms5904 KiB
#include "gondola.h" #include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; int valid(int n, int a[]) { bool ok = true; map<int, bool> mp; for (int i = 0; i < n; i++) { ok &= (!mp[a[i]]); mp[a[i]] = true; } int pos = -1, val = -1; for (int i = 0; i < n; i++) { if (a[i] <= n) { val = a[i]; pos = i; break; } } val++; if (val > n) val = 1; for (int i = pos + 1; i < n; i++) { if (a[i] <= n) { ok &= (a[i] == val); } val++; if (val > n) val = 1; } for (int i = 0; i < pos; i++) { if (a[i] <= n) { ok &= (a[i] == val); } val++; if (val > n) val = 1; } return (int) ok; } int replacement(int n, int a[], int ans[]) { int pos = -1, val = -1; for (int i = 0; i < n; i++) { if (a[i] <= n) { pos = i; val = a[i]; break; } } vector<pair<int, int>> v; for (int i = 0; i < n; i++) { if (a[i] > n) v.push_back({a[i], i}); } if (pos != -1) { for (int i = pos; i < n; i++) { a[i] = val++; if (val > n) val = 1; } for (int i = 0; i < pos; i++) { a[i] = val++; if (val > n) val = 1; } } else { for (int i = 0; i < n; i++) a[i] = i + 1; } int ptr = 0; sort(v.begin(), v.end()); int cur = n + 1; for (int i = 0; i < v.size(); i++) { while (cur <= v[i].first) { ans[ptr++] = a[v[i].second]; a[v[i].second] = cur++; } } return ptr; } int bigmod(int a, int b) { a %= mod; int res = 1; while (b > 0) { if (b & 1) res = (1LL * res * a) % mod; a = (1LL * a * a) % mod, b >>= 1; } return res; } int countReplacement(int n, int a[]) { if (!valid(n, a)) return 0; int ans = 1; sort(a, a + n); int last = n; for (int i = 0; i < n; i++) { if (a[i] > n) { if (i == 0) ans = (1LL * ans * n) % mod; ans = (1LL * ans * bigmod(n - i, a[i] - last - 1)) % mod; last = a[i]; } } return ans; }

Compilation message (stderr)

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