QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#240103 | #6534. Peg Solitaire | zlt | AC ✓ | 1ms | 4080kb | C++14 | 3.0kb | 2023-11-05 11:55:51 | 2023-11-05 11:55:51 |
Judging History
answer
// Problem: P9700 [GDCPC2023] Peg Solitaire
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P9700
// Memory Limit: 1 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))
using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;
int n, m, K;
bool vis[9][9];
void solve() {
scanf("%d%d%d", &n, &m, &K);
vector<pii> vc;
while (K--) {
int x, y;
scanf("%d%d", &x, &y);
vc.pb(x, y);
}
queue< vector<pii> > q;
q.push(vc);
set< vector<pii> > S;
S.insert(vc);
int ans = 99;
while (q.size()) {
vector<pii> u = q.front();
q.pop();
mems(vis, 0);
ans = min(ans, (int)u.size());
for (pii p : u) {
vis[p.fst][p.scd] = 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (i >= 3 && vis[i][j] && vis[i - 1][j] && !vis[i - 2][j]) {
vis[i][j] ^= 1;
vis[i - 1][j] ^= 1;
vis[i - 2][j] ^= 1;
vector<pii> v;
for (int x = 1; x <= n; ++x) {
for (int y = 1; y <= m; ++y) {
if (vis[x][y]) {
v.pb(x, y);
}
}
}
if (S.find(v) == S.end()) {
S.insert(v);
q.push(v);
}
vis[i][j] ^= 1;
vis[i - 1][j] ^= 1;
vis[i - 2][j] ^= 1;
}
if (i <= n - 2 && vis[i][j] && vis[i + 1][j] && !vis[i + 2][j]) {
vis[i][j] ^= 1;
vis[i + 1][j] ^= 1;
vis[i + 2][j] ^= 1;
vector<pii> v;
for (int x = 1; x <= n; ++x) {
for (int y = 1; y <= m; ++y) {
if (vis[x][y]) {
v.pb(x, y);
}
}
}
if (S.find(v) == S.end()) {
S.insert(v);
q.push(v);
}
vis[i][j] ^= 1;
vis[i + 1][j] ^= 1;
vis[i + 2][j] ^= 1;
}
if (j >= 3 && vis[i][j] && vis[i][j - 1] && !vis[i][j - 2]) {
vis[i][j] ^= 1;
vis[i][j - 1] ^= 1;
vis[i][j - 2] ^= 1;
vector<pii> v;
for (int x = 1; x <= n; ++x) {
for (int y = 1; y <= m; ++y) {
if (vis[x][y]) {
v.pb(x, y);
}
}
}
if (S.find(v) == S.end()) {
S.insert(v);
q.push(v);
}
vis[i][j] ^= 1;
vis[i][j - 1] ^= 1;
vis[i][j - 2] ^= 1;
}
if (j <= m - 2 && vis[i][j] && vis[i][j + 1] && !vis[i][j + 2]) {
vis[i][j] ^= 1;
vis[i][j + 1] ^= 1;
vis[i][j + 2] ^= 1;
vector<pii> v;
for (int x = 1; x <= n; ++x) {
for (int y = 1; y <= m; ++y) {
if (vis[x][y]) {
v.pb(x, y);
}
}
}
if (S.find(v) == S.end()) {
S.insert(v);
q.push(v);
}
vis[i][j] ^= 1;
vis[i][j + 1] ^= 1;
vis[i][j + 2] ^= 1;
}
}
}
}
printf("%d\n", ans);
}
int main() {
int T = 1;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3780kb
input:
3 3 4 5 2 2 1 2 1 4 3 4 1 1 1 3 3 1 1 1 2 1 3 2 1 1 2 1
output:
2 3 1
result:
ok 3 number(s): "2 3 1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 4040kb
input:
20 2 1 2 1 1 2 1 5 1 3 3 1 2 1 4 1 3 3 6 1 2 2 2 1 1 2 3 3 1 3 2 4 4 4 2 3 3 1 3 2 1 2 1 1 1 1 1 5 2 6 3 2 4 1 2 1 5 2 2 2 5 1 1 3 1 1 2 1 5 1 1 5 4 6 5 4 6 4 4 2 3 4 3 1 6 6 6 3 2 4 1 3 2 1 2 2 2 2 1 1 1 5 3 4 2 2 5 1 4 3 3 2 6 5 6 5 5 6 5 2 4 2 1 3 4 1 4 2 6 5 1 6 2 1 1 4 2 3 1 3 3 5 6 2 1 3 3 1 5...
output:
2 2 3 1 1 2 1 1 3 3 2 1 3 3 2 1 3 1 2 2
result:
ok 20 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
20 2 1 1 2 1 4 3 2 4 3 1 1 6 4 6 4 3 5 4 4 2 3 2 3 4 2 3 3 6 4 3 1 2 6 2 4 3 5 6 6 6 3 3 3 6 4 2 3 2 4 1 1 4 3 3 1 1 1 2 3 2 2 2 2 1 3 2 2 1 2 2 2 3 4 5 2 1 3 4 3 1 2 2 3 2 2 5 5 1 5 2 3 2 5 1 4 2 2 5 6 6 5 1 2 2 1 4 5 3 4 4 1 1 2 3 4 1 1 1 2 2 2 2 1 2 3 4 1 1 2 1 1 2 2 2 6 3 6 4 2 4 1 1 3 6 2 3 3 2...
output:
1 2 2 4 4 1 1 1 2 2 6 2 2 3 4 1 1 1 3 2
result:
ok 20 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3852kb
input:
20 1 5 3 1 2 1 3 1 1 5 6 6 5 4 2 4 4 4 4 6 2 5 3 3 5 2 4 4 1 3 1 4 2 5 2 6 3 6 3 1 5 2 3 2 4 1 4 3 3 3 5 3 5 5 2 2 2 3 1 4 3 3 2 6 1 4 3 1 5 1 1 1 4 1 3 5 6 1 1 2 1 3 4 1 5 2 2 3 3 2 5 2 2 5 2 1 5 4 6 1 3 4 3 2 2 1 2 3 3 2 3 2 3 3 2 3 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 6 4 5 2 1 6 2 3 2 1 2 4 2 5...
output:
2 1 2 2 1 2 3 2 2 3 1 1 1 3 2 2 2 3 2 1
result:
ok 20 numbers
Test #5:
score: 0
Accepted
time: 1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