/*input
*/
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
}
using namespace my_template;
const int MOD = 1000000009;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
vi kur(250002);
ll mypow(ll a, ll b)
{
ll res = 1;
a %= MOD;
while (b)
{
if (b & 1)
res = (res * a) % MOD;
b >>= 1;
a = (a * a) % MOD;
}
return res;
}
int valid(int n, int inputSeq[])
{
set<int> turiu;
for (int i = 0; i < n; ++i)
{
if (turiu.find(inputSeq[i]) != turiu.end()) return 0;
turiu.insert(inputSeq[i]);
}
int pos = -1;
for (int i = 0; i < n; ++i)
{
if (inputSeq[i] <= n) {
pos = (i - inputSeq[i] + 1 + n) % n;
break;
}
}
if (pos == -1) return 1;
for (int i = 0; i < n; ++i)
{
if (inputSeq[(pos + i) % n] <= n and inputSeq[(pos + i) % n] != i + 1)
return 0;
}
return 1;
}
//----------------------
int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
int pos = -1;
for (int i = 0; i < n; ++i)
{
if (gondolaSeq[i] <= n) {
pos = (i - gondolaSeq[i] + 1 + n) % n;
break;
}
}
vi inputSeq;
if (pos == -1) {
for (int i = 1; i <= n; ++i)
inputSeq.emplace_back(i);
} else {
inputSeq.resize(n);
for (int i = 0; i < n; ++i)
inputSeq[(pos + i) % n] = i + 1;
}
vpi sk; // {val, pos}
for (int i = 0; i < n; ++i)
{
if (gondolaSeq[i] > n) {
sk.emplace_back(gondolaSeq[i], i);
}
}
sort(sk.begin(), sk.end());
int piv = n + 1;
// for (auto u : sk) printf("%d %d\n", u.x, u.y);
int ind = 0;
for (int i = 0; i < (int)sk.size(); ++i)
{
while (inputSeq[sk[i].y] != gondolaSeq[sk[i].y]) {
replacementSeq[ind++] = inputSeq[sk[i].y];
// sk[i].x = piv++;
inputSeq[sk[i].y] = piv++;
}
}
return ind;
}
//----------------------
int countReplacement(int n, int inputSeq[])
{
if (!valid(n, inputSeq)) return 0;
ll ret = 1;
int posit = 0;
vpi sk;
for (int i = 0; i < n; ++i)
{
if (inputSeq[i] > n) {
posit++;
sk.emplace_back(inputSeq[i], i);
}
}
sort(sk.begin(), sk.end());
// for (auto u : sk) printf("%d %d\n", u.x, u.y);
int last = n;
for (int i = 0; i < (int)sk.size(); ++i)
{
// printf("posit = %d, kit = %d\n", posit, sk[i].x - last - 1);
ret = (ret * mypow(posit, sk[i].x - last - 1)) % MOD;
posit--;
last = sk[i].x;
}
if ((int)sk.size() == n) ret = (ret * n) % MOD;
// TODO kai visi > n
return (int)ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
19 ms |
3200 KB |
Output is correct |
7 |
Correct |
18 ms |
1664 KB |
Output is correct |
8 |
Correct |
32 ms |
4956 KB |
Output is correct |
9 |
Correct |
13 ms |
2560 KB |
Output is correct |
10 |
Correct |
40 ms |
5624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
6 ms |
1280 KB |
Output is correct |
6 |
Correct |
19 ms |
3200 KB |
Output is correct |
7 |
Correct |
18 ms |
1664 KB |
Output is correct |
8 |
Correct |
34 ms |
4984 KB |
Output is correct |
9 |
Correct |
13 ms |
2432 KB |
Output is correct |
10 |
Correct |
40 ms |
5496 KB |
Output is correct |
11 |
Correct |
5 ms |
1280 KB |
Output is correct |
12 |
Correct |
5 ms |
1280 KB |
Output is correct |
13 |
Correct |
24 ms |
3072 KB |
Output is correct |
14 |
Correct |
5 ms |
1280 KB |
Output is correct |
15 |
Correct |
53 ms |
5624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1308 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
6 ms |
1280 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1408 KB |
Output is correct |
9 |
Correct |
5 ms |
1408 KB |
Output is correct |
10 |
Correct |
6 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1408 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1408 KB |
Output is correct |
9 |
Correct |
6 ms |
1408 KB |
Output is correct |
10 |
Correct |
6 ms |
1408 KB |
Output is correct |
11 |
Correct |
16 ms |
1920 KB |
Output is correct |
12 |
Correct |
18 ms |
2048 KB |
Output is correct |
13 |
Correct |
20 ms |
2312 KB |
Output is correct |
14 |
Correct |
17 ms |
1920 KB |
Output is correct |
15 |
Correct |
26 ms |
3320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1408 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1280 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1280 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1280 KB |
Output is correct |
9 |
Correct |
59 ms |
5488 KB |
Output is correct |
10 |
Correct |
44 ms |
4728 KB |
Output is correct |
11 |
Correct |
19 ms |
2560 KB |
Output is correct |
12 |
Correct |
22 ms |
2816 KB |
Output is correct |
13 |
Correct |
9 ms |
1664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1280 KB |
Output is correct |
2 |
Correct |
5 ms |
1408 KB |
Output is correct |
3 |
Correct |
5 ms |
1280 KB |
Output is correct |
4 |
Correct |
5 ms |
1280 KB |
Output is correct |
5 |
Correct |
5 ms |
1408 KB |
Output is correct |
6 |
Correct |
5 ms |
1280 KB |
Output is correct |
7 |
Correct |
5 ms |
1280 KB |
Output is correct |
8 |
Correct |
5 ms |
1280 KB |
Output is correct |
9 |
Correct |
54 ms |
5496 KB |
Output is correct |
10 |
Correct |
43 ms |
4856 KB |
Output is correct |
11 |
Correct |
19 ms |
2552 KB |
Output is correct |
12 |
Correct |
22 ms |
2944 KB |
Output is correct |
13 |
Correct |
9 ms |
1664 KB |
Output is correct |
14 |
Correct |
68 ms |
6392 KB |
Output is correct |
15 |
Correct |
77 ms |
7032 KB |
Output is correct |
16 |
Correct |
16 ms |
2432 KB |
Output is correct |
17 |
Correct |
49 ms |
5112 KB |
Output is correct |
18 |
Correct |
30 ms |
3448 KB |
Output is correct |