QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#714751 | #5675. Quotdoku | zeyu# | AC ✓ | 855ms | 3728kb | C++23 | 3.8kb | 2024-11-06 05:26:50 | 2024-11-06 05:26:51 |
Judging History
answer
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pl pair<ll, ll>
#define pi pair<int, int>
#define minpq priority_queue<ll, vector<ll>, greater<ll>>
using namespace std;
#if 1
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '['; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "]";}
void _print() {cerr << endl << flush;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "*["<<__LINE__<<"]\t"<< #x << " = "; _print(x)
#endif
const ll mod = 1e9 + 7;
template<typename T> bool chkmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
ll gcd(ll a, ll b) {if(b == 0){return a;} return gcd(b, a % b);}
int a[9][9];
map<pi, vector<pair<pi, int>>> cons;
bool valid(int i, int j, int v){
if (i == 9) return true;
if (a[i][j] != 0 && a[i][j] != v) return false;
for (pair<pi, int> p : cons[{i, j}]){
int pv = a[p.fi.fi][p.fi.se];
int mul = p.se;
if (mul != 0 && pv != 0){
if (v > pv && v / pv != mul) return false;
if (v < pv && pv / v != mul) return false;
}
}
for (int k = 0; k < 9; k ++) if (k != j && a[i][k] == v) return false;
for (int k = 0; k < 9; k ++) if (k != i && a[k][j] == v) return false;
int si = i / 3 * 3, sj = j / 3 * 3;
for (int k1 = 0; k1 < 3; k1 ++){
for (int k2 = 0; k2 < 3; k2 ++){
if (si + k1 == i && sj + k2 == j) continue;
if (a[si + k1][sj + k2] == v) return false;
}
}
return true;
}
void dfs(int i, int j, int v){
if (i == 9){
for (int x = 0; x < 9; x ++){
for (int y = 0; y < 9; y ++) cout << a[x][y] << ' ';
cout << '\n';
}
exit(0);
}
bool preassigned = false;
if (a[i][j] != 0) preassigned = true;
a[i][j] = v;
int ni, nj;
if (j == 8){
ni = i + 1; nj = 0;
} else{
ni = i; nj = j + 1;
}
for (int nv = 1; nv <= 9; nv ++){
if (valid(ni, nj, nv)){
dfs(ni, nj, nv);
}
}
if (! preassigned) a[i][j] = 0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int k; cin >> k;
for (int x = 0; x < 15; x ++){
if (((x & 1) + x / 5) & 1){
for (int y = 0; y < 9; y ++){
int r1 = x / 5 * 3 + (x % 5) / 2, r2 = r1 + 1;
int mul; cin >> mul;
cons[{r1, y}].push_back({{r2, y}, mul});
cons[{r2, y}].push_back({{r1, y}, mul});
}
} else{
for (int y = 0; y < 3; y ++){
for (int z = 0; z < 2; z ++){
int r = x / 5 * 3 + (x % 5) / 2, c1 = y * 3 + z, c2 = y * 3 + z + 1;
int mul; cin >> mul;
cons[{r, c1}].push_back({{r, c2}, mul});
cons[{r, c2}].push_back({{r, c1}, mul});
}
}
}
}
// for (auto p : cons){
// cout << p.fi.fi << ' ' << p.fi.se << '\n';
// for (pair<pi, int> x : cons[p.fi]){
// cout << x.fi.fi << ' ' << x.fi.se << ' ' << x.se << '\n';
// }
// }
for (int x = 0; x < k; x ++){
int i, j, v; cin >> i >> j >> v;
i --; j --;
a[i][j] = v;
}
for (int v = 1; v <= 9; v ++){
if (valid(0, 0, v)) dfs(0, 0, v);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 855ms
memory: 3604kb
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: 23ms
memory: 3596kb
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 2 0 0 2 1 4 2 1 0 0 0 9 1 1 1 1 0 0 3 1 1 6 7 6 9 9 4 3 7
output:
5 2 9 1 3 7 8 6 4 4 6 1 8 5 2 7 9 3 7 8 3 4 6 9 5 1 2 3 5 7 6 9 1 4 2 8 8 9 2 3 4 5 6 7 1 6 1 4 7 2 8 3 5 9 1 4 5 9 7 3 2 8 6 2 3 8 5 1 6 9 4 7 9 7 6 2 8 4 1 3 5
result:
ok 9 lines
Test #3:
score: 0
Accepted
time: 581ms
memory: 3664kb
input:
4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