Task: | Kaaleppi's puzzle |
Sender: | Noname 01 |
Submission time: | 2016-05-28 14:12:35 +0300 |
Language: | C++ |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | WRONG ANSWER | 0.05 s | details |
#2 | ACCEPTED | 0.28 s | details |
#3 | ACCEPTED | 0.10 s | details |
Code
// NONAME-01 #include <bits/stdc++.h> using namespace std; long long p = 1000000007; int n; long long dp[1011][2]; long long C[1011][1011]; long long F[1011]; long long p2[1011]; void Fill() { int i, j; C[0][0] =1; for (i = 1; i <= 1000; i++) { C[i][0] = 1; for (j = 1; j <= i; j++) { C[i][j] = ( C[i-1][j-1] + C[i-1][j] ) % p; } } F[0] = F[1] = 1; for (i = 2; i <= 1000; i++) { F[i] = (i * F[i-1]) % p; } p2[0] = 1; for (i = 1; i <= 1000; i++) p2[i] = (2 * p2[i-1]) % p; } long long FF(int n, int i, int j) { return (C[i-1][i-j] * C[n-i][j]) % p; // put i conflicts in j bins; } void Load() { cin >> n; } void Solve() { long long ans; int i, j; long long cur; if (n < 3) { cout << "0\n"; return; } ans = F[n] % p; for (i = 1; i <= n-1; i++) { for (j = 1; j <= i && j+i <= n; j++) { cur = p2[j]; cur = (cur * F[n-i]) % p; cur = (cur * FF(n, i, j)) % p; if (i % 2 == 0) ans = (ans+cur) % p; else ans = (ans-cur+p) % p; } } cout << ans << "\n"; } int main() { Fill(); memset(dp, -1, sizeof(dp)); ios_base::sync_with_stdio(0); cin.tie(0); int nt, tt; cin >> nt; for (tt = 0; tt < nt; tt++) { Load(); Solve(); } return 0; }
Test details
Test 1
Verdict: WRONG ANSWER
input |
---|
20 1 2 3 4 ... |
correct output |
---|
1 0 0 2 14 ... |
user output |
---|
0 0 0 2 14 ... |
Test 2
Verdict: ACCEPTED
input |
---|
20 981 982 983 984 ... |
correct output |
---|
436438246 92806357 21003215 151460560 326076265 ... |
user output |
---|
436438246 92806357 21003215 151460560 326076265 ... |
Test 3
Verdict: ACCEPTED
input |
---|
20 352 478 99 92 ... |
correct output |
---|
552481822 246955132 94569313 829032275 94621650 ... |
user output |
---|
552481822 246955132 94569313 829032275 94621650 ... |