Submission #51109572


Source Code Expand

// LUOGU_RID: 150146216
// LUOGU_RID: 150076734
// Author: gsczl71
// Copyright (c) 2024 gsczl71 All rights reserved.

#include<bits/stdc++.h>
#define ll long long
#define i128 __int128
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fs first
#define sc second
#define endl '\n'
#define debug puts("AK IOI")
#define re register
#define pb push_back
#define mem(a,x) memset((a),(x),sizeof(a))
#define vi vector<int>
#define pq priority_queue
using namespace std;
//#define int long long
const int mod = 1e9+7;
//const int mod = 998244353;
const int inf = 0x3f3f3f3f,N = 7,M = 1e6+5,K = 3000+5;
const long long linf = 0x3f3f3f3f3f3f3f3f;
int a[N][N];
int vis[N][N];
int color[N][N];
int n;
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
pii js(int x){
	return {(x-1)/4+1,(x-1)%4+1};
}
void dfs(int x,int y,int col){
	for(int i = 0 ;i < 4;i++){
		int xx = x + dx[i];
		int yy = y + dy[i];
		if(xx >= 0 && xx <= 5 &&yy >= 0 &&yy <= 5 && (vis[xx][yy]^(col-1)) && !color[xx][yy]){
			color[xx][yy] = col;
			dfs(xx,yy,col);
		}
	}
}
void solve(){
	n=4;
	for(int i = 1;i <= n;i++) for(int j = 1;j <= n;j++) cin >> a[i][j];
	
	int ans=0;
	for(int i = 1;i<=(1<<(n*n))-1;i++){
		int flag=1;
		for(int j = 1;j <= n * n ;j++){
			if(!((i>>(j-1))&1)&&a[js(j).fs][js(j).sc]) {
				flag=0;break;
			}vis[js(j).fs][js(j).sc] = (i>>(j-1))&1;
		}if(flag){
			// ans++;
			int col = 0;
			memset(color,0,sizeof color);
			int flag=1;
			for(int x = 1;x <= n && flag;x++){
				for(int y = 1;y <= n;y++){
					if(vis[x][y] && !col && !color[x][y]){
						color[x][y] = ++col;
						dfs(x,y,col);flag=0;break;
						
					}
				}
			}
			flag = 1;
			for(int x=0;x<=5 && flag;x++){
				for(int y=0;y<=5;y++){
					if(!vis[x][y] && col && !color[x][y]){
						color[x][y] = ++col;
						dfs(x,y,col);
						flag=0;
						break;
					}
				}
			}
			int ok = 1;
			for(int x = 0;x<=5;x++){
				for(int y = 0;y <= 5;y++){
					if(color[x][y] == 0){
						ok = 0;
						break;
					}
				}
			}
			if(ok) ans++;
		}
	}cout<<ans<<endl;
}
signed main(){
	// ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int T=1;
//	cin >> T;
	while(T--) solve();
	return 0;
}

Submission Info

Submission Time
Task E - Moat
User Expert_Dream
Language C++ 17 (gcc 12.2)
Score 500
Code Size 2304 Byte
Status AC
Exec Time 19 ms
Memory 3636 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 48
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 19 ms 3488 KiB
001.txt AC 19 ms 3448 KiB
002.txt AC 19 ms 3428 KiB
003.txt AC 11 ms 3528 KiB
004.txt AC 10 ms 3428 KiB
005.txt AC 6 ms 3448 KiB
006.txt AC 4 ms 3524 KiB
007.txt AC 11 ms 3524 KiB
008.txt AC 11 ms 3452 KiB
009.txt AC 4 ms 3400 KiB
010.txt AC 3 ms 3396 KiB
011.txt AC 3 ms 3444 KiB
012.txt AC 1 ms 3528 KiB
013.txt AC 1 ms 3424 KiB
014.txt AC 1 ms 3416 KiB
015.txt AC 3 ms 3488 KiB
016.txt AC 2 ms 3444 KiB
017.txt AC 1 ms 3460 KiB
018.txt AC 1 ms 3492 KiB
019.txt AC 1 ms 3528 KiB
020.txt AC 1 ms 3552 KiB
021.txt AC 1 ms 3636 KiB
022.txt AC 1 ms 3552 KiB
023.txt AC 1 ms 3524 KiB
024.txt AC 6 ms 3520 KiB
025.txt AC 6 ms 3456 KiB
026.txt AC 8 ms 3528 KiB
027.txt AC 8 ms 3444 KiB
028.txt AC 4 ms 3448 KiB
029.txt AC 4 ms 3448 KiB
030.txt AC 4 ms 3444 KiB
031.txt AC 1 ms 3456 KiB
032.txt AC 1 ms 3476 KiB
033.txt AC 1 ms 3472 KiB
034.txt AC 11 ms 3428 KiB
035.txt AC 1 ms 3444 KiB
036.txt AC 2 ms 3552 KiB
037.txt AC 1 ms 3636 KiB
038.txt AC 1 ms 3448 KiB
039.txt AC 1 ms 3488 KiB
040.txt AC 2 ms 3468 KiB
041.txt AC 3 ms 3440 KiB
042.txt AC 2 ms 3488 KiB
043.txt AC 1 ms 3428 KiB
044.txt AC 2 ms 3396 KiB
045.txt AC 2 ms 3520 KiB
example0.txt AC 6 ms 3472 KiB
example1.txt AC 1 ms 3624 KiB