답안 #915005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
915005 2024-01-23T06:48:45 Z Tuanlinh123 Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
314 ms 18260 KB
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;

ll a[100005], b[100005], toa[100005], tob[100005];
struct num
{
    ll t, i, j;
    num(){}
    num(ll i, ll t): i(i), t(t)
    {
        if (t==0) j=toa[i];
        else j=tob[i];
    }
    bool operator < (const num &o) const
    {
        ll v=t==0?a[i]-a[j]:b[i]-b[j], ov=o.t==0?a[o.i]-a[o.j]:b[o.i]-b[o.j];
        if (v*(o.j-o.i)==ov*(j-i)) return mp(t, mp(i, j))<mp(o.t, mp(o.i, o.j));
        return v*(o.j-o.i)<ov*(j-i);
    }
};
set <num> S;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m, cn, cm, ans=0; cin >> n >> m; cn=n, cm=m;
    for (ll i=1; i<=n; i++) cin >> a[i];
    for (ll i=1; i<=m; i++) cin >> b[i];
    for (ll i=1; i<n; i++) toa[i]=i+1, S.insert(num(i, 0));
    for (ll i=1; i<m; i++) tob[i]=i+1, S.insert(num(i, 1));
    while (S.size())
    {
        num Min=*S.begin(); S.erase(S.begin());
        ll t=Min.t, i=Min.i, j=Min.j;
        if (t==0)
        {
            if (j==cn) ans+=b[cm]*(j-i), cn=i;
            else
            {
                S.erase(num(j, 0)), toa[i]=toa[j];
                S.insert(num(i, 0));
            }
        }
        else
        {
            if (j==cm) ans+=a[cn]*(j-i), cm=i;
            else
            {
                S.erase(num(j, 1)), tob[i]=tob[j];
                S.insert(num(i, 1));
            }
        }
    }
    cout << ans << "\n";
}

Compilation message

kyoto.cpp: In constructor 'num::num(long long int, long long int)':
kyoto.cpp:14:11: warning: 'num::i' will be initialized after [-Wreorder]
   14 |     ll t, i, j;
      |           ^
kyoto.cpp:14:8: warning:   'long long int num::t' [-Wreorder]
   14 |     ll t, i, j;
      |        ^
kyoto.cpp:16:5: warning:   when initialized here [-Wreorder]
   16 |     num(ll i, ll t): i(i), t(t)
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2424 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 86 ms 8572 KB Output is correct
5 Correct 35 ms 7704 KB Output is correct
6 Correct 27 ms 4952 KB Output is correct
7 Correct 314 ms 16976 KB Output is correct
8 Correct 271 ms 16632 KB Output is correct
9 Correct 308 ms 16976 KB Output is correct
10 Correct 295 ms 16744 KB Output is correct
11 Correct 74 ms 16724 KB Output is correct
12 Correct 261 ms 16964 KB Output is correct
13 Correct 269 ms 16876 KB Output is correct
14 Correct 118 ms 16720 KB Output is correct
15 Correct 105 ms 17232 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2520 KB Output is correct
23 Correct 1 ms 2548 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2424 KB Output is correct
9 Correct 2 ms 2652 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 2 ms 2652 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 2 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2516 KB Output is correct
29 Correct 1 ms 2392 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 86 ms 8572 KB Output is correct
33 Correct 35 ms 7704 KB Output is correct
34 Correct 27 ms 4952 KB Output is correct
35 Correct 314 ms 16976 KB Output is correct
36 Correct 271 ms 16632 KB Output is correct
37 Correct 308 ms 16976 KB Output is correct
38 Correct 295 ms 16744 KB Output is correct
39 Correct 74 ms 16724 KB Output is correct
40 Correct 261 ms 16964 KB Output is correct
41 Correct 269 ms 16876 KB Output is correct
42 Correct 118 ms 16720 KB Output is correct
43 Correct 105 ms 17232 KB Output is correct
44 Correct 1 ms 2392 KB Output is correct
45 Correct 1 ms 2396 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2520 KB Output is correct
51 Correct 1 ms 2548 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 100 ms 9800 KB Output is correct
56 Correct 2 ms 2392 KB Output is correct
57 Correct 6 ms 3160 KB Output is correct
58 Correct 23 ms 4444 KB Output is correct
59 Correct 279 ms 18020 KB Output is correct
60 Correct 283 ms 18232 KB Output is correct
61 Correct 288 ms 18040 KB Output is correct
62 Correct 304 ms 18260 KB Output is correct
63 Correct 66 ms 17744 KB Output is correct
64 Correct 292 ms 18000 KB Output is correct
65 Correct 308 ms 18224 KB Output is correct
66 Correct 95 ms 18028 KB Output is correct
67 Correct 109 ms 18244 KB Output is correct