//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█
#include <bits/stdc++.h>
using namespace std;
typedef long long int lo;
//~ #define int long long
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n*2;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const int li = 302;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flagt,t,dp[li][li][li][3][2];
int cev;
//~ map<PIIIII,int> dp;
inline int add(int x,int y){
if(x+y>=mod)return x+y-mod;
return x+y;
}
inline int f(int x,int y,int z,int kim,bool last){
int cevv=0;
//~ if(x==0 && z==0 && kim==1)return 1;
//~ if(y==0 && x==0 && kim==2)return 1;
//~ if(z==0 && y==0 && kim==3)return 1;
//~ if(z==0 && last==0 && kim==3)return 1;
if(x==0 && y==0 && z==0)return 1;
if(dp[x][y][z][kim][last]!=0)return dp[x][y][z][kim][last];
//~ cout<<x<<" : : "<<y<<" : ;"<<z<<endl;
if(kim==0){
if(x==0 && z==0)cevv=add(cevv,f(x,y,z,1,0));
for(int i=1;i<=x;i++)cevv=add(cevv,f(x-1,y,z,1,1));
for(int i=1;i<=z;i++)cevv=add(cevv,f(x,y+1,z-1,1,0));
}
if(kim==1){
if(y==0 && x==0)cevv=add(cevv,f(x,y,z,2,last));
for(int i=1;i<=y;i++)cevv=add(cevv,f(x,y-1,z,2,1));
for(int i=1;i<=x;i++)cevv=add(cevv,f(x-1,y,z+1,2,last));
}
if(kim==2){
//~ if(last && y==0)cevv=add(cevv,f(x,y,z,1,0));
for(int i=1;i<=z;i++)cevv=add(cevv,f(x,y,z-1,0,0));
if(last)for(int i=1;i<=y;i++)cevv=add(cevv,f(x+1,y-1,z,0,0));
}
return dp[x][y][z][kim][last]=cevv;
}
inline int clearr(int x,int y,int z,int kim,bool last){
int cevv=0;
//~ if(x==0 && z==0 && kim==1)return 1;
//~ if(y==0 && x==0 && kim==2)return 1;
//~ if(z==0 && y==0 && kim==3)return 1;
//~ if(z==0 && last==0 && kim==3)return 1;
if(x==0 && y==0 && z==0)return 0;
//~ dp[x][y][z][kim][last]=0;
if(dp[x][y][z][kim][last]!=0)return 0;
//~ cout<<x<<" : : "<<y<<" : ;"<<z<<endl;
if(kim==0){
if(x==0 && z==0)cevv=add(cevv,clearr(x,y,z,1,0));
for(int i=1;i<=x;i++)cevv=add(cevv,clearr(x-1,y,z,1,1));
for(int i=1;i<=z;i++)cevv=add(cevv,clearr(x,y+1,z-1,1,0));
}
if(kim==1){
if(y==0 && x==0)cevv=add(cevv,clearr(x,y,z,2,last));
for(int i=1;i<=y;i++)cevv=add(cevv,clearr(x,y-1,z,2,1));
for(int i=1;i<=x;i++)cevv=add(cevv,clearr(x-1,y,z+1,2,last));
}
if(kim==2){
//~ if(last && y==0)cevv=add(cevv,f(x,y,z,1,0));
for(int i=1;i<=z;i++)cevv=add(cevv,clearr(x,y,z-1,0,0));
if(last)for(int i=1;i<=y;i++)cevv=add(cevv,clearr(x+1,y-1,z,0,0));
}
return dp[x][y][z][kim][last]=0;
}
main(void){
scanf("%d %d",&n,&t);
while(t--){
//~ dp.clear();
FOR{
scanf("%d",&a[i]);
}
FOR{
scanf("%d",&b[i]);
}
int aveb=0,avec=0,bvec=0;
FOR{
int oku;
scanf("%d",&oku);
for(int j=1;j<=n*2;j++){
if(oku==a[j])avec++;
if(oku==b[j])bvec++;
}
}
FOR{
for(int j=1;j<=n*2;j++){
if(a[i]==b[j])aveb++;
}
}
//~ for(int i=0;i<=aveb+bvec;i++){
//~ for(int j=0;j<=bvec+avec;j++){
//~ for(int jj=0;jj<=avec+aveb;jj++){
//~ for(int kk=0;kk<=2;kk++){
//~ dp[i][j][jj][kk][0]=-1;
//~ dp[i][j][jj][kk][1]=-1;
//~ }
//~ }
//~ }
//~ }
//~ aveb=2;
//~ avec=2;
//~ bvec=2;
//~ cout<<aveb<<" :: "<<bvec<<" :: "<<avec<<endl;
printf("%d\n",f(aveb,bvec,avec,0,0));
//~ clearr(aveb,bvec,avec,0,0);
}
return 0;
}
Compilation message
fishing.cpp:94:10: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
94 | main(void){
| ^
fishing.cpp: In function 'int main()':
fishing.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
95 | scanf("%d %d",&n,&t);
| ~~~~~^~~~~~~~~~~~~~~
fishing.cpp:99:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
99 | scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
fishing.cpp:102:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
102 | scanf("%d",&b[i]);
| ~~~~~^~~~~~~~~~~~
fishing.cpp:107:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
107 | scanf("%d",&oku);
| ~~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
1408 KB |
Output is correct |
4 |
Correct |
8 ms |
4480 KB |
Output is correct |
5 |
Correct |
193 ms |
27768 KB |
Output is correct |
6 |
Correct |
332 ms |
41252 KB |
Output is correct |
7 |
Correct |
587 ms |
57976 KB |
Output is correct |
8 |
Correct |
974 ms |
78052 KB |
Output is correct |
9 |
Correct |
1526 ms |
101624 KB |
Output is correct |
10 |
Execution timed out |
2088 ms |
120468 KB |
Time limit exceeded |