# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
877106 | konber | T-Covering (eJOI19_covering) | C++14 | 69 ms | 12112 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> a, grid;
vector<pair<int, int>> sp;
int K, N, M;
int f(int x){
if(x==K) return 0;
int i=sp[x].first, j=sp[x].second;
int s1=-1, s2=-1, s3=-1, s4=-1;
if(i-1>=0 && i+1<M && j-1>=0){
if(grid[i][j]+grid[i-1][j]+grid[i+1][j]+grid[i][j-1]==0){
grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j-1]=1;
int d=f(x+1);
if(d!=-1) s1 = a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1]+d;
grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j-1]=0;
}
}
if(i-1>=0 && i+1<M && j+1<N){
if(grid[i][j]+grid[i-1][j]+grid[i+1][j]+grid[i][j+1]==0){
grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j+1]=1;
int d=f(x+1);
if(d!=-1) s2 = a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j+1]+d;
grid[i][j]=grid[i-1][j]=grid[i+1][j]=grid[i][j+1]=0;
}
}
if(j-1>=0 && j+1<N && i+1<M){
if(grid[i][j]+grid[i][j-1]+grid[i][j+1]+grid[i+1][j]==0){
grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i+1][j]=1;
int d=f(x+1);
if(d!=-1) s3 = a[i][j]+a[i][j-1]+a[i][j+1]+a[i+1][j]+d;
grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i+1][j]=0;
}
}
if(j-1>=0 && j+1<N && i-1>=0){
if(grid[i][j]+grid[i][j-1]+grid[i][j+1]+grid[i-1][j]==0){
grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i-1][j]=1;
int d=f(x+1);
if(d!=-1) s4 = a[i][j]+a[i][j-1]+a[i][j+1]+a[i-1][j]+d;
grid[i][j]=grid[i][j-1]=grid[i][j+1]=grid[i-1][j]=0;
}
}
return max(s1, max(s2, max(s3, s4)));
}
int main()
{
scanf("%d%d", &M, &N);
a.resize(M, vector<int>(N));
grid.resize(M, vector<int>(N));
for(int i=0; i < M; i++){
for(int j=0; j < N; j++)
scanf("%d", &a[i][j]);
}
scanf("%d", &K);
sp.resize(K);
for(int i=0; i < K; i++){
scanf("%d%d", &sp[i].first, &sp[i].second);
}
if(K <= 10){
int ans=f(0);
if(ans>=0) printf("%d\n", ans);
else printf("No\n");
}
else{
int sum=0;
bool valid=true;
for(int x=0; x < K; x++){
int i=sp[x].first, j=sp[x].second;
int s1=-1, s2=-1, s3=-1, s4=-1;
if(i-1>=0 && i+1<M && j-1>=0) s1=a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j-1];
if(i-1>=0 && i+1<M && j+1<N) s2=a[i][j]+a[i-1][j]+a[i+1][j]+a[i][j+1];
if(j-1>=0 && j+1<N && i-1>=0) s3=a[i][j]+a[i][j-1]+a[i][j+1]+a[i-1][j];
if(j-1>=0 && j+1<N && i+1<M) s4=a[i][j]+a[i][j-1]+a[i][j+1]+a[i+1][j];
int d=max(s1, max(s2, max(s3, s4)));
if(d==-1){
valid=false;
break;
}
sum += d;
}
if(!valid) printf("No\n");
else printf("%d\n", sum);
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |