Submission #1775619
Source Code Expand
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1100000
#define mod 1000000007
using namespace std;
int n, m, k, bin[25], f[N], g[N][25], map[25][25], x, y, z, sum, LOG[N], ans, ff, L, last;
int main(){
scanf("%d%d%d", &n, &m, &k);
bin[0]=1; for(int i=1; i<=n; i++)bin[i]=bin[i-1]<<1;
LOG[0]=-1; for(int i=1; i<=bin[n]; i++)LOG[i]=LOG[i>>1]+1;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)map[i][j]=2;
for(int i=1; i<=k; i++){scanf("%d%d%d", &x, &y, &z); map[x][y]=z^1;}
if(n==1){printf("1"); return 0;} n--;
memset(g, 0, sizeof(g)); sum=1;
for(int owo=1; owo<=m; owo++){
memset(f, 0, sizeof(f));
for(int s=0; s<=bin[n]-1; s++){
ff=1;
for(int i=1; i<=n; i++)if(((s&bin[n-i])?1:0)==map[owo][i]){ff=0; break;}
if(!ff)continue;
for(int i=1; i<=n; i++)if(!(s&bin[i-1])){
f[s]+=g[((s+bin[i-1])>>(i-1))<<(i-1)][1]; if(f[s]>=mod)f[s]-=mod;
}
f[s]=sum-f[s]; if(f[s]<0)f[s]+=mod;
}
sum=0;
for(int s=0; s<=bin[n]-1; s++){sum+=f[s]; if(sum>=mod)sum-=mod;}
memset(g, 0, sizeof(g));
for(int s=bin[n]-1; s; s--){
L=n-LOG[s&(-s)]; g[s][L]=f[s];
for(int i=1; i<=n-L; i++){g[s][L]+=g[s+bin[n-L-i]][L+i]; if(g[s][L]>=mod)g[s][L]-=mod;}
}
for(int s=1; s<=bin[n]-1; s++){
L=n-LOG[s&(-s)]; last=n;
for(int i=L-1; i; i--){
g[s][i]=g[s][i+1];
if(!(s&bin[n-L+i])){
if(last==n)continue;
g[s][i]+=g[s+bin[n-L+i]-bin[last]][i+1]; if(g[s][i]>=mod)g[s][i]-=mod;
}else last=n-L+i;
}
}
}
ans=0; for(int i=0; i<=bin[n]-1; i++){ans+=f[i]; if(ans>=mod)ans-=mod;}
printf("%d", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Zigzag |
User |
leoly |
Language |
C++14 (GCC 5.4.1) |
Score |
1600 |
Code Size |
1619 Byte |
Status |
AC |
Exec Time |
2737 ms |
Memory |
116224 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:9:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &n, &m, &k);
^
./Main.cpp:14:53: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=k; i++){scanf("%d%d%d", &x, &y, &z); map[x][y]=z^1;}
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1600 / 1600 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt, sample4.txt |
All |
sample1.txt, sample2.txt, sample3.txt, sample4.txt, a1.txt, a10.txt, a11.txt, a12.txt, a13.txt, a2.txt, a3.txt, a4.txt, a5.txt, a6.txt, a7.txt, a8.txt, a9.txt, b1.txt, b10.txt, b11.txt, b12.txt, b13.txt, b14.txt, b15.txt, b16.txt, b17.txt, b2.txt, b3.txt, b4.txt, b5.txt, b6.txt, b7.txt, b8.txt, b9.txt, n18.txt, n19.txt, n20.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt |
Case Name |
Status |
Exec Time |
Memory |
a1.txt |
AC |
92 ms |
112128 KB |
a10.txt |
AC |
1832 ms |
116224 KB |
a11.txt |
AC |
1631 ms |
116224 KB |
a12.txt |
AC |
1517 ms |
116224 KB |
a13.txt |
AC |
1355 ms |
116224 KB |
a2.txt |
AC |
92 ms |
112128 KB |
a3.txt |
AC |
92 ms |
112128 KB |
a4.txt |
AC |
158 ms |
112128 KB |
a5.txt |
AC |
257 ms |
112256 KB |
a6.txt |
AC |
2707 ms |
116224 KB |
a7.txt |
AC |
2444 ms |
116224 KB |
a8.txt |
AC |
2425 ms |
116224 KB |
a9.txt |
AC |
2122 ms |
116224 KB |
b1.txt |
AC |
289 ms |
112128 KB |
b10.txt |
AC |
2041 ms |
116224 KB |
b11.txt |
AC |
1591 ms |
116224 KB |
b12.txt |
AC |
1262 ms |
116224 KB |
b13.txt |
AC |
1157 ms |
116224 KB |
b14.txt |
AC |
1112 ms |
116224 KB |
b15.txt |
AC |
1099 ms |
116224 KB |
b16.txt |
AC |
1096 ms |
116224 KB |
b17.txt |
AC |
1095 ms |
116224 KB |
b2.txt |
AC |
1097 ms |
116224 KB |
b3.txt |
AC |
275 ms |
112128 KB |
b4.txt |
AC |
118 ms |
113152 KB |
b5.txt |
AC |
289 ms |
112128 KB |
b6.txt |
AC |
179 ms |
116224 KB |
b7.txt |
AC |
2704 ms |
116224 KB |
b8.txt |
AC |
2555 ms |
116224 KB |
b9.txt |
AC |
2325 ms |
116224 KB |
n18.txt |
AC |
738 ms |
113152 KB |
n19.txt |
AC |
1388 ms |
116224 KB |
n20.txt |
AC |
2736 ms |
116224 KB |
sample1.txt |
AC |
53 ms |
112128 KB |
sample2.txt |
AC |
53 ms |
112128 KB |
sample3.txt |
AC |
80 ms |
112128 KB |
sample4.txt |
AC |
2737 ms |
116224 KB |