QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106109 | #6305. Chinese Checker | zzpcd | WA | 30ms | 3820kb | C++17 | 5.6kb | 2023-05-16 16:51:35 | 2023-05-16 16:51:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define MN 125
typedef pair<int, int> P;
const int L[18] = {0, 13, 12, 11, 10, 1, 2, 3, 4, 5, 4, 3, 2, 1, 10, 11, 12, 13};
const int R[18] = {0, 13, 14, 15, 16, 25, 24, 23, 22, 21, 22, 23, 24, 25, 16, 15, 14, 13};
const int gx[] = {-1, 1, -1, 1, 0, 0};
const int gy[] = {-1, 1, 1, -1, 2, -2};
map <vector<int>, bool> ans;
int N;
P pos[MN];
bool vis[MN], occ[MN];
int ha[400][400];
int nxt[33][20][6];
// int prea[33][20], sufa[33][20];
// int preb[33][20], sufb[33][20];
int mia, mib, maa, mab;
int n, poi[MN];
queue<int> que;
void init() {
mia = 10000, mib = 10000;
maa = -10000, mab = -10000;
for(int i = 1; i <= 17; i++) {
for(int x = L[i]; x <= R[i]; x += 2) {
pos[++N] = P(i, x);
ha[i][x] = N;
mia = min(mia, i - x);
maa = max(maa, i - x);
mib = min(mib, i + x);
mab = max(mab, i + x);
}
}
// cerr << mia << " " << maa << "\n";
// cerr << mib << " " << mab << "\n";
}
void build(int x, int id) {
vector<int> tmp(n);
int N = 0;
for(int i = 1; i <= n; i++) {
if(i == id) continue;
if(x && x < poi[i]) tmp[N++] = x, x = 0;
tmp[N++] = poi[i];
}
if(x) tmp[N++] = x;
ans[tmp] = 1;
}
void move(int& x, int& y, int dir) {
x = x + gx[dir], y = y + gy[dir];
return;
}
void solve() {
ans.clear();
scanf("%d", &n);
memset(occ, 0, sizeof occ);
for(int i = 1; i <= n; i++) {
P tmp;
auto& [x, y] = tmp;
scanf("%d%d", &x, &y);
y = (y - 1 << 1) + L[x];
// cerr << x << " " << y << " z\n";
poi[i] = ha[x][y];
occ[poi[i]] = 1;
}
sort(poi + 1, poi + 1 + n);
for(int i = 1; i <= n; i++) {
memset(vis, 0, sizeof vis);
for(int j = 1; j <= 17; j++) {
for(int k = R[j], lst = -1; k >= L[j]; k -= 2) {
if(ha[j][k] != poi[i] && occ[ha[j][k]]) lst = ha[j][k];
nxt[j][k][4] = lst;
}
for(int k = L[j], lst = -1; k <= R[j]; k += 2) {
if(ha[j][k] != poi[i] && occ[ha[j][k]]) lst = ha[j][k];
nxt[j][k][5] = lst;
}
}
for(int j = mia, k, y; j <= maa; j += 2) {
k = 1;
// cerr << k << " " << k - j << " " << j << " zz\n";
while(k - j < 0 || !ha[k][k - j]) ++k;
// cerr << k << " " << k - j << " " << j << "\n";
for(int lst = -1; ha[k][k - j]; k++){
// cerr << k << " " << k - j << " " << j << " x\n";
if(ha[k][k - j] != poi[i] && occ[ha[k][k - j]]) lst = ha[k][k - j];
nxt[k][k - j][0] = lst;
// cerr << "yyy\n";
}
k = 80;
// cerr << k << " " << k - j << " " << j << " y\n";
while(!ha[k][k - j]) --k;
// cerr << k << " " << k - j << " " << j << "\n";
for(int lst = -1; ha[k][k - j]; k--){
if(ha[k][k - j] != poi[i] && occ[ha[k][k - j]]) lst = ha[k][k - j];
nxt[k][k - j][1] = lst;
}
}
// std::cerr << "xxxxx" << endl;
for(int j = mib, k, y; j <= mab; j += 2) {
k = 1;
// cerr << k << " " << j - k << " " << j << "\n";
while(!ha[k][j - k]) ++k;
// cerr << k << " " << j - k << " " << j << "\n";
for(int lst = -1; ha[k][j - k]; k++){
if(ha[k][j - k] != poi[i] && occ[ha[k][j - k]]) lst = ha[k][j - k];
nxt[k][j - k][2] = lst;
}
k = 80;
while(j - k < 0 || !ha[k][j - k]) --k;
// cerr << k << " " << j - k << " " << j << "\n";
for(int lst = -1; ha[k][j - k]; k--){
if(ha[k][j - k] != poi[i] && occ[ha[k][j - k]]) lst = ha[k][j - k];
nxt[k][j - k][3] = lst;
}
}
vis[poi[i]] = 1;
que.push(poi[i]);
// cerr << poi[i] << "\n";
// std::cerr << "xxxx" << endl;
while(!que.empty()) {
int v = que.front();
auto [x, y] = pos[v];
que.pop();
build(v, i);
// cerr << i << " : \n";
// cerr << x << " " << y << "\n";
for(int u = 0; u < 6; u++) {
int nx = x, ny = y;
move(nx, ny, u);
// cerr << x << " " << y << " " << nx << " " << ny << " " << u << " u\n";
// cerr << nxt[nx][ny][u] << "\n";
if(ny < 1 || !ha[nx][ny] || nxt[nx][ny][u] == -1) continue;
// cerr << "zzz\n";
auto [mx, my] = pos[nxt[nx][ny][u]];
int ox = 2 * mx - x, oy = 2 * my - y;
// cerr << mx << " " << my << "\n";
if(ox < 1 || oy < 1 || !ha[ox][oy]) continue;
move(mx, my, u);
int z = nxt[mx][my][u];
// cerr << ox << " " << oy << " zz\n";
// cerr << z << "\n";
if(z == -1 || pos[z].first < min(x, ox) || pos[z].first > max(x, ox)) {
// cerr << " ????\n";
if(!vis[ha[ox][oy]]) {
vis[ha[ox][oy]] = 1;
que.push(ha[ox][oy]);
}
}
}
// cerr << "xzzz\n";
}
}
printf("%d\n", ans.size() - 1);
}
int main() {
int TT = 1;
init();
scanf("%d", &TT);
while(TT--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3588kb
input:
5 1 1 1 2 1 1 2 1 2 9 4 9 6 10 1 1 2 1 2 2 3 1 3 2 3 3 4 1 4 2 4 3 4 4 10 1 1 2 1 2 2 5 7 3 2 3 3 4 1 4 2 4 3 4 4
output:
0 1 2 6 13
result:
ok 5 number(s): "0 1 2 6 13"
Test #2:
score: -100
Wrong Answer
time: 30ms
memory: 3820kb
input:
100 81 1 1 16 1 11 4 13 8 12 3 12 12 11 1 4 2 9 5 8 10 5 5 9 7 3 2 14 1 7 11 13 7 10 2 8 3 9 8 10 6 12 10 6 7 11 2 7 3 13 12 8 6 17 1 10 5 5 12 13 9 13 1 9 4 5 10 11 8 13 4 5 4 9 1 7 8 5 6 13 13 5 1 9 3 8 8 8 5 13 2 13 5 11 3 9 2 6 4 3 3 8 2 13 11 8 7 5 7 6 10 11 9 10 3 11 10 6 3 7 1 4 4 15 2 7 2 3 ...
output:
114 151 167 161 188 154 95 28 222 59 1 95 69 59 21 94 202 193 6 97 68 107 207 12 70 153 168 135 95 62 123 203 19 7 71 125 229 150 32 126 126 34 7 105 42 112 22 102 185 84 144 148 0 64 97 38 14 3 46 92 119 20 201 79 110 2 41 0 203 79 64 237 0 147 56 59 58 240 48 22 259 160 5 130 60 2 125 25 30 192 16...
result:
wrong answer 1st numbers differ - expected: '190', found: '114'