답안 #568670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568670 2022-05-26T03:22:57 Z dantoh000 Sightseeing in Kyoto (JOI22_kyoto) C++14
10 / 100
3 ms 468 KB
#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);

}

Compilation message

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]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 456 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 408 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 3 ms 452 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 2 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 456 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 408 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 3 ms 452 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 304 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Incorrect 2 ms 468 KB Output isn't correct
32 Halted 0 ms 0 KB -