이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define F first
#define S second
#define pii pair<int ,int>
#define all(a) a.begin(),a.end()
#define loop(i,s,e) for(int i=s;i<e;i++)
using namespace std;
const int N = (int)1e6 + 6;
int n, m, k, g[N], okt = 0;
vector<int> vc, adj[N];
int hx[] = {-1, 1, 0, 0};
int hy[] = {0, 0, 1, -1};
bool vis[N], ok[N];
bool valid(int i,int j){return (i >= 0 && i < n && j >= 0 && j < m);}
void dfs(int v){
vis[v] = 1;
if(!ok[v])vc.pb(g[v]);
else okt ++;
for(auto u : adj[v])if(!vis[u])dfs(u);
}
int32_t main(){
// ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i ++)
for(int j = 0; j < m;j ++){
int v = i*m +j;
cin >> g[v];
ok[v] = vis[v] = 0;
}
cin >> k;
int ans = 0;
for(int i = 0; i < k; i ++){
int x,y;cin >> x >> y;
int v = x*m+y;
// cout << "V : " << v << endl;
ok[v] = 1, ans += g[v];
for(int r = 0;r < 4 ;r ++){
int xx = x + hx[r], yy = y + hy[r];
if (!valid(xx, yy)) continue;
int u = xx*m + yy;
adj[v].pb(u);
adj[u].pb(v);
}
}
for(int r = 0; r < n; r ++){
for(int c = 0; c < m; c ++){
int v = r*m+c;
if(!vis[v] && ok[v]){
okt=0;
vc.clear();
dfs(v);
if(vc.size() < 3*okt){
cout << "No";
return 0;
}
sort(all(vc));
for(int i = 1; i <= 3 * okt; i ++) ans+=vc[vc.size()-i] ;
}
}
}
cout << ans << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
covering.cpp: In function 'int32_t main()':
covering.cpp:57:30: warning: comparison of integer expressions of different signedness: 'std::vector<long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
57 | if(vc.size() < 3*okt){
| ~~~~~~~~~~^~~~~~~
# | 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... |