QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#112216 | #5675. Quotdoku | PetroTarnavskyi# | AC ✓ | 207ms | 3568kb | C++17 | 2.2kb | 2023-06-10 17:56:45 | 2023-06-10 17:56:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))
int row[9][9], col[9][9], sq[9][9];
int pr[9][9];
int pc[9][9];
int ans[9][9];
void readRow(int r)
{
int a, b;
cin >> a >> b;
pr[r][1] = a;
pr[r][2] = b;
cin >> a >> b;
pr[r][4] = a;
pr[r][5] = b;
cin >> a >> b;
pr[r][7] = a;
pr[r][8] = b;
}
void readCol(int c)
{
FOR (i, 0, 9)
{
int a;
cin >> a;
pc[c][i] = a;
}
}
void solve(int x, int y)
{
if (x == 9)
{
FOR (i, 0, 9)
{
FOR (j, 0, 9) cout << ans[i][j] + 1 << ' ';
cout << '\n';
}
exit(0);
}
if (y == 9)
{
solve(x + 1, 0);
return;
}
if (ans[x][y] != -1)
{
solve(x, y + 1);
return;
}
int idx = x / 3 * 3 + y / 3;
FOR (i, 0, 9)
{
if (row[x][i] || col[y][i] || sq[idx][i]) continue;
if (pr[x][y])
{
assert(y > 0);
int mx = max(i, ans[x][y - 1]) + 1;
int mn = min(i, ans[x][y - 1]) + 1;
if (mx / mn != pr[x][y]) continue;
}
if (pc[x][y])
{
assert((x % 3) > 0);
int mx = max(i, ans[x - 1][y]) + 1;
int mn = min(i, ans[x - 1][y]) + 1;
if (mx / mn != pc[x][y]) continue;
}
ans[x][y] = i;
row[x][i] = 1;
col[y][i] = 1;
sq[idx][i] = 1;
solve(x, y + 1);
ans[x][y] = -1;
row[x][i] = 0;
col[y][i] = 0;
sq[idx][i] = 0;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
FOR (i, 0, 9)
FOR (j, 0, 9)
ans[i][j] = -1;
int k;
cin >> k;
FOR (i, 0, 3)
{
readRow(i * 3 + 0);
readCol(i * 3 + 1);
readRow(i * 3 + 1);
readCol(i * 3 + 2);
readRow(i * 3 + 2);
}
FOR (i, 0, k)
{
int x, y, z;
cin >> x >> y >> z;
x--, y--, z--;
ans[x][y] = z;
row[x][z] = 1;
col[y][z] = 1;
sq[(x / 3) * 3 + y / 3][z] = 1;
}
solve(0, 0);
}
詳細信息
Test #1:
score: 100
Accepted
time: 207ms
memory: 3412kb
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: 8ms
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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
ok 9 lines
Test #7:
score: 0
Accepted
time: 23ms
memory: 3392kb
input:
2 1 6 0 0 1 3 1 1 8 0 0 0 2 2 1 2 2 0 0 3 1 1 1 4 0 0 0 3 7 1 1 1 0 0 6 8 0 0 4 4 0 0 0 0 0 2 3 1 0 0 0 0 0 2 1 0 0 0 0 0 1 1 7 0 0 0 0 0 1 5 0 0 4 2 0 0 1 1 1 9 1 0 0 0 1 2 1 3 5 0 0 4 2 2 8 1 0 0 0 2 4 4 1 1 0 0 3 9 1 4 2 3 4 7
output:
7 6 1 2 8 5 4 3 9 9 4 8 6 1 3 2 7 5 5 3 2 7 9 4 6 1 8 1 7 6 8 2 9 5 4 3 4 5 9 3 6 7 1 8 2 8 2 3 4 5 1 9 6 7 2 9 4 1 3 8 7 5 6 3 1 5 9 7 6 8 2 4 6 8 7 5 4 2 3 9 1
result:
ok 9 lines
Test #8:
score: 0
Accepted
time: 7ms
memory: 3344kb
input:
4 1 4 0 0 2 1 1 8 2 0 0 0 1 1 1 5 4 0 0 4 3 1 3 1 0 0 0 1 2 6 2 2 0 0 2 4 0 0 7 9 0 0 0 0 0 3 5 2 0 0 0 0 0 2 1 0 0 0 0 0 4 1 1 0 0 0 0 0 2 2 0 0 1 1 0 0 1 1 3 2 1 0 0 0 1 5 2 2 2 0 0 6 7 1 1 8 0 0 0 3 8 1 1 5 0 0 4 1 2 4 9 7 1 6 7 5 8 9 4 6
output:
9 8 2 4 6 1 7 3 5 5 1 4 9 7 3 8 2 6 7 3 6 5 2 8 9 4 1 8 2 3 7 1 9 5 6 4 1 6 9 2 5 4 3 7 8 4 7 5 8 3 6 1 9 2 6 9 7 1 8 2 4 5 3 2 4 8 3 9 5 6 1 7 3 5 1 6 4 7 2 8 9
result:
ok 9 lines
Test #9:
score: 0
Accepted
time: 142ms
memory: 3560kb
input:
1 2 1 0 0 1 5 1 3 3 0 0 0 2 1 3 5 6 0 0 1 2 1 9 1 0 0 0 4 1 2 2 1 0 0 3 1 0 0 4 1 0 0 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