CSES - Datatähti 2025 alku - Results
Submission details
Task:Kortit II
Sender:MikaelE
Submission time:2024-11-10 16:32:19 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
#40
#50
Test results
testverdicttimegroup
#10.00 s1, 2, 3, 4, 5details
#20.04 s2, 3, 4, 5details
#3--3, 4, 5details
#4--4, 5details
#5--5details
#6--5details

Code

#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
long long factorial(int num){
long long answer = 1;
for(int i = num; i > 0; i--){
answer *= i;
}
return answer;
}
int nums(int size, int depth, unordered_set<int>* previousNums, int* points){
int successes = 0;
for(int i = 1; i <= size; i++){
if(i == depth) continue;
long unsigned int setSize = previousNums->size();
previousNums->insert(i);
if(previousNums->size() == setSize){
continue;
}
if(i < depth) *points -= 1;
if(*points > size - depth || 0 - *points > size - depth){
previousNums->erase(i);
if(i < depth) *points += 1;
continue;
}
if(depth == size){
if(*points == 0){
successes++;
}
previousNums->erase(i);
if(i < depth) *points += 1;
if(i == size){
return successes;
}
continue;
}
successes += nums(size, depth + 1, previousNums, points);
previousNums->erase(i);
if(i < depth) *points += 1;
}
return successes;
}
struct testStruct{
int n, player1Points, player2Points;
public:
testStruct(){
n = 0;
player1Points = 0;
player2Points = 0;
}
};
int binomialCoefficients(int n, int k) {
if (k == 0 || k == n)
return 1;
return binomialCoefficients(n - 1, k - 1) + binomialCoefficients(n - 1, k);
}
int main(){
int testCounts;
cin >> testCounts;
vector<testStruct> tests;
for(int i = 0; i < testCounts; i++){
testStruct test;
cin >> test.n >> test.player1Points >> test.player2Points;
tests.push_back(test);
}
//5!/(1!*(5-1)!) * 5! * 7
for(testStruct test : tests){
unordered_set<int> previous;
if(test.player1Points == 0 || test.player2Points == 0){
cout << 0 << endl;
continue;
}
if(test.player1Points + test.player2Points > test.n){
cout << 0 << endl;
continue;
}
int points = test.player1Points;
int successes = nums(test.player1Points + test.player2Points, 1, &previous, &points);
cout << (factorial(test.n) * binomialCoefficients(test.n, (test.n - test.player1Points - test.player2Points)) * successes) % (1000000000 + 7) << endl;
}
return 0;
}

Test details

Test 1

Group: 1, 2, 3, 4, 5

Verdict:

input
54
4 4 0
3 1 3
3 2 2
4 0 4
...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 2

Group: 2, 3, 4, 5

Verdict:

input
284
6 1 0
5 0 2
7 1 5
7 7 5
...

correct output
0
0
35280
0
36720
...

user output
0
0
35280
0
36720
...

Test 3

Group: 3, 4, 5

Verdict:

input
841
19 3 12
19 19 13
19 7 13
20 11 15
...

correct output
40291066
0
0
0
0
...

user output
(empty)

Test 4

Group: 4, 5

Verdict:

input
1000
15 12 6
7 1 6
44 4 26
6 6 5
...

correct output
0
5040
494558320
0
340694548
...

user output
(empty)

Test 5

Group: 5

Verdict:

input
1000
892 638 599
966 429 655
1353 576 1140
1403 381 910
...

correct output
0
0
0
249098285
0
...

user output
(empty)

Test 6

Group: 5

Verdict:

input
1000
2000 1107 508
2000 1372 249
2000 588 65
2000 1739 78
...

correct output
750840601
678722180
744501884
159164549
868115056
...

user output
(empty)