이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int n,m;
set<pair<int,int>>s;
bool f(int x,int y){
if(x<0 || x>=n || y<0 || y>=m)return false;
if(s.count({x,y}))return false;
return true;
}
int32_t main(){
cin>>n>>m;
int arr[n][m];
for(int i=0;i<n;i++){
for(int j=0;j<m;j++)cin>>arr[i][j];
}
int k;
cin>>k;
int ans=0;
for(int i=0;i<k;i++){
int a,b;
cin>>a>>b;
s.insert({a,b});
}
for(auto i:s){
int x=i.ff;
int y=i.ss;
int z=(f(x-1,y)+f(x+1,y)+f(x,y-1)+f(x,y+1));
if(z>1){
ans=-1;
break;
}
if(z==1){
ans+=arr[x][y];
for(int j=-1;j<=1;j+=2){
for(int k=-1;k<=1;k+=2){
if(f(j,k)){
ans+=arr[j][k];
}
}
}
}
else{
ans+=arr[x][y]+arr[x-1][y]+arr[x+1][y]+arr[x][y-1]+arr[x][y+1];
ans-=min({arr[x-1][y],arr[x+1][y],arr[x][y-1],arr[x][y+1]});
}
}
if(ans==-1)cout<<"No"<<endl;
else cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
covering.cpp: In function 'int32_t main()':
covering.cpp:48:20: warning: array subscript -1 is below array bounds of 'long long int [(<anonymous> + 1)]' [-Warray-bounds]
48 | ans+=arr[j][k];
| ~~~~~~~~^
# | 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... |