이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
typedef unsigned long long ull;
using namespace std;
const int N=305;
int n,r,c,mvx[]={0,1,0,-1},mvy[]={1,0,-1,0};
int rec(vector<vector<bool>> v){
int s=0;
for (int i=0;i<r;i++) for (int j=0;j<c;j++) s+=v[i][j];
if (s==r*c) return 0;
int ans=INT_MAX;
for (int k=0;k<4;k++){
set<pair<int,int>> b;
for (int i=0;i<r;i++){
for (int j=0;j<c;j++){
if (!v[i][j]) continue;
int x=i+mvx[k],y=j+mvy[k];
if (x<0 || x>=r || y<0 || y>=c) continue;
if (v[x][y]) continue;
b.ep({x,y});
}
}
if (b.empty()) continue;
for (auto u:b) v[u.F][u.S]=1;
ans=min(ans,rec(v)+1);
for (auto u:b) v[u.F][u.S]=0;
}return ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<vector<bool>> v;
cin>>r>>c;
for (int i=0;i<r;i++){
vector<bool> b;
for (int j=0;j<c;j++) b.pb(0);
v.pb(b);
}
cin>>n;
for (int i=0;i<n;i++){
int x,y;
cin>>x>>y;
v[--x][--y]=1;
}
cout<<rec(v);
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |