Submission #18988207


Source Code Expand

/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define mod 1000000007
using namespace std;
const int N=25;
int n,m,k,lim[N][N],dp[2][1<<21];
inline void add(int &a,int b){a=((a+b>=mod)?a+b-mod:a+b);}
inline void del(int &a,int b){a=((a-b<0)?a-b+mod:a-b);}
inline void mul(int &a,int b){a=1ll*a*b%mod;}
inline int m_pow(int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) mul(ans,a);
		b>>=1;
		mul(a,a);
	}
	return ans;
}
inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}
inline int lowbit(int x){return x&(-x);}
signed main()
{
	n=read()-1;m=read();k=read();
	memset(lim,-1,sizeof(lim));
	for (int i=1;i<=k;i++)
	{
		int a=read(),b=read()-1,c=read();
		lim[a][b]=c;
	}
	int full=(1<<n)-1;
	for (int mask=0;mask<=full;mask++)
	{
		bool bl=1;
		for (int i=0;i<n;i++)
		{
			if (lim[1][i]==-1) continue;
			if (lim[1][i]!=((mask>>i)&1))
			{
				bl=0;
				break;
			}
		}
		if (bl) dp[0][mask]=1;
	}
	int cur=1;
	for (int i=2;i<=m;i++)
	{
		for (int j=0;j<n;j++)
		{
			memset(dp[cur],0,(1<<n)*sizeof(int));
			for (int mask=0;mask<=full;mask++)
			{
				if (!dp[cur^1][mask]) continue;
				if (lim[i][j]!=1&&(mask>>j)%2==0) add(dp[cur][mask],dp[cur^1][mask]);
				if (lim[i][j]!=0)
				{
					if ((mask>>j)&1){add(dp[cur][mask],dp[cur^1][mask]);continue;}
					int s=mask>>(j+1),t=(mask&((1<<(j+1))-1));
					if (!s) add(dp[cur][mask|(1<<j)],dp[cur^1][mask]);
					else
					{
						s-=lowbit(s);s=(s<<(j+1))|t;s|=(1<<j);
						add(dp[cur][s],dp[cur^1][mask]);
					}
				}
			}
			// for (int mask=0;mask<=full;mask++) printf("%d ",dp[cur][mask]);
			// printf("\n");
			cur^=1;
		}
	}
	cur^=1;
	int ans=0;
	for (int mask=0;mask<=full;mask++) add(ans,dp[cur][mask]);
	printf("%d\n",ans);
}

Submission Info

Submission Time
Task F - Zigzag
User SevenDawns
Language C++ (GCC 9.2.1)
Score 1600
Code Size 1964 Byte
Status AC
Exec Time 670 ms
Memory 7820 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1600 / 1600
Status
AC × 4
AC × 41
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 8 ms 3724 KiB
a10.txt AC 328 ms 7520 KiB
a11.txt AC 220 ms 7656 KiB
a12.txt AC 201 ms 7724 KiB
a13.txt AC 201 ms 7640 KiB
a2.txt AC 2 ms 3668 KiB
a3.txt AC 2 ms 3656 KiB
a4.txt AC 2 ms 3496 KiB
a5.txt AC 20 ms 3852 KiB
a6.txt AC 655 ms 7648 KiB
a7.txt AC 522 ms 7724 KiB
a8.txt AC 543 ms 7520 KiB
a9.txt AC 451 ms 7524 KiB
b1.txt AC 3 ms 3560 KiB
b10.txt AC 403 ms 7584 KiB
b11.txt AC 241 ms 7664 KiB
b12.txt AC 156 ms 7820 KiB
b13.txt AC 135 ms 7700 KiB
b14.txt AC 128 ms 7768 KiB
b15.txt AC 130 ms 7720 KiB
b16.txt AC 124 ms 7596 KiB
b17.txt AC 127 ms 7720 KiB
b2.txt AC 243 ms 7636 KiB
b3.txt AC 3 ms 3660 KiB
b4.txt AC 16 ms 4628 KiB
b5.txt AC 2 ms 3628 KiB
b6.txt AC 39 ms 7708 KiB
b7.txt AC 656 ms 7524 KiB
b8.txt AC 602 ms 7820 KiB
b9.txt AC 487 ms 7656 KiB
n18.txt AC 149 ms 4524 KiB
n19.txt AC 309 ms 5656 KiB
n20.txt AC 670 ms 7724 KiB
sample1.txt AC 2 ms 3504 KiB
sample2.txt AC 3 ms 3624 KiB
sample3.txt AC 3 ms 3424 KiB
sample4.txt AC 668 ms 7664 KiB