이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
typedef pair<double, ii> iii;
const int INF = 1000000000000000000;
int n,m;
int a[1005], b[1005];
set<int> x,y;
priority_queue<iii, vector<iii>, greater<iii> > pq1, pq2;
main(){
scanf("%lld%lld",&n,&m);
for (int i = 0; i < n; i++){
scanf("%lld",&a[i]);
}
for (int j = 0; j < m; j++){
scanf("%lld",&b[j]);
}
for (int i = 0; i < n; i++){
x.insert(i);
}
for (int j = 0; j < m; j++){
y.insert(j);
}
for (int i = 0; i < n-1; i++){
pq1.push({a[i]-a[i+1],{i,i+1}});
}
for (int j = 0; j < m-1; j++){
pq2.push({b[j]-b[j+1],{j,j+1}});
}
int ans = 0;
while (pq1.size() || pq2.size()){
if (pq2.empty() || (!pq1.empty() && pq1.top().fi < pq2.top().fi)){
iii cur = pq1.top(); pq1.pop();
int l = cur.se.fi, r = cur.se.se;
if (x.find(l) == x.end() || x.find(r) == x.end()) continue;
x.erase(r);
auto it = x.lower_bound(r);
if (it == x.end()){
///printf("adding H edge %d->%d, length %d and cost %d\n",l,r,r-l,b[*y.rbegin()]);
ans += b[*y.rbegin()]*(r-l);
}
else{
int nr = *it;
double nd = (double)(a[l]-a[nr])/(nr-l);
pq1.push({nd, {l,nr}});
}
}
else {
iii cur = pq2.top(); pq2.pop();
int l = cur.se.fi, r = cur.se.se;
if (y.find(l) == y.end() || y.find(r) == y.end()) continue;
y.erase(r);
auto it = y.lower_bound(r);
if (it == y.end()){
///printf("adding W edge %d->%d, length %d and cost %d\n",l,r,r-l,a[*x.rbegin()]);
ans += a[*x.rbegin()]*(r-l);
}
else{
int nr = *it;
double nd = (double)(b[l]-b[nr])/(nr-l);
pq2.push({nd, {l,nr}});
}
}
}
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
kyoto.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
13 | main(){
| ^~~~
kyoto.cpp: In function 'int main()':
kyoto.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%lld%lld",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~~~
kyoto.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
kyoto.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%lld",&b[j]);
| ~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |