QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#473183 | #6534. Peg Solitaire | zzisjtu# | WA | 0ms | 3700kb | C++23 | 1.8kb | 2024-07-11 22:51:09 | 2024-07-11 22:51:10 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(), x.end()
#define lowbit(i) ((i)&(-i))
#define pii pair<int,int>
#define endl '\n'
#define mk(x,y) make_pair(x,y)
#define popcount(x) __builtin_popcount(x)
#define LF(x) fixed<<setprecision(x)
const double pi=3.14159265358979323846;
const double eps=1e-9;
const int inf=1e9;
const long long INF=4e18;
const int mod=1e9+7;
using namespace std;
const int N=1e5+10;
void solve()
{
int n,m,k;
cin>>n>>m>>k;
vector<vector<int>>a(n+1,vector<int>(m+1));
for(int i=1;i<=k;i++){
int x,y;
cin>>x>>y;
a[x][y]=1;
}
int ans=inf;
function<void(int)> dfs=[&](int cnt){
ans=min(ans,cnt);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(i>=3&&a[i][j]==1&&a[i-1][j]==1&&a[i-2][j]==0){//up
a[i][j]=a[i-1][j]=0;
a[i-2][j]=1;
dfs(cnt-1);
a[i][j]=a[i-1][j]=1;
a[i-2][j]=0;
}
else if(i<=n-2&&a[i][j]==1&&a[i+1][j]==1&&a[i+2][j]==0){//down
a[i][j]=a[i+1][j]=0;
a[i+2][j]=1;
dfs(cnt-1);
a[i][j]=a[i+1][j]=0;
a[i+2][j]=1;
}
if(j>=3&&a[i][j]==1&&a[i][j-1]==1&&a[i][j-2]==0){//left
a[i][j]=a[i][j-1]=0;
a[i][j-2]=1;
dfs(cnt-1);
a[i][j]=a[i][j-1]=1;
a[i][j-2]=0;
}
else if(j<=m-2&&a[i][j]==1&&a[i][j+1]==1&a[i][j+2]==0){//right
a[i][j]=a[i][j+1]=0;
a[i][j+2]=1;
dfs(cnt-1);
a[i][j]=a[i][j+1]=1;
a[i][j+2]=0;
}
}
}
};
dfs(k);
cout<<ans<<endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>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: 3700kb
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: 0ms
memory: 3460kb
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 2 1 2 1 1 3 3 2 1 3 3 2 1 3 1 3 2
result:
wrong answer 4th numbers differ - expected: '1', found: '2'