Submission #1776409
Source Code Expand
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
int n,m,k,fb[22][22],s[2][1<<21];
const ll MOD=1e9+7;
int main()
{
scanf("%d%d%d",&n,&m,&k); --n;
for(int i=1,a,b,c;i<=k;++i)
scanf("%d%d%d",&a,&b,&c),fb[a][b-1]|=1<<(!c);
s[0][0]=1; int x=0;
for(int i=1;i<=m;++i)
{
for(int j=0;j<n;++j)
{
x^=1; memset(s[x],0,sizeof s[x]);
for(int r=0;r<(1<<n);++r)
{
bool a=(r>>j)&1;
for(int w=a;w<=1;++w)
{
if(fb[i][j]&(1<<w)) continue;
register int g,tt;
if(w==a) g=r;
else
{
g=r|(1<<j),tt=r>>j;
if(tt) g^=(tt&-tt)<<j;
}
s[x][g]+=s[!x][r];
(s[x][g]>=MOD)?(s[x][g]-=MOD):0;
}
}
}
}
ll ans=0;
for(int r=0;r<(1<<n);++r) ans+=s[x][r];
printf("%lld\n",ans%MOD);
}
Submission Info
Submission Time
2017-11-16 12:26:10+0900
Task
F - Zigzag
User
fjzzq2002
Language
C++14 (GCC 5.4.1)
Score
1600
Code Size
1767 Byte
Status
AC
Exec Time
1639 ms
Memory
16640 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:36:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&m,&k); --n;
^
./Main.cpp:38:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&a,&b,&c),fb[a][b-1]|=1<<(!c);
^
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
13 ms
16640 KB
a10.txt
AC
1198 ms
16640 KB
a11.txt
AC
1112 ms
16640 KB
a12.txt
AC
1097 ms
16640 KB
a13.txt
AC
1040 ms
16640 KB
a2.txt
AC
13 ms
16640 KB
a3.txt
AC
12 ms
16640 KB
a4.txt
AC
41 ms
16640 KB
a5.txt
AC
109 ms
16640 KB
a6.txt
AC
1579 ms
16640 KB
a7.txt
AC
1420 ms
16640 KB
a8.txt
AC
1472 ms
16640 KB
a9.txt
AC
1351 ms
16640 KB
b1.txt
AC
78 ms
16640 KB
b10.txt
AC
1288 ms
16640 KB
b11.txt
AC
1115 ms
16640 KB
b12.txt
AC
1040 ms
16640 KB
b13.txt
AC
1001 ms
16640 KB
b14.txt
AC
955 ms
16640 KB
b15.txt
AC
906 ms
16640 KB
b16.txt
AC
873 ms
16640 KB
b17.txt
AC
837 ms
16640 KB
b2.txt
AC
667 ms
16640 KB
b3.txt
AC
35 ms
16640 KB
b4.txt
AC
71 ms
16640 KB
b5.txt
AC
13 ms
16640 KB
b6.txt
AC
114 ms
16640 KB
b7.txt
AC
1613 ms
16640 KB
b8.txt
AC
1511 ms
16640 KB
b9.txt
AC
1404 ms
16640 KB
n18.txt
AC
412 ms
16640 KB
n19.txt
AC
781 ms
16640 KB
n20.txt
AC
1605 ms
16640 KB
sample1.txt
AC
6 ms
16640 KB
sample2.txt
AC
6 ms
16640 KB
sample3.txt
AC
11 ms
16640 KB
sample4.txt
AC
1639 ms
16640 KB