Submission #27691693


Source Code Expand

#include<bits/stdc++.h>
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define ll long long
using namespace std;
const int N = 607;
int n;
bool vis[N][N], f[N][N]; 
int cnt[N];
bool ok = false;
bool use[N][N];
int dt[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; 
void DFS (int x, int y) {
	use[x][y] = true;
	L(o, 0, 3) {
		int cx = x + dt[o][0], cy = y + dt[o][1];
		if(vis[cx][cy] && !use[cx][cy]) {
			DFS (cx, cy);
		}
	}
}
void dfs (int x) {
	if (ok) return ;
	if(x == n + 1) {
		L(i, 1, n) 
			L(j, 1, n) 
				use[i][j] = false;
		int nt = 0;
		L(i, 1, n) 
			L(j, 1, n) 
				if(vis[i][j] && !use[i][j])
					DFS (i, j), nt += 1;
		if(nt != n) return ;
		ok = true;
		return ;
	}
	L(i, 1, n - 2) if(cnt[i] < 3)
		L(j, i + 1, n - 1) if(cnt[j] < 3)
			L(k, j + 1, n) if(cnt[k] < 3 && !ok) {
				vis[x][i] = vis[x][j] = vis[x][k] = true, cnt[i] += 1, cnt[j] += 1, cnt[k] += 1;
				dfs (x + 1);
				if(!ok) vis[x][i] = vis[x][j] = vis[x][k] = false, cnt[i] -= 1, cnt[j] -= 1, cnt[k] -= 1;
			}
} 
void solve (int x) {
	L(i, 1, n) cnt[i] = 0;
	memset(vis, 0, sizeof(vis));
	n = x, ok = false;
	dfs (1);
}
int main () {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0); 
	int n;
	cin >> n; 
	solve (6), swap(vis, f);
	int k = 6 + n % 6 ;
	solve (k);
	for (int u = k; u < n; u += 6) {
		L(a, 1, 6) 
			L(b, 1, 6) 
				vis[u + a][u + b] = f[a][b];
	}
	L(i, 1, n) {
		L(j, 1, n) {
			if(vis[i][j]) cout << "#";
			else cout << ".";
		}
		cout << '\n';
	}
	return 0;
}

Submission Info

Submission Time
Task A - Three Cells per Row and Column
User zhoukangyang
Language C++ (GCC 9.2.1)
Score 300
Code Size 1599 Byte
Status AC
Exec Time 18 ms
Memory 4348 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 11 ms 4244 KiB
01-001.txt AC 6 ms 4240 KiB
01-002.txt AC 6 ms 4308 KiB
01-003.txt AC 4 ms 4252 KiB
01-004.txt AC 6 ms 4272 KiB
01-005.txt AC 15 ms 4316 KiB
01-006.txt AC 4 ms 4216 KiB
01-007.txt AC 5 ms 4224 KiB
01-008.txt AC 5 ms 4348 KiB
01-009.txt AC 10 ms 4316 KiB
01-010.txt AC 7 ms 4228 KiB
01-011.txt AC 14 ms 4280 KiB
01-012.txt AC 7 ms 4312 KiB
01-013.txt AC 10 ms 4308 KiB
01-014.txt AC 14 ms 4240 KiB
01-015.txt AC 9 ms 4308 KiB
01-016.txt AC 14 ms 4300 KiB
01-017.txt AC 14 ms 4188 KiB
01-018.txt AC 18 ms 4280 KiB
01-019.txt AC 14 ms 4240 KiB
01-020.txt AC 16 ms 4348 KiB
01-021.txt AC 15 ms 4312 KiB
01-022.txt AC 13 ms 4308 KiB
01-023.txt AC 13 ms 4260 KiB