QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#766825#6534. Peg SolitairediguoAC ✓1ms3764kbC++202.6kb2024-11-20 18:45:282024-11-20 18:45:30

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 18:45:30]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3764kb
  • [2024-11-20 18:45:28]
  • 提交

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 <= m && 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

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: 0ms
memory: 3592kb

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: 3532kb

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: 3496kb

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: 0ms
memory: 3764kb

input:

20
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5 2
6 6 6
2 4
3 4
3 3
4 3
4 2
5...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2

result:

ok 20 numbers