답안 #568672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568672 2022-05-26T03:24:46 Z dantoh000 Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
517 ms 22608 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<long double, ii> iii;
int n,m;
int a[100005], b[100005];
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;
                long double nd = (long double)(a[l]-a[nr])/(long double)(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;
                long double nd = (long double)(b[l]-b[nr])/(long double)(nr-l);
                pq2.push({nd, {l,nr}});
            }
        }
    }
    printf("%lld",ans);

}

Compilation message

kyoto.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
kyoto.cpp: In function 'int main()':
kyoto.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%lld%lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
kyoto.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
kyoto.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%lld",&b[j]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 476 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 163 ms 9276 KB Output is correct
5 Correct 84 ms 8848 KB Output is correct
6 Correct 45 ms 4412 KB Output is correct
7 Correct 410 ms 21208 KB Output is correct
8 Correct 424 ms 21220 KB Output is correct
9 Correct 466 ms 21212 KB Output is correct
10 Correct 412 ms 21176 KB Output is correct
11 Correct 179 ms 21152 KB Output is correct
12 Correct 418 ms 21220 KB Output is correct
13 Correct 448 ms 21304 KB Output is correct
14 Correct 272 ms 21400 KB Output is correct
15 Correct 159 ms 21424 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 308 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 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 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 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 3 ms 476 KB Output is correct
16 Correct 3 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 163 ms 9276 KB Output is correct
33 Correct 84 ms 8848 KB Output is correct
34 Correct 45 ms 4412 KB Output is correct
35 Correct 410 ms 21208 KB Output is correct
36 Correct 424 ms 21220 KB Output is correct
37 Correct 466 ms 21212 KB Output is correct
38 Correct 412 ms 21176 KB Output is correct
39 Correct 179 ms 21152 KB Output is correct
40 Correct 418 ms 21220 KB Output is correct
41 Correct 448 ms 21304 KB Output is correct
42 Correct 272 ms 21400 KB Output is correct
43 Correct 159 ms 21424 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 308 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 155 ms 10128 KB Output is correct
56 Correct 2 ms 448 KB Output is correct
57 Correct 12 ms 1488 KB Output is correct
58 Correct 43 ms 3156 KB Output is correct
59 Correct 517 ms 22608 KB Output is correct
60 Correct 493 ms 22120 KB Output is correct
61 Correct 486 ms 22120 KB Output is correct
62 Correct 476 ms 22160 KB Output is correct
63 Correct 198 ms 22252 KB Output is correct
64 Correct 467 ms 22212 KB Output is correct
65 Correct 448 ms 22352 KB Output is correct
66 Correct 240 ms 22340 KB Output is correct
67 Correct 171 ms 21692 KB Output is correct