CSES - Datatähti 2025 alku - Results
Submission details
Task:Kortit II
Sender:vulpesomnia
Submission time:2024-10-30 20:29:47 +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.01 s2, 3, 4, 5details
#3--3, 4, 5details
#4--4, 5details
#50.03 s5details
#60.02 s5details

Code

#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

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 % 1000000007 * i) % 100000007;
  }
  return answer;
}

string sumtest(int n) {
  string answer = "1";
  for (int i = 2; i <= n; i++) {
    answer += "+" + to_string(i);
  }
  return answer;
}
string factortest(int n) {
  string answer = "1";
  for (int i = 2; i <= n; i++) {
    answer += "*" + to_string(i);
  }
  return answer;
}

vector<long> createNumberLine(int n) {
  vector<long> answer = {};
  for (long i = 1; i <= n; i++) {
    answer.push_back(i);
  }
  return answer;
}

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;*/

  // b permutations laske katso jos on samanlainen algoritmi
  // jos on skill issue käytä n² kaavaa? jos pystyy?



  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});
  }
  long mod = 1000000000 + 7;
  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
    //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<int> 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++;
        }
        next_permutation(l2.begin(),l2.end());
      }
      long kerroin = ((d%mod*n%mod)%mod != 0) ? (d%mod*n%mod)%mod : 1;
      cout << (p%mod * fcm(n)%mod * kerroin%mod)%mod << "\n";
    } else {
      cout << 0 << "\n";
    }
  } 
}

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
0
0
0
0
0
...

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
0
0
0
0
0
...