Submission #1117261

# Submission time Handle Problem Language Result Execution time Memory
1117261 2024-11-23T07:00:27 Z imarn Sightseeing in Kyoto (JOI22_kyoto) C++14
100 / 100
117 ms 17856 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define szz(r) (ll)r.size()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
struct line{
    ll a,b,c,d;
    bool operator<(const line &o)const{
        return a*o.b<o.a*b;
    }
};
const int mxn=1e5+5;
bool dla[mxn]{0},dlb[mxn]{0};
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int h,w;cin>>h>>w;
    ll a[h+1],b[w+1];
    int la[h+2],ra[h+2],lb[w+2],rb[w+2];
    for(int i=1;i<=h;i++)cin>>a[i],la[i]=i-1,ra[i]=i+1;
    for(int i=1;i<=w;i++)cin>>b[i],lb[i]=i-1,rb[i]=i+1;
    priority_queue<line>qa,qb;
    for(int i=2;i<=h;i++)qa.push({a[i]-a[i-1],1,i-1,i});
    for(int i=2;i<=w;i++)qb.push({b[i]-b[i-1],1,i-1,i});
    ll rs=0;int lsa=h,lsb=w;
    while(!qa.empty()||!qb.empty()){
        if(!qb.empty()&&(qa.empty()||qa.top()<qb.top())){
            auto u=qb.top();qb.pop();
            if(dlb[u.c]||dlb[u.d])continue;
            //cout<<b[u.c]<<' '<<b[u.d]<<" B\n";
            if(u.d==lsb){
                rs+=u.b*a[lsa];
                lsb-=u.b;
            }dlb[u.d]=1;
            rb[u.c]=rb[u.d];
            lb[rb[u.d]]=u.c;
            if(u.c!=0&&rb[u.d]!=w+1)qb.push({b[rb[u.d]]-b[u.c],rb[u.d]-u.c,u.c,rb[u.d]});
        }
        else {
            auto u=qa.top();qa.pop();
            if(dla[u.c]||dla[u.d])continue;
            //cout<<a[u.c]<<' '<<a[u.d]<<" A\n";
            if(u.d==lsa){
                rs+=u.b*b[lsb];
                lsa-=u.b;
            }dla[u.d]=1;
            ra[u.c]=ra[u.d];
            la[ra[u.d]]=u.c;
            if(u.c!=0&&ra[u.d]!=h+1)qa.push({a[ra[u.d]]-a[u.c],ra[u.d]-u.c,u.c,ra[u.d]});
        }
    }cout<<rs;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:28:9: warning: variable 'la' set but not used [-Wunused-but-set-variable]
   28 |     int la[h+2],ra[h+2],lb[w+2],rb[w+2];
      |         ^~
kyoto.cpp:28:25: warning: variable 'lb' set but not used [-Wunused-but-set-variable]
   28 |     int la[h+2],ra[h+2],lb[w+2],rb[w+2];
      |                         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 1 ms 520 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 504 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 37 ms 8136 KB Output is correct
5 Correct 23 ms 8136 KB Output is correct
6 Correct 16 ms 4300 KB Output is correct
7 Correct 95 ms 16572 KB Output is correct
8 Correct 103 ms 16572 KB Output is correct
9 Correct 101 ms 16488 KB Output is correct
10 Correct 93 ms 16480 KB Output is correct
11 Correct 60 ms 16444 KB Output is correct
12 Correct 102 ms 16572 KB Output is correct
13 Correct 95 ms 16520 KB Output is correct
14 Correct 73 ms 16580 KB Output is correct
15 Correct 53 ms 16868 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 464 KB Output is correct
23 Correct 1 ms 508 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 1 ms 520 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 504 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 37 ms 8136 KB Output is correct
33 Correct 23 ms 8136 KB Output is correct
34 Correct 16 ms 4300 KB Output is correct
35 Correct 95 ms 16572 KB Output is correct
36 Correct 103 ms 16572 KB Output is correct
37 Correct 101 ms 16488 KB Output is correct
38 Correct 93 ms 16480 KB Output is correct
39 Correct 60 ms 16444 KB Output is correct
40 Correct 102 ms 16572 KB Output is correct
41 Correct 95 ms 16520 KB Output is correct
42 Correct 73 ms 16580 KB Output is correct
43 Correct 53 ms 16868 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 1 ms 336 KB Output is correct
47 Correct 1 ms 336 KB Output is correct
48 Correct 1 ms 464 KB Output is correct
49 Correct 1 ms 336 KB Output is correct
50 Correct 1 ms 464 KB Output is correct
51 Correct 1 ms 508 KB Output is correct
52 Correct 1 ms 336 KB Output is correct
53 Correct 1 ms 336 KB Output is correct
54 Correct 1 ms 504 KB Output is correct
55 Correct 40 ms 8984 KB Output is correct
56 Correct 1 ms 592 KB Output is correct
57 Correct 4 ms 1236 KB Output is correct
58 Correct 13 ms 2428 KB Output is correct
59 Correct 105 ms 17776 KB Output is correct
60 Correct 114 ms 17596 KB Output is correct
61 Correct 111 ms 17644 KB Output is correct
62 Correct 107 ms 17640 KB Output is correct
63 Correct 61 ms 17608 KB Output is correct
64 Correct 117 ms 17600 KB Output is correct
65 Correct 111 ms 17596 KB Output is correct
66 Correct 66 ms 17604 KB Output is correct
67 Correct 58 ms 17856 KB Output is correct