QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#220464 | #5202. Dominoes | suibian_xiaozhao | WA | 1ms | 3476kb | C++20 | 2.3kb | 2023-10-20 13:54:38 | 2023-10-20 13:54:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using vint = vector<int>;
constexpr int N = 1e3 + 5;
int n, k, p[N], fa[N];
void solve(vector<vint> dat, int ff) {
int m = dat[0].size();
if(m == 1) return fa[dat[0][0]] = ff, void();
vector<vint> pos(k, vint(n + 1));
for(int i = 0; i < k; i++)
for(int j = 0; j < m; j++)
pos[i][dat[i][j]] = j;
auto split = [&](int u, vint arr, vint &a, vint &b) {
bool find = 0;
for(int it : arr)
if(it == u) find = 1;
else if(find) b.push_back(it);
else a.push_back(it);
};
auto check = [&](int u) {
int x = -1, y = -1;
for(int i = 0, sz; i < k; i++) {
sz = pos[i][u];
if(!sz) return false;
if(x == -1 || x == sz) x = sz;
else if(y == -1 || y == sz) y = sz;
else return false;
sz = m - 1 - sz;
if(!sz) return false;
if(x == -1 || x == sz) x = sz;
else if(y == -1 || y == sz) y = sz;
else return false;
}
vint c, d;
for(auto &arr : dat) {
vint a, b;
split(u, arr, a, b);
sort(a.begin(), a.end());
sort(b.begin(), b.end());
if(c.empty() || c == a) c = a;
else if(d.empty() || d == a) d = a;
else return false;
if(c.empty() || c == b) c = b;
else if(d.empty() || d == b) d = b;
else return false;
}
return true;
};
for(int id : dat[0]) {
if(!check(id)) continue;
fa[id] = ff;
int beg = dat[0][0];
vector<vint> ldat, rdat;
for(auto arr : dat) {
vint a, b;
split(id, arr, a, b);
if(find(a.begin(), a.end(), beg) == a.end()) a.swap(b);
ldat.push_back(a), rdat.push_back(b);
}
solve(ldat, id), solve(rdat, id);
}
}
int main() {
cin >> n >> k;
vector<vector<int>> dat;
for(int _ = 1; _ <= k; _++) {
vector<int> arr(n, 0);
for(int i = 0; i < n; i++) cin >> arr[i];
dat.push_back(arr);
}
solve(dat, -1);
for(int i = 1; i <= n; i++) cout << fa[i] << (i == n ? '\n' : ' ');
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3476kb
input:
3 6 ...#.. ...... #...##
output:
0 0 0
result:
wrong answer 1st numbers differ - expected: '52', found: '0'