# HIIT Open 2016

 Start: 2016-05-28 11:00:00 End: 2016-05-28 16:00:00

CSES - HIIT Open 2016 - Results
History
2016-05-28 14:13:57
2016-05-28 14:12:35
 Task: Kaaleppi's puzzle Sender: Noname 01 Submission time: 2016-05-28 14:13:57 Language: C++ Status: READY Result: ACCEPTED

## Test results

 test verdict time (s) #1 ACCEPTED 0.05 / 5.00 details #2 ACCEPTED 0.29 / 5.00 details #3 ACCEPTED 0.10 / 5.00 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;
}

{
cin >> n;
}

void Solve()
{
long long ans;
int i, j;
long long cur;

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++) {
Solve();
}
return 0;
}```

## Test details

### Test 1

Verdict: ACCEPTED

input
```20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...```
view   save

correct output
```1 0 0 2 14 90 646 5242 47622 479306 5296790 63779034 831283558 661506141 203183149 878035968 456796197 911763426 428159996 654286749 ...```
view   save

user output
```1 0 0 2 14 90 646 5242 47622 479306 5296790 63779034 831283558 661506141 203183149 878035968 456796197 911763426 428159996 654286749 ...```
view   save

### Test 2

Verdict: ACCEPTED

input
```20 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 ...```
view   save

correct output
```436438246 92806357 21003215 151460560 326076265 424575830 228692865 201160758 157874096 500271360 735748839 456205691 368613063 327270428 147787261 753800152 993342525 445553830 110101472 711794305 ...```
view   save

user output
```436438246 92806357 21003215 151460560 326076265 424575830 228692865 201160758 157874096 500271360 735748839 456205691 368613063 327270428 147787261 753800152 993342525 445553830 110101472 711794305 ...```
view   save

### Test 3

Verdict: ACCEPTED

input
```20 352 478 99 92 723 608 491 441 38 12 905 907 42 558 218 960 555 381 518 ...```
view   save

correct output
```552481822 246955132 94569313 829032275 94621650 839827603 628162266 795849857 836338597 63779034 646544931 898906053 521761952 479901674 111527011 499723151 220091149 904428111 159152418 190829541 ...```
view   save

user output
```552481822 246955132 94569313 829032275 94621650 839827603 628162266 795849857 836338597 63779034 646544931 898906053 521761952 479901674 111527011 499723151 220091149 904428111 159152418 190829541 ...```
view   save