#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int len = 305, mod = 1e9+7;
int dp[len][len][len];
vector<int> vec[len];
int add(int a, int b){
return (a+b)%mod;
}
int mul(int a, int b){
return (a*1LL*b)%mod;
}
int solve(int x, int y, int z){
if (x == 0 && y == 0 && z == 0)
return 1;
if (dp[x][y][z] != -1)
return dp[x][y][z];
int ans = 0;
for (int bit = 1; bit < 8; bit++){
int s[] = {x, y, z};
int c = 1;
for (int i = 0; i < 3; i++){
if ((bit&(1<<i)) && s[i] > 0)
c = mul(c, s[i]), s[i]--;
else if (!(bit&(1<<i)) && s[(i+2)%3] > 0)
c = mul(c, s[(i+2)%3]), s[(i+2)%3]--, s[(i+1)%3]++;
else
c = 0;
}
if (c > 0)
ans = add(ans, mul(c, solve(s[0], s[1], s[2])));
}
return dp[x][y][z] = ans;
}
int main(){
int n, t;
scanf("%d %d", &n, &t);
for (int x = 0; x <= 3*n; x++)
for (int y = 0; y <= 3*n; y++)
for (int z = 0; z <= 3*n; z++)
dp[x][y][z] = -1;
for (int test = 0; test < t; test++){
for (int card = 1; card <= 3*n; card++)
vec[card].clear();
for (int t = 0; t < 3; t++){
for (int i = 0; i < 2*n; i++){
int card;
scanf("%d", &card);
vec[card].pb(t);
}
}
int x = 0, y = 0, z = 0;
for (int card = 1; card <= 3*n; card++){
int a = vec[card][0], b = vec[card][1];
if (a > b) swap(a, b);
if (a == 0 && b == 1) x++;
if (a == 1 && b == 2) y++;
if (a == 0 && b == 2) z++;
}
printf("%d\n", solve(x, y, z));
}
return 0;
}
Compilation message
fishing.cpp: In function 'int main()':
fishing.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
46 | scanf("%d %d", &n, &t);
| ~~~~~^~~~~~~~~~~~~~~~~
fishing.cpp:60:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
60 | scanf("%d", &card);
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
1644 KB |
Output isn't correct |
4 |
Incorrect |
4 ms |
4972 KB |
Output isn't correct |
5 |
Incorrect |
26 ms |
28140 KB |
Output isn't correct |
6 |
Incorrect |
41 ms |
40080 KB |
Output isn't correct |
7 |
Incorrect |
59 ms |
54252 KB |
Output isn't correct |
8 |
Incorrect |
87 ms |
70764 KB |
Output isn't correct |
9 |
Incorrect |
116 ms |
89152 KB |
Output isn't correct |
10 |
Incorrect |
163 ms |
107628 KB |
Output isn't correct |