QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#702033#6534. Peg Solitairelibantian#AC ✓10ms4024kbC++232.0kb2024-11-02 15:08:412024-11-02 15:08:43

Judging History

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

  • [2024-11-02 15:08:43]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:4024kb
  • [2024-11-02 15:08:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define all(_a) _a.begin(), _a.end()
map<pii,int>mp;
map<map<pii,int>,bool>st;
int res=INF;
int n,m,k;
void dfs(map<pii,int>mp){
    if(st[mp])return ;
    st[mp]=true;
    int cnt=0;
    for(int x=1;x<=n;x++){
        for(int y=1;y<=m;y++){
            if(mp[{x,y}]){
                cnt++;
                if((x+2<=n)&&mp[{x+1,y}]&&!mp[{x+2,y}]){
                    auto ne=mp;
                    ne[{x,y}]=0;
                    ne[{x+1,y}]=0;
                    ne[{x+2,y}]=1;
                    dfs(ne);
                     
                }
                if((x-2)>=1&&mp[{x-1,y}]&&!mp[{x-2,y}]){
                    auto ne=mp;
                    ne[{x,y}]=0;
                    ne[{x-1,y}]=0;
                    ne[{x-2,y}]=1;
                    dfs(ne);
                     
                }
                if((y+2<=m)&&mp[{x,y+1}]&&!mp[{x,y+2}]){
                    auto ne=mp;
                    ne[{x,y}]=0;
                    ne[{x,y+1}]=0;
                    ne[{x,y+2}]=1;
                    dfs(ne);
                }
                if((y-2)>=1&&mp[{x,y-1}]&&!mp[{x,y-2}]){
                    auto ne=mp;
                    ne[{x,y}]=0;
                    ne[{x,y-1}]=0;
                    ne[{x,y-2}]=1;
                    dfs(ne);
                }
            }
        }
    }
    res=min(res,cnt);
}
void solve(){
    mp.clear();
    st.clear();
    res=INF;
    
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)mp[{i,j}]=0;
    }
    for(int i=1;i<=k;i++){
        int x,y;
        cin>>x>>y;
        mp[{x,y}]=1;
    }
    dfs(mp);
    cout<<res<<endl;

}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << setiosflags(ios::fixed) << setprecision(15);
    int T;
    T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

詳細信息

Test #1:

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

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

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: 1ms
memory: 3648kb

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

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: 10ms
memory: 4024kb

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