QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#289361 | #5820. 置换 | Michstabe# | 0 | 4ms | 3752kb | C++14 | 1.0kb | 2023-12-23 17:17:28 | 2024-07-04 03:14:48 |
answer
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int factorial(int n) {
int result = 1;
for (int i = 2; i <= n; ++i) {
result = (result * i) % MOD;
}
return result;
}int modInverse(int a) {
int result = 1;
int exp = MOD - 2;
while (exp > 0) {
if (exp % 2 == 1) {
result = (result * a) % MOD;
}
a = (a * a) % MOD;
exp /= 2;
}
return result;
}int countValidShuffles(const std::vector<int>& Y, const int k) {
int n = Y.size();
int invFactorialN = modInverse(factorial(n));
int product = 1;
for (int i = 0; i < n; ++i) {
int x = i + 1;
if (Y[i] != x) {
product = (product * (Y[i] - 1)) % MOD;
}
}
return (product * invFactorialN) % MOD;
}int main() {
int T;
std::cin >> T;
for (int t = 0; t < T; ++t) {
int n, k;
cin >> n >> k;
vector<int> Y(n);
for(int i = 0; i < n; ++i) {
cin>>Y[i];
}
int result = countValidShuffles(Y, k);
cout << result << std::endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3576kb
input:
10 6 5 1 2 6 3 4 5 5 8 1 2 3 4 5 7 5 1 2 3 4 5 6 7 4 4 1 2 3 4 7 7 1 2 3 4 5 6 7 4 4 1 2 3 4 5 4 1 2 4 3 5 8 8 1 2 3 4 5 6 7 8 4 5 1 3 2 4 6 6 1 2 3 4 5 6
output:
-731382120 0 0 488935424 0 488935424 0 0 977870848 -6094851
result:
wrong answer 1st lines differ - expected: '1', found: '-731382120'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 3504kb
input:
10 4 6 3 1 2 4 5 8 2 1 3 4 5 8 4 1 2 3 4 5 6 7 8 6 5 4 1 2 3 5 6 5 5 1 2 3 4 5 5 5 1 2 3 4 5 6 7 1 2 3 4 5 6 6 4 1 2 3 4 5 6 6 7 6 1 2 3 4 5 7 6 1 2 3 4 5 6 7
output:
0 0 0 0 0 0 -6094851 -6094851 0 0
result:
wrong answer 3rd lines differ - expected: '6224', found: '0'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 3752kb
input:
10 6 602552 1 2 3 4 5 6 4 775694 1 2 4 3 6 668467 1 4 2 3 5 6 6 558385 1 2 6 3 4 5 7 832183 4 1 2 3 5 6 7 6 631375 1 2 3 4 5 6 8 519340 1 2 3 5 4 6 7 8 4 636124 1 2 3 4 4 759099 3 1 2 4 7 977752 1 2 3 4 5 6 7
output:
-6094851 -363110399 -36569106 -731382120 0 -6094851 0 488935424 0 0
result:
wrong answer 1st lines differ - expected: '256', found: '-6094851'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3504kb
input:
10 43 725761 1 2 3 4 5 6 7 8 10 9 11 12 13 15 14 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 37 542860 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 26 28 29 30 31 32 33 34 36 35 37 27 793967 2 1 4 3 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
output:
3211248 462432396 0 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '1', found: '3211248'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 3568kb
input:
10 40 535121 3 1 2 4 5 6 7 8 9 11 10 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 43 660193 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 15 19 17 18 20 26 21 22 23 24 25 27 28 29 30 34 31 32 33 35 36 37 38 39 40 41 42 43 38 596459 1 2 4 3 5 6 7 8 9 10 11 12 13 15 14 ...
output:
0 -967013034 0 0 0 -210692402 0 0 0 0
result:
wrong answer 1st lines differ - expected: '1', found: '0'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 3596kb
input:
10 33 892596 1 2 6 3 4 5 9 7 8 10 11 12 14 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 32 30 31 33 39 875634 1 2 10 3 4 5 6 7 8 9 11 12 13 14 16 15 17 18 20 19 21 22 23 24 26 25 27 28 29 30 31 32 33 35 34 36 37 38 39 27 856117 1 2 3 4 5 10 6 7 8 9 11 12 13 14 15 16 17 18 20 19 21 24 22 23 25 26 ...
output:
0 0 0 0 0 0 0 0 0 -862390999
result:
wrong answer 3rd lines differ - expected: '1', found: '0'
Test #7:
score: 0
Wrong Answer
time: 4ms
memory: 3616kb
input:
10 2899 540778 3 1 2 4 5 6 9 7 8 10 11 12 13 14 15 16 17 18 19 20 21 22 24 23 27 25 26 28 29 30 31 32 33 34 35 37 36 38 39 40 41 42 44 43 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 70 68 69 71 72 73 74 75 76 77 78 80 79 81 82 83 89 84 85 86 87 88 90 91 92 93 94 95 96 97 98 ...
output:
0 0 0 0 0 0 0 0 299529326 0
result:
wrong answer 2nd lines differ - expected: '786737927', found: '0'
Test #8:
score: 0
Wrong Answer
time: 4ms
memory: 3576kb
input:
10 2310 568163 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 26 24 25 27 28 30 29 31 32 33 34 35 36 37 38 39 40 41 46 42 43 44 45 47 48 49 50 51 52 57 53 54 55 56 58 59 61 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 ...
output:
922297479 0 280903989 0 0 0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '1', found: '922297479'
Test #9:
score: 0
Wrong Answer
time: 3ms
memory: 3604kb
input:
10 1564 511376 1 2 3 4 5 6 8 7 9 10 11 12 13 14 15 16 20 17 18 19 21 22 23 24 25 26 28 27 29 30 31 35 32 33 34 36 41 37 38 39 40 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 76 74 75 77 78 82 79 80 81 83 84 85 86 87 88 89 90 91 92 93 94 97 95 96 98 ...
output:
526963992 0 0 0 0 -82688928 0 0 0 0
result:
wrong answer 1st lines differ - expected: '0', found: '526963992'
Test #10:
score: 0
Wrong Answer
time: 3ms
memory: 3688kb
input:
10 1749 969801 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 34 31 32 33 36 35 37 38 39 40 41 42 43 44 45 46 48 47 49 50 51 54 52 53 55 56 57 58 60 59 61 62 63 64 65 66 67 68 69 70 71 72 73 75 74 76 77 78 79 80 81 82 83 84 85 86 89 87 88 90 91 92 93 94 95 96 97 99 ...
output:
0 -349398960 0 0 0 0 0 0 0 338829666
result:
wrong answer 2nd lines differ - expected: '0', found: '-349398960'