QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#110841#6309. AqreetheningWA 2ms3384kbC++172.4kb2023-06-04 04:55:442023-06-04 04:55:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-04 04:55:46]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3384kb
  • [2023-06-04 04:55:44]
  • 提交

answer

#include "bits/stdc++.h"
#include <algorithm>
#include <array>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

constexpr int dx[4] = {0, -1, 1, 0};
constexpr int dy[4] = {-1, 0, 0, 1};

void solve() {
	int n, m;
	cin >> n >> m;

	if (n == 3 && m % 4 == 3) {
		int ans = 9 * (m / 4) + 8;
		cout << ans << "\n";
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int i2 = i % 4;
				int j2 = j % 4;
				int cell = !((i2 == 1 && j2 == 1) || (j2 == 3 && i2 != 1));
				cout << cell << " \n"[j == m - 1];
			}
		}
		return;
	}
	if (m == 3 && n % 4 == 3) {
		int ans = 9 * (n / 4) + 8;
		cout << ans << "\n";
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int i2 = i % 4;
				int j2 = j % 4;
				int cell = !((i2 == 1 && j2 == 1) || (i2 == 3 && j2 != 1));
				cout << cell << " \n"[j == m - 1];
			}
		}
		return;
	}

	vector<vector<bool>> board(n, vector<bool>(m));
	vector<int> per(4);
	int max_ans = 0;
	vector<int> ans_per;
	for (int i = 0; i < 4; i++) per[i] = i;
	do {
		int cnt1 = 0;
		pii st = {0, 0};
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int i2 = i % 4;
				int j2 = j % 4;
				board[i][j] = (per[i2] != j2);
				cnt1 += board[i][j];
				if (board[i][j]) st = {i, j};
			}
		}
		vector<vector<bool>> vis(n, vector<bool>(m));
		auto can_vis = [&](int x, int y) {
			if (x >= 0 && x <= n - 1 && y >= 0 && y <= m - 1) {
				if (!board[x][y]) return false;
				return !vis[x][y];
			}
			return false;
		};
		function<void(pii, int&)> dfs = [&](pii cur, int& cnt) {
			vis[cur.first][cur.second] = 1;
			++cnt;
			for (int i = 0; i < 4; i++) {
				int nxtx = cur.first + dx[i];
				int nxty = cur.second + dy[i];
				if (can_vis(nxtx, nxty)) {
					dfs({nxtx, nxty}, cnt);
				}		
			}
		};
		int actual_cnt1 = 0;
		dfs(st, actual_cnt1);
		// cout << actual_cnt1 << " " << cnt1 << " " << max_ans << endl;
		if (actual_cnt1 == cnt1) {
			if (cnt1 > max_ans) {
				max_ans = cnt1;
				ans_per = per;
			}
		}
	} while (next_permutation(begin(per), end(per)));
	cout << max_ans << "\n";
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int i2 = i % 4;
			int j2 = j % 4;
			int cell = (ans_per[i2] != j2);
			cout << cell << " \n"[j == m - 1];
		}
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3384kb

input:

3
2 2
3 4
3 8

output:

4
1 1
1 1
9
0 1 1 1
1 0 1 1
1 1 1 0
18
0 1 1 1 0 1 1 1
1 0 1 1 1 0 1 1
1 1 1 0 1 1 1 0

result:

wrong answer Length must be equal to m (test case 1)