QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#711230 | #5675. Quotdoku | dbaumg | AC ✓ | 195ms | 3844kb | C++20 | 2.7kb | 2024-11-05 06:58:05 | 2024-11-05 06:58:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define OK(r, c) (r >= 0 && c >= 0 && r < 9 && c < 9)
#define SQ(r, c) ((r) / 3 + 3 * ((c) / 3))
int gr[9][9], mk[3][9], q[9][9][9][9];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool lV(int r, int c) {
for (int i = 0; i < 4; i++) {
int x = r + dx[i];
int y = c + dy[i];
if (!OK(x, y) || gr[x][y] == 0 || q[r][c][x][y] == 0)
continue;
if (q[r][c][x][y] != max(gr[r][c], gr[x][y]) / min(gr[r][c], gr[x][y]))
return false;
}
return true;
}
void add(int r, int c, int x, int s) {
gr[r][c] = s > 0 ? x : 0;
mk[0][r] ^= 1 << (x - 1);
mk[1][c] ^= 1 << (x - 1);
mk[2][SQ(r, c)] ^= 1 << (x - 1);
}
bool bT(int r, int c) {
if (r == 9)
return true;
int rI = r + (c + 1) / 9;
int cI = (c + 1) % 9;
if (gr[r][c])
return lV(r, c) && bT(rI, cI);
int mask = mk[0][r] & mk[1][c] & mk[2][SQ(r, c)];
for (int x = 1; mask >> (x - 1); x++) {
if ((mask >> (x - 1)) & 1) {
add(r, c, x, 1);
if (lV(r, c) && bT(rI, cI))
return true;
add(r, c, x, -1);
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int k;
cin >> k;
queue<pair<int, int>> q1, q2;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
if (j % 3 != 2) q1.push({i, j});
if (i % 3 != 2) q2.push({i, j});
}
}
for (int i = 0; i < 3; i++) {
vector<int> v = {6, 9, 6, 9, 6};
for (int t : v) {
for (int j = 0; j < t; j++) {
if (t == 6) {
auto p = q1.front();
q1.pop();
cin >> q[p.first][p.second][p.first][p.second + 1];
q[p.first][p.second + 1][p.first][p.second] = q[p.first][p.second][p.first][p.second + 1];
} else {
auto p = q2.front();
q2.pop();
cin >> q[p.first][p.second][p.first + 1][p.second];
q[p.first + 1][p.second][p.first][p.second] = q[p.first][p.second][p.first + 1][p.second];
}
}
}
}
for (int i = 0; i < 3; i++)
for (int j = 0; j < 9; j++)
mk[i][j] = 511;
while (k--) {
int r, c, x;
cin >> r >> c >> x;
r -= 1;
c -= 1;
add(r, c, x, 1);
}
bT(0, 0);
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++)
cout << gr[i][j] << " ";
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 195ms
memory: 3504kb
input:
0 1 1 0 0 1 2 1 1 1 0 0 0 6 1 2 1 1 0 0 7 3 2 6 1 0 0 0 3 1 2 2 7 0 0 3 1 0 0 1 4 0 0 0 0 0 3 3 2 0 0 0 0 0 1 1 0 0 0 0 0 1 6 1 0 0 0 0 0 7 5 0 0 1 3 0 0 1 1 1 2 2 0 0 0 4 1 6 2 1 0 0 2 4 8 1 1 0 0 0 3 1 9 4 1 0 0 2 3
output:
3 5 9 2 7 1 6 8 4 4 6 8 5 3 9 1 7 2 2 1 7 4 8 6 3 9 5 5 9 1 3 2 8 4 6 7 7 2 3 9 6 4 5 1 8 6 8 4 7 1 5 9 2 3 9 7 2 1 4 3 8 5 6 8 3 5 6 9 7 2 4 1 1 4 6 8 5 2 7 3 9
result:
ok 9 lines
Test #2:
score: 0
Accepted
time: 5ms
memory: 3568kb
input:
3 2 4 0 0 1 1 1 3 9 0 0 0 1 1 1 1 6 0 0 1 3 1 1 3 0 0 0 1 9 1 1 2 0 0 5 2 0 0 1 9 0 0 0 0 0 2 2 5 0 0 0 0 0 1 1 0 0 0 0 0 2 2 1 0 0 0 0 0 3 4 0 0 4 1 0 0 4 1 2 1 1 0 0 0 4 2 1 1 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 7 6 5 4 2 3 8 5 6 3 8 2 7 9 1 4 1 7 9 4 6 8 3 5 2 4 3 6 5 9 2 7 8 1 2 5 8 7 3 1 4 6 9
result:
ok 9 lines
Test #5:
score: 0
Accepted
time: 6ms
memory: 3844kb
input:
2 9 1 0 0 1 1 7 3 1 0 0 0 4 1 3 2 1 0 0 9 4 1 2 2 0 0 0 8 1 1 1 3 0 0 1 1 0 0 2 2 0 0 0 0 0 2 1 2 0 0 0 0 0 1 1 0 0 0 0 0 6 1 4 0 0 0 0 0 7 3 0 0 9 6 0 0 1 1 4 5 2 0 0 0 2 2 1 2 1 0 0 1 1 4 1 1 0 0 0 1 4 9 1 1 0 0 3 2 5 2 8 4 8 7
output:
1 9 8 2 3 5 4 6 7 7 3 5 8 4 6 1 9 2 4 6 2 9 1 7 8 5 3 5 2 1 3 8 4 9 7 6 3 8 7 6 5 9 2 1 4 6 4 9 1 7 2 5 3 8 9 1 6 7 2 8 3 4 5 2 5 3 4 6 1 7 8 9 8 7 4 5 9 3 6 2 1
result:
ok 9 lines
Test #6:
score: 0
Accepted
time: 2ms
memory: 3832kb
input:
3 2 2 0 0 1 2 7 1 1 0 0 0 1 1 4 5 1 0 0 1 2 4 1 4 0 0 0 6 1 2 1 3 0 0 7 2 0 0 3 6 0 0 0 0 0 1 7 1 0 0 0 0 0 3 1 0 0 0 0 0 4 1 2 0 0 0 0 0 1 1 0 0 8 4 0 0 1 3 4 9 1 0 0 0 1 2 2 4 1 0 0 1 1 1 1 1 0 0 0 1 3 4 2 1 0 0 4 2 3 4 8 5 6 4 4 2 2
output:
7 3 8 4 6 1 9 5 2 1 5 9 7 3 2 6 4 8 4 6 2 8 9 5 1 7 3 9 2 7 3 1 6 4 8 5 5 8 1 2 7 4 3 9 6 6 4 3 9 5 8 2 1 7 8 1 4 6 2 7 5 3 9 2 9 5 1 8 3 7 6 4 3 7 6 5 4 9 8 2 1
result:
ok 9 lines
Test #7:
score: 0
Accepted
time: 17ms
memory: 3612kb
input:
2 1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