QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100850 | #1806. Character Grid | ckiseki# | AC ✓ | 3ms | 3276kb | C++20 | 968b | 2023-04-28 13:10:18 | 2023-04-28 13:10:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
char a[13][14];
set<pair<char, char>> s;
bool dfs(int i, int j) {
if (j == 13) {
return dfs(i + 1, 0);
} else if (i == 13) {
return true;
} else {
for (int x = 0; x < 13; ++x) {
a[i][j] = x + (i & 1) * 13 + 'a';
if (i and s.find({a[i - 1][j], a[i][j]}) != s.end())
continue;
if (j and s.find({a[i][j - 1], a[i][j]}) != s.end())
continue;
if (i) s.emplace(a[i - 1][j], a[i][j]);
if (j) s.emplace(a[i][j - 1], a[i][j]);
if (dfs(i, j + 1)) return true;
if (i) s.erase({a[i - 1][j], a[i][j]});
if (j) s.erase({a[i][j - 1], a[i][j]});
}
return false;
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
cout << 13 << '\n';
assert(dfs(0, 0));
for (int i = 0; i < 13; ++i)
cout << a[i] << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3276kb
input:
output:
13 aabacadaeafag nonpnqnrnsntn ahbbcbdbebfbg unuoopoqoroso aibiajbhccdce vnvownwotppqp akbjalbkamcfd xnxoynyoznzpr bmdfchdgcjded touqrpspuptqq clcgefegdheci sqvqsrrsvrtwp ddiehfgffhgga
result:
ok accepted