QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#106111 | #6305. Chinese Checker | zzpcd | WA | 48ms | 3848kb | C++17 | 5.7kb | 2023-05-16 17:11:56 | 2023-05-16 17:11:58 |
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) cerr << pos[z].first << " " << pos[z].second << "\n";
if(z == -1 || pos[z].second < min(y, oy) || pos[z].second > max(y, oy)) {
// 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: 3584kb
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: 48ms
memory: 3848kb
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:
174 360 211 464 333 227 144 38 328 84 1 138 99 65 25 136 347 293 9 205 91 181 261 16 97 230 298 395 168 81 214 272 25 7 104 180 410 260 50 158 258 47 10 156 78 173 30 142 332 119 197 283 0 104 114 54 21 5 59 157 167 25 395 160 203 3 50 0 248 106 97 376 0 334 75 99 75 347 66 25 466 333 6 187 86 2 166...
result:
wrong answer 1st numbers differ - expected: '190', found: '174'