QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#766819 | #6534. Peg Solitaire | diguo | WA | 1ms | 3840kb | C++20 | 2.6kb | 2024-11-20 18:44:11 | 2024-11-20 18:44:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x, y) x.begin() + y, x.end()
#define mkp make_pair
#define pii pair<int, int>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pll pair<long long, long long>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(name, base, limit) for(int name = base; name <= limit; ++name)
#define per(name, base, limit) for(int name = base; name >= limit; --name)
#define lowbit(x) ((x) & -(x))
#define ls(p) ((p) << 1)
#define rs(p) ((p) << 1 | 1)
const int INF = 0x3f3f3f3f;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
inline long long read()
{
long long x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void solve()
{
int n = read(), m = read(), k = read();
map<pii, bool> mp;
rep(i, 1, k)
{
int u = read(), v = read();
mp[{u, v}] = 1;
}
int ans = k;
function<void(map<pii, bool>, int)> dfs = [&](map<pii, bool> mp, int dep) -> void
{
ans = min(ans, k - dep);
for (auto [t, _]: mp)
{
auto [x, y] = t;
if (x - 2 >= 1 && mp.find({x - 1, y}) != mp.end() && mp.find({x - 2, y}) == mp.end())
{
auto q(mp);
q.erase({x - 1, y});
q.erase({x, y});
q[{x - 2, y}] = 1;
dfs(q, dep + 1);
}
if (x + 2 <= n && mp.find({x + 1, y}) != mp.end() && mp.find({x + 2, y}) == mp.end())
{
auto q(mp);
q.erase({x + 1, y});
q.erase({x, y});
q[{x + 2, y}] = 1;
dfs(q, dep + 1);
}
if (y - 2 >= 1 && mp.find({x, y - 1}) != mp.end() && mp.find({x, y - 2}) == mp.end())
{
auto q(mp);
q.erase({x, y - 1});
q.erase({x, y});
q[{x, y - 2}] = 1;
dfs(q, dep + 1);
}
if (y + 2 <= n && mp.find({x, y + 1}) != mp.end() && mp.find({x, y + 2}) == mp.end())
{
auto q(mp);
q.erase({x, y + 1});
q.erase({x, y});
q[{x, y + 2}] = 1;
dfs(q, dep + 1);
}
}
};
dfs(mp, 0);
cout << ans;
}
int main()
{
int t = read();
while (t--)
{
solve();
if (t) putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3840kb
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: -100
Wrong Answer
time: 1ms
memory: 3544kb
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 4 3 2 1 3 4 2 1 3 1 2 2
result:
wrong answer 9th numbers differ - expected: '3', found: '4'