# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
921167 | 2024-02-03T11:38:45 Z | Macker | Gondola (IOI14_gondola) | C++17 | 16 ms | 2260 KB |
#include "gondola.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() ll mod = 1e9+7; ll power(ll n, ll k){ ll res = 1; n %= mod; while(k > 0){ if(k & 1) res = (res * n) % mod; n = (n * n) % mod; k /= 2; } return res; } int valid(int n, int inputSeq[]) { return countReplacement(n, inputSeq) != 0; } //---------------------- int replacement(int n, int gondolaSeq[], int replacementSeq[]) { vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { v[i] = {gondolaSeq[i], i}; } sort(all(v)); ll strt = -1; for (auto &i : v) { if(i.first <= n){ strt = (i.second - i.first + 1 + n) % n; break; } } if(strt == -1) strt = 0; for (int i = 0; i < n; i++) { gondolaSeq[i] = (i - strt + n) % n + 1; } int ls = n; int j = 0; for (auto &i : v) { while(ls < i.first){ replacementSeq[j++] = gondolaSeq[i.second]; ls++; gondolaSeq[i.second] = ls; } } return j; } //---------------------- int countReplacement(int n, int inputSeq[]) { vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { v[i] = {inputSeq[i], i}; } sort(all(v)); for (int i = 1; i < v.size(); i++) { if(v[i].first == v[i - 1].first) return 0; } ll strt = -1; ll fin = 0; bool m = true; ll res = 1; for (int j = 0; j < v.size(); j++) { auto i = v[j]; if(i.first <= n){ if(strt == -1){ strt = (i.second - i.first + 1 + n) % n; } else{ if((i.second - i.first + 1 + n) % n != strt) return 0; } m = false; } else{ ll ls; if(j == 0 || v[j - 1].first <= n){ ls = n; } else ls = v[j - 1].first; res = (res * power(n - fin, i.first - ls - 1)) % mod; } fin++; } if(m) res = (res * n) % mod; return res; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 5 ms | 964 KB | Output is correct |
7 | Correct | 12 ms | 1880 KB | Output is correct |
8 | Correct | 10 ms | 1628 KB | Output is correct |
9 | Correct | 4 ms | 604 KB | Output is correct |
10 | Correct | 12 ms | 1880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 5 ms | 860 KB | Output is correct |
7 | Correct | 12 ms | 1748 KB | Output is correct |
8 | Correct | 8 ms | 1628 KB | Output is correct |
9 | Correct | 4 ms | 604 KB | Output is correct |
10 | Correct | 12 ms | 1884 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 5 ms | 860 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 12 ms | 1908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 532 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 448 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 444 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 344 KB | Output is correct |
11 | Correct | 11 ms | 1628 KB | Output is correct |
12 | Correct | 11 ms | 1884 KB | Output is correct |
13 | Correct | 11 ms | 1352 KB | Output is correct |
14 | Correct | 8 ms | 1628 KB | Output is correct |
15 | Correct | 16 ms | 2260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Incorrect | 0 ms | 344 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Incorrect | 1 ms | 348 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 444 KB | Output is correct |
5 | Correct | 1 ms | 352 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Incorrect | 1 ms | 344 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |