Task: | Kortit II |
Sender: | vulpesomnia |
Submission time: | 2024-10-31 20:31:35 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 8 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 3 |
#2 | ACCEPTED | 5 |
#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 | ACCEPTED | 0.01 s | 2, 3, 4, 5 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3, 4, 5 | details |
#4 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
#5 | WRONG ANSWER | 0.07 s | 5 | details |
#6 | WRONG ANSWER | 0.22 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; } string printFactor(int n) { string answer = "1"; for (int i = 2 ; i <= n; i++) { answer += "*" + to_string(i); } 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); } } // d kertaa -> 1+2+3 ja 1+2 ja 1 long sumOfSums(int d, int n) { /*long answer = 0; for (int i = 1; i <= n-d+1; i++) { int x = n-i-1; answer += x*(x+1)/2; string test = "1"; for (int j = 2; j <= x; j++) { test += "+" + to_string(j); } cout << test << endl; } return (answer != 0) ? answer : 1;*/ return (fcm(n)%mod)/((fcm(d)%mod)*(fcm(n-d)%mod)); } 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;*/ /*cout << sumOfSums(2, 4) << endl; return 0;*/ long t; vector<vector<long>> g; cin >> t; for (long i = 0; i < t; i++) { long n, a, b; cin >> n >> a >> b; long d = n-(a+b); //Tasapelit //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(n2); vector<long> l2 = createNumberLine(n2); 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()); } //TASAPELIT EI LASKETA OIKEIN //long kerroin = (d != 0) ? fcm(d)*fcm(n2) : 1;//((d%mod)*(n%mod))%mod : 1; //TEE STRING VERSIO MATIKASTA: 4 1 1: 576/144 = 4 = (1*2*3*->4<-) //cout << "Math: " << p << " * " << printFactor(n2) << " * (" << printFactor(d) << " * " << n << ") * " << "( " << printFactor(n) << " / " << printFactor(n-d) << " )" << "\n"; //TODO: vaihda d! * JOTAIN se kerroin JOTAIN //(n-1) * (n-1)(n-2) d-1 kertaa ja yhteensä d kertaa ////(fc(n)/fc(n-d));//(( ( (p%mod) * (fcm(n)%mod) ) % mod ) * kerroin % mod ) % mod; //long vastaus = p * fc(n2) * (fc(d)*(n)) * sumOfSums(d, n) * fc(d); //kaik //long vastaus = p * fc(n2) * (1+2+3) * (d*(d+1)/2); //long vastaus = p * fc(n2) * fc(d) * ((n-1)*(n-1+1)/2) * sumOfSums(d, n); long vastaus = ((p%mod) * (fcm(n2)%mod) * (sumOfSums(d, n)%mod) * (sumOfSums(d, n)%mod) * (fcm(d)%mod))%mod; //cout << isCorrect(vastaus, n, a, b) << "\n";//<< " | " << n << " " << a << " " << b << "\n"; cout << vastaus << "\n"; } else { cout << 0 << "\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: ACCEPTED
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: 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: WRONG ANSWER
input |
---|
1000 892 638 599 966 429 655 1353 576 1140 1403 381 910 ... |
correct output |
---|
0 0 0 249098285 0 ... |
user output |
---|
0 0 0 0 0 ... |
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 ... |