답안 #1113003

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113003 2024-11-15T11:22:24 Z ttamx Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
25 ms 10952 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;

const int N=2e5+5;

int n,m;
ll a[N],b[N];
ll ans;

struct Info{
    ll c0,c1;
    bool operator<(const Info &o)const{
        return c0*o.c1<o.c0*c1;
    }
    void update(const Info &o){
        c0+=o.c0,c1+=o.c1;
    }
};

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    ans+=a[0]*(m-1)+b[0]*(n-1);
    vector<Info> c,d;
    for(int i=1;i<n;i++){
        Info cur{a[i]-a[i-1],1};
        while(!c.empty()&&cur<c.back()){
            cur.update(c.back());
            c.pop_back();
        }
        c.emplace_back(cur);
    }
    for(int i=1;i<m;i++){
        Info cur{b[i]-b[i-1],1};
        while(!d.empty()&&cur<d.back()){
            cur.update(d.back());
            d.pop_back();
        }
        d.emplace_back(cur);
    }
    Info va{0,0},vb{0,0};
    for(int i=0,j=0;i<c.size()||j<d.size();){
        if(i==c.size()||(j<d.size()&&d[j]<c[i])){
            ans+=va.c0*d[j].c1;
            vb.update(d[j]);
            j++;
        }else{
            ans+=vb.c0*c[i].c1;
            va.update(c[i]);
            i++;
        }
    }
    cout << ans << "\n";
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0,j=0;i<c.size()||j<d.size();){
      |                     ~^~~~~~~~~
kyoto.cpp:51:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for(int i=0,j=0;i<c.size()||j<d.size();){
      |                                 ~^~~~~~~~~
kyoto.cpp:52:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if(i==c.size()||(j<d.size()&&d[j]<c[i])){
      |            ~^~~~~~~~~~
kyoto.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if(i==c.size()||(j<d.size()&&d[j]<c[i])){
      |                          ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2552 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2560 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2560 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2556 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2556 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 6 ms 2896 KB Output is correct
5 Correct 5 ms 2896 KB Output is correct
6 Correct 3 ms 2640 KB Output is correct
7 Correct 12 ms 3408 KB Output is correct
8 Correct 12 ms 3408 KB Output is correct
9 Correct 12 ms 3408 KB Output is correct
10 Correct 12 ms 3408 KB Output is correct
11 Correct 11 ms 3664 KB Output is correct
12 Correct 12 ms 3408 KB Output is correct
13 Correct 12 ms 3408 KB Output is correct
14 Correct 11 ms 3568 KB Output is correct
15 Correct 16 ms 8768 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2552 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2552 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2552 KB Output is correct
4 Correct 1 ms 2552 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2560 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2560 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2384 KB Output is correct
20 Correct 1 ms 2556 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2556 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2384 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 6 ms 2896 KB Output is correct
33 Correct 5 ms 2896 KB Output is correct
34 Correct 3 ms 2640 KB Output is correct
35 Correct 12 ms 3408 KB Output is correct
36 Correct 12 ms 3408 KB Output is correct
37 Correct 12 ms 3408 KB Output is correct
38 Correct 12 ms 3408 KB Output is correct
39 Correct 11 ms 3664 KB Output is correct
40 Correct 12 ms 3408 KB Output is correct
41 Correct 12 ms 3408 KB Output is correct
42 Correct 11 ms 3568 KB Output is correct
43 Correct 16 ms 8768 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2552 KB Output is correct
46 Correct 1 ms 2384 KB Output is correct
47 Correct 1 ms 2384 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2384 KB Output is correct
50 Correct 1 ms 2384 KB Output is correct
51 Correct 1 ms 2384 KB Output is correct
52 Correct 1 ms 2552 KB Output is correct
53 Correct 1 ms 2384 KB Output is correct
54 Correct 1 ms 2384 KB Output is correct
55 Correct 8 ms 3320 KB Output is correct
56 Correct 1 ms 2552 KB Output is correct
57 Correct 2 ms 2384 KB Output is correct
58 Correct 3 ms 2640 KB Output is correct
59 Correct 20 ms 3920 KB Output is correct
60 Correct 21 ms 3920 KB Output is correct
61 Correct 20 ms 3920 KB Output is correct
62 Correct 21 ms 3920 KB Output is correct
63 Correct 21 ms 9672 KB Output is correct
64 Correct 18 ms 4712 KB Output is correct
65 Correct 19 ms 4688 KB Output is correct
66 Correct 17 ms 4688 KB Output is correct
67 Correct 25 ms 10952 KB Output is correct