| Task: | Kortit II |
| Sender: | vulpesomnia |
| Submission time: | 2024-10-30 23:20:32 +0200 |
| Language: | C++ (C++11) |
| Status: | READY |
| Result: | 3 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 3 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| #5 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5 | details |
| #2 | TIME LIMIT EXCEEDED | -- | 2, 3, 4, 5 | details |
| #3 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
| #4 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #5 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #6 | WRONG ANSWER | 0.02 s | 5 | details |
Code
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
long mod = 1000000000 + 7;
int fc(int factor) { //factorial
int answer = 1;
for (long i = 1; i <= factor; i++) {
answer *= i;
}
return answer;
}
long fcm(int factor) { //factorial
long answer = 1;
for (long i = 1; i <= factor; i++) {
answer = (answer % mod * i % mod) % mod;
}
return answer;
}
vector<long> createNumberLine(int n) {
vector<long> answer = {};
for (long i = 1; i <= n; i++) {
answer.push_back(i);
}
return answer;
}
vector<vector<long>> testInput(int amt) {
vector<vector<long>> answer = {};
int a = 1;
int b = 1;
int n = 1;
for (int i = 1; i <= amt*amt*amt; i++) {
if (a % amt == 1 && a != 1) {
a = 1;
b++;
if (b % amt == 1 && b != 1) {
b = 1;
n++;
}
}
answer.push_back({n, a, b});
cout << n << " " << a << " " << b << "\n";
a++;
}
return answer;
}
void printArray(vector<long> a) {
for (int i = 0; i < (int)a.size(); i++) {
cout << a[i] << " ";
}
cout << "\n";
}
long bruteForce(int n, int a, int b) {
long p = 0;
vector<long> l1 = createNumberLine(n);
vector<long> l2 = createNumberLine(n);
for (int i = 1; i <= fc(n); i++) {
for (int j = 1; j <= fc(n); j++) {
int a1 = 0;
int b1 = 0;
for (int k = 0; k < n; k++) {
if (l1[k] > l2[k]) {
a1++;
} else if (l2[k] > l1[k]) {
b1++;
}
}
if (a1 == a && b1 == b) {
p++;
}
next_permutation(l2.begin(), l2.end());
}
next_permutation(l1.begin(), l1.end());
}
return p;
}
string isCorrect(long answer, int n, int a, int b) {
long bf = bruteForce(n, a, b);
if (answer == bf) {
return "true " + to_string(bf);
} else {
return "false A: " + to_string(answer) + " | BF: " + to_string(bf) + " " + to_string(n) + " " + to_string(a) + " " + to_string(b);
}
}
int main() {
/*int a = 0;
int n = 0;
cout << "n, a: ";
cin >> n >> a;
int ap = 0; //a permutations
for (int i = 1; i <= n; i++) {
int d = n-i; // Vaikutusalue
if (d >= a) { //kertolasku amt: a-1 ja summa amt: d-a+1
int sum = (d-a+1 != 0) ? d-a+1 : 1;
ap += (fc(n-i)/fc(sum))*((sum*(sum+1)/2));
cout << "x: " << i << " ap: " << factortest(n-i) << "/" << factortest(sum) << " sum: " << sumtest(sum) << endl;
cout << "ap: " << (fc(n-i)/fc(sum))*((sum*(sum+1)/2)) << endl;
} else {
continue; //break; ??
}
}
cout << ap;*/
long t;
vector<vector<long>> g;
cin >> t;
for (long i = 0; i < t; i++) {
long n, a, b;
cin >> n >> a >> b;
g.push_back({n, a, b});
}
//vector<vector<long>> g = testInput(4);
for (long i = 0; i < (long)g.size(); i++) {
long n = g[i][0];
long a = g[i][1];
long b = g[i][2];
long d = n-(a+b); //Tasapelit
cout << bruteForce(n, a, b) << "\n";
continue;
//Tasapelikerroin on tasapelit * n
//Permutaatiokerroin on n!
//Nykyinen tavoite: Hanki kaikki permutaatiot järjestykselle 1, 2, 3.. n
//
long n2 = n-d; //Uusi n
long p = 0;
//if (a+b <= n && (abs(a-b) != a+b || a+b == 0)) {
/*for (int x = 0; x < n; x++) {
Oikea O(n) ratkaisu tulee tähän
}*/
//Bruteforce test:
vector<long> l1 = createNumberLine(n);
vector<long> l2 = createNumberLine(n);
for (long j = 1; j <= fc(n2); j++) {
long a1 = 0;
long b1 = 0;
for (long k = 0; k < (long)l2.size(); k++) {
if (l2[k] > k+1) {
b1++;
} else if (l2[k] < k+1) {
a1++;
}
}
if (a1 == a && b1 == b) {
p++;
cout << "\n";
printArray(l1);
printArray(l2);
}
next_permutation(l2.begin(),l2.end());
}
if (p == 0) {
cout << 0 << "\n";//" | " << n << " " << a << " " << b << "\n";
} else {
long kerroin = (d != 0) ? ((d%mod)*(n%mod))%mod : 1;
long vastaus = (( ( (p%mod) * (fcm(n)%mod) ) % mod ) * kerroin % mod ) % mod;
cout << isCorrect(vastaus, n, a, b) << "\n";//<< " | " << n << " " << a << " " << b << "\n";
}
}// else {
//cout << 0 << "\n";
//}
//}
}
Test details
Test 1
Group: 1, 2, 3, 4, 5
Verdict: ACCEPTED
| 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: TIME LIMIT EXCEEDED
| input |
|---|
| 284 6 1 0 5 0 2 7 1 5 7 7 5 ... |
| correct output |
|---|
| 0 0 35280 0 36720 ... |
| user output |
|---|
| (empty) |
Test 3
Group: 3, 4, 5
Verdict: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| 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: TIME LIMIT EXCEEDED
| 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: WRONG ANSWER
| input |
|---|
| 1000 2000 1107 508 2000 1372 249 2000 588 65 2000 1739 78 ... |
| correct output |
|---|
| 750840601 678722180 744501884 159164549 868115056 ... |
| user output |
|---|
| 0 0 0 0 0 ... |
