QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21571#2851. 生生不息ha114514ha#AC ✓1ms5716kbC++204.2kb2022-03-07 15:10:022022-05-08 03:38:54

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:38:54]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:5716kb
  • [2022-03-07 15:10:02]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<queue>
#include<vector>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#include<ctime>
#include<random>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define bc(x) __builtin_popcount(x)
#define re register
#define il inline
#define pii pair<int,int>
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define mem0(x) memset(x,0,sizeof(x))
#define mem0x3f(x) memset(x,0x3f,sizeof(x))
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n';
// #pragma GCC optimize(3)
#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
namespace IO_BUFF{
	mt19937 rnd(time(0)^(ll)(new char));
	int rend(int x){
		return rnd()%x+1;
	}
	void rendom_shuffle(int *a,int len){
		shuffle(a+1,a+len+1,rnd);
	}
	const int BS=(1<<24)+5;char Buffer[BS],*HD,*TL;
	inline int gc(){
	    if(HD==TL) TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);
	    return (HD==TL)?EOF:*HD++;
	}
	inline int inn(){
	    int x,ch,s=1;while((ch=gc())<'0'||ch>'9')if(ch=='-')s=-1;x=ch^'0';
	    while((ch=gc())>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^'0');return x*s;
	}
	char ssss[19999999],tttt[20];int ssl,ttl;
    inline int print(int x)
    {
        if(x<0)ssss[++ssl]='-',x=(-x);
		if(!x) ssss[++ssl]='0';for(ttl=0;x;x/=10) tttt[++ttl]=char(x%10+'0');
        for(;ttl;ttl--) ssss[++ssl]=tttt[ttl];return ssss[++ssl]='\n';
    }
	inline int Flush(){return fwrite(ssss+1,sizeof(char),ssl,stdout),ssl=0,0;}
	int read(){
		char c=getchar();int x=1;int s=0;
		while(c<'0' || c>'9'){if(c=='-')x=-1;c=getchar();}
		while(c>='0' && c<='9'){
			s=s*10+c-'0';c=getchar();
		}
		return s*x;
	}
}using namespace IO_BUFF;
namespace CFConTest{
	const int mod=2148473648;
	inline int add(const int &x,const int &y){
		return (x+y>=mod?x+y-mod:x+y);
	}
	inline int del(const int &x,const int &y){
		return (x-y<0?x-y+mod:x-y);
	}
	int ksm(int x,int k){
		int base=1;
		while(k){
			if(k&1)base=1ll*base*x%mod;
			k>>=1;
			x=1ll*x*x%mod;
		}
		return base;
	}
};
using namespace CFConTest;
int T,n,m;
int f[1<<25],vis[1<<25];
int dx[]={-1,-1,-1,0,0,1,1,1};
int dy[]={-1,0,1,-1,1,-1,0,1};
#define id(x,y) ((x-1)*m+y)
bool check(int x,int y){
	if(x<1 || x>n || y<1 || y>m)return 0;
	return 1;
}
int bj[1<<25];
int check(int x){
	if(vis[x]){
		if(f[x]==-1){
			f[x]=1;return 1;
		}
		else return f[x];
	}
	vis[x]=1;
	int ne=0;
	for(int i=1;i<=n;i++){
		for(int k=1;k<=m;k++){
			int tmp=0;
			for(int j=0;j<8;j++){
				if(check(i+dx[j],k+dy[j])){
					if(x&(1<<(id(i+dx[j],k+dy[j])-1)))tmp++;
				}
			}
			if(tmp==3 && !(x&(1<<(id(i,k)-1))))ne|=(1<<((id(i,k)-1)));
			if((tmp==2 || tmp==3) && (x&(1<<(id(i,k)-1))))ne|=(1<<(id(i,k)-1));
		}
	}
	if(!ne)f[x]=0;
	else f[x]=check(ne);
	return f[x];
}
signed main(){
	#ifdef newbiewzs
		freopen("data.in","r",stdin);
	#else
	#endif
	//T=read();
	/*for(int i=1;i<=5;i++){
		for(int k=1;k<=5;k++){
			n=i;m=k;
		//	n=3;m=3;
			memset(f,-1,sizeof(f));
			memset(vis,0,sizeof(vis));
			int ans=0;
			for(int i=0;i<(1<<(n*m));i++){
				if(check(i)==1){
					ans++;
				}
			}
			cout<<n<<" "<<m<<" "<<ans<<'\n';
		}
	}*/
	T=read();
	while(T--){
		n=read();m=read();
		if(n==1 && m==1)cout<<0<<'\n';
		if(n==1 && m==2)cout<<0<<'\n';
		if(n==1 && m==3)cout<<0<<'\n';
		if(n==1 && m==4)cout<<0<<'\n';
		if(n==1 && m==5)cout<<0<<'\n';
		
		if(n==2 && m==1)cout<<0<<'\n';
		if(n==2 && m==2)cout<<5<<'\n';
		if(n==2 && m==3)cout<<18<<'\n';
		if(n==2 && m==4)cout<<73<<'\n';
		if(n==2 && m==5)cout<<267<<'\n';
		
		if(n==3 && m==1)cout<<0<<'\n';
		if(n==3 && m==2)cout<<18<<'\n';
		if(n==3 && m==3)cout<<150<<'\n';
		if(n==3 && m==4)cout<<1533<<'\n';
		if(n==3 && m==5)cout<<11398<<'\n';
		
		if(n==4 && m==1)cout<<0<<'\n';
		if(n==4 && m==2)cout<<73<<'\n';
		if(n==4 && m==3)cout<<1533<<'\n';
		if(n==4 && m==4)cout<<31828<<'\n';
		if(n==4 && m==5)cout<<469972<<'\n';
		
		if(n==5 && m==1)cout<<0<<'\n';
		if(n==5 && m==2)cout<<267<<'\n';
		if(n==5 && m==3)cout<<11398<<'\n';
		if(n==5 && m==4)cout<<469972<<'\n';
		if(n==5 && m==5)cout<<12785753<<'\n';	
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5716kb

input:

25
2 4
2 3
2 1
1 5
4 2
5 4
5 3
2 5
1 4
4 4
5 2
5 1
4 5
3 3
3 2
4 3
5 5
3 1
4 1
3 5
3 4
1 3
1 2
2 2
1 1

output:

73
18
0
0
73
469972
11398
267
0
31828
267
0
469972
150
18
1533
12785753
0
0
11398
1533
0
0
5
0

result:

ok 25 lines