Submission #555114

# Submission time Handle Problem Language Result Execution time Memory
555114 2022-04-30T07:39:25 Z tht2005 Sightseeing in Kyoto (JOI22_kyoto) C++17
100 / 100
523 ms 27152 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

struct dt {
    LL n, d;
    int i;
    bool t;
    bool operator< (const dt& B) const {
        return n * B.d > B.n * d;
    }
};

const int N = 100005;
int n, m, cnt, a[N], b[N], x[N], y[N];
LL res;
multiset<dt> S;
multiset<dt>::iterator z[N], t[N];
set<int> c, d;

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    for(int i = 0; i < m; ++i) {
        scanf("%d", b + i);
    }
    for(int i = 1; i < n; ++i) {
        z[i] = S.insert({ a[i] - a[i - 1], 1, i, 0 });
        c.insert(i);
    }
    for(int i = 1; i < m; ++i) {
        t[i] = S.insert({ b[i] - b[i - 1], 1, i, 1 });
        d.insert(i);
    }
    while(!S.empty()) {
        auto [nn, dd, i, _] = *S.begin();
        S.erase(S.begin());
        if(_) {
            auto it = d.erase(d.find(i));
            if(it != d.end()) {
                int j = *it;
                dt tmp = *t[j];
                S.erase(t[j]);
                tmp.n += nn;
                tmp.d += dd;
                t[j] = S.insert(tmp);
            }
            y[i] = cnt++;
        }
        else {
            auto it = c.erase(c.find(i));
            if(it != c.end()) {
                int j = *it;
                dt tmp = *z[j];
                S.erase(z[j]);
                tmp.n += nn;
                tmp.d += dd;
                z[j] = S.insert(tmp);
            }
            x[i] = cnt++;
        }
    }
    res = 0;
    for(int i = n - 1, j = m - 1; i || j; ) {
        if(i == 0) {
            res += a[0];
            --j;
        }
        else if(j == 0) {
            res += b[0];
            --i;
        }
        else if(x[i] < y[j]) {
            res += b[j];
            --i;
        }
        else {
            res += a[i];
            --j;
        }
    }
    printf("%lld", res);
    return 0;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
kyoto.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf("%d", a + i);
      |         ~~~~~^~~~~~~~~~~~~
kyoto.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%d", b + i);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 3 ms 2132 KB Output is correct
10 Correct 3 ms 2132 KB Output is correct
11 Correct 3 ms 2020 KB Output is correct
12 Correct 3 ms 2132 KB Output is correct
13 Correct 2 ms 2132 KB Output is correct
14 Correct 3 ms 2132 KB Output is correct
15 Correct 3 ms 2020 KB Output is correct
16 Correct 3 ms 2132 KB Output is correct
17 Correct 3 ms 2112 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1880 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1880 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1872 KB Output is correct
28 Correct 1 ms 2004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 2 ms 2004 KB Output is correct
4 Correct 152 ms 11792 KB Output is correct
5 Correct 68 ms 11168 KB Output is correct
6 Correct 37 ms 5840 KB Output is correct
7 Correct 503 ms 26156 KB Output is correct
8 Correct 503 ms 26048 KB Output is correct
9 Correct 516 ms 26084 KB Output is correct
10 Correct 516 ms 25980 KB Output is correct
11 Correct 179 ms 25964 KB Output is correct
12 Correct 503 ms 26084 KB Output is correct
13 Correct 487 ms 26080 KB Output is correct
14 Correct 258 ms 26044 KB Output is correct
15 Correct 199 ms 26188 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 1 ms 1876 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1800 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1876 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 2 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1876 KB Output is correct
2 Correct 1 ms 1876 KB Output is correct
3 Correct 1 ms 1876 KB Output is correct
4 Correct 2 ms 2004 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 1876 KB Output is correct
7 Correct 1 ms 1880 KB Output is correct
8 Correct 1 ms 1876 KB Output is correct
9 Correct 3 ms 2132 KB Output is correct
10 Correct 3 ms 2132 KB Output is correct
11 Correct 3 ms 2020 KB Output is correct
12 Correct 3 ms 2132 KB Output is correct
13 Correct 2 ms 2132 KB Output is correct
14 Correct 3 ms 2132 KB Output is correct
15 Correct 3 ms 2020 KB Output is correct
16 Correct 3 ms 2132 KB Output is correct
17 Correct 3 ms 2112 KB Output is correct
18 Correct 1 ms 1876 KB Output is correct
19 Correct 1 ms 1876 KB Output is correct
20 Correct 1 ms 1876 KB Output is correct
21 Correct 1 ms 1876 KB Output is correct
22 Correct 1 ms 1880 KB Output is correct
23 Correct 1 ms 1876 KB Output is correct
24 Correct 1 ms 1880 KB Output is correct
25 Correct 1 ms 1876 KB Output is correct
26 Correct 1 ms 1876 KB Output is correct
27 Correct 1 ms 1872 KB Output is correct
28 Correct 1 ms 2004 KB Output is correct
29 Correct 1 ms 1876 KB Output is correct
30 Correct 1 ms 1876 KB Output is correct
31 Correct 2 ms 2004 KB Output is correct
32 Correct 152 ms 11792 KB Output is correct
33 Correct 68 ms 11168 KB Output is correct
34 Correct 37 ms 5840 KB Output is correct
35 Correct 503 ms 26156 KB Output is correct
36 Correct 503 ms 26048 KB Output is correct
37 Correct 516 ms 26084 KB Output is correct
38 Correct 516 ms 25980 KB Output is correct
39 Correct 179 ms 25964 KB Output is correct
40 Correct 503 ms 26084 KB Output is correct
41 Correct 487 ms 26080 KB Output is correct
42 Correct 258 ms 26044 KB Output is correct
43 Correct 199 ms 26188 KB Output is correct
44 Correct 1 ms 1876 KB Output is correct
45 Correct 1 ms 1876 KB Output is correct
46 Correct 1 ms 1876 KB Output is correct
47 Correct 1 ms 1876 KB Output is correct
48 Correct 1 ms 1876 KB Output is correct
49 Correct 1 ms 1876 KB Output is correct
50 Correct 1 ms 1800 KB Output is correct
51 Correct 1 ms 1876 KB Output is correct
52 Correct 1 ms 1876 KB Output is correct
53 Correct 1 ms 1876 KB Output is correct
54 Correct 2 ms 1876 KB Output is correct
55 Correct 168 ms 12916 KB Output is correct
56 Correct 2 ms 2004 KB Output is correct
57 Correct 12 ms 2916 KB Output is correct
58 Correct 28 ms 5252 KB Output is correct
59 Correct 498 ms 27152 KB Output is correct
60 Correct 518 ms 26956 KB Output is correct
61 Correct 497 ms 26960 KB Output is correct
62 Correct 505 ms 27028 KB Output is correct
63 Correct 138 ms 26956 KB Output is correct
64 Correct 523 ms 27052 KB Output is correct
65 Correct 507 ms 26836 KB Output is correct
66 Correct 200 ms 27104 KB Output is correct
67 Correct 206 ms 26012 KB Output is correct