Submission #430143

# Submission time Handle Problem Language Result Execution time Memory
430143 2021-06-16T11:42:07 Z 2qbingxuan Constellation 3 (JOI20_constellation3) C++14
35 / 100
10 ms 11032 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back

using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
const int mod = 1000000007;
const int inf = 1e9;
const ll INF = 1e18;
const int maxn = 100025;

void chmax(ll &x, ll v) {
    if (x < v) x = v;
}
bool alive[maxn];

int pa[maxn];
int anc(int x) { return x==pa[x] ? x : pa[x]=anc(pa[x]); }
map<int,ll> top[maxn];
ll tag[maxn];
ll dp[maxn];
void join(int a, int b, int h) {
    a = anc(a);
    b = anc(b);
    assert (a != b);
    while (top[a].size() && top[a].begin()->first <= h) {
        chmax(dp[a], top[a].begin()->second + tag[a]);
        top[a].erase(top[a].begin());
    }
    while (top[b].size() && top[b].begin()->first <= h) {
        chmax(dp[b], top[b].begin()->second + tag[b]);
        top[b].erase(top[b].begin());
    }
    ll tmpdp = dp[b] + dp[a];
    tag[a] += dp[b];
    tag[b] += dp[a];
    if (top[a].size() > top[b].size()) {
        for (auto [y, val]: top[b])
            chmax(top[a][y], val + tag[b] - tag[a]);
        swap(top[a], top[b]);
        swap(tag[a], tag[b]);
    } else {
        for (auto [y, val]: top[a])
            chmax(top[b][y], val + tag[a] - tag[b]);
    }
    dp[b] = tmpdp;
    pa[a] = b;
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    iota(pa, pa+n, 0);
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    int m;
    cin >> m;
    ll tot = 0, ans = 0;
    for (int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        --x;
        chmax(top[x][y], c);
        tot += c;
    }
    map<int, vector<int>> mp;
    for (int i = 0; i < n; i++) mp[A[i]].push_back(i);
    for (const auto &[h, indices]: mp) {
        for (int i: indices) {
            if (i > 0 && alive[i-1]) {
                join(i-1, i, h);
            }
            if (i+1 < n && alive[i+1]) {
                join(i, i+1, h);
            }
            alive[i] = true;
        }
    }
    int root = anc(0);
    for (auto [y, val]: top[root]) chmax(ans, val + tag[root]);
    chmax(ans, dp[root]);
    cout << tot - ans << '\n';
}

Compilation message

constellation3.cpp: In function 'void join(int, int, int)':
constellation3.cpp:61:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   61 |         for (auto [y, val]: top[b])
      |                   ^
constellation3.cpp:66:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   66 |         for (auto [y, val]: top[a])
      |                   ^
constellation3.cpp: In function 'int main()':
constellation3.cpp:93:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   93 |     for (const auto &[h, indices]: mp) {
      |                      ^
constellation3.cpp:105:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  105 |     for (auto [y, val]: top[root]) chmax(ans, val + tag[root]);
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5064 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 5 ms 5032 KB Output is correct
9 Correct 5 ms 5068 KB Output is correct
10 Correct 5 ms 5068 KB Output is correct
11 Correct 4 ms 5044 KB Output is correct
12 Correct 4 ms 5068 KB Output is correct
13 Correct 4 ms 5068 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5068 KB Output is correct
16 Correct 4 ms 5020 KB Output is correct
17 Correct 4 ms 5068 KB Output is correct
18 Correct 5 ms 5068 KB Output is correct
19 Correct 4 ms 5068 KB Output is correct
20 Correct 4 ms 5068 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5064 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 5 ms 5032 KB Output is correct
9 Correct 5 ms 5068 KB Output is correct
10 Correct 5 ms 5068 KB Output is correct
11 Correct 4 ms 5044 KB Output is correct
12 Correct 4 ms 5068 KB Output is correct
13 Correct 4 ms 5068 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5068 KB Output is correct
16 Correct 4 ms 5020 KB Output is correct
17 Correct 4 ms 5068 KB Output is correct
18 Correct 5 ms 5068 KB Output is correct
19 Correct 4 ms 5068 KB Output is correct
20 Correct 4 ms 5068 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 6 ms 5324 KB Output is correct
24 Correct 6 ms 5324 KB Output is correct
25 Correct 7 ms 5324 KB Output is correct
26 Correct 6 ms 5292 KB Output is correct
27 Correct 7 ms 5324 KB Output is correct
28 Correct 7 ms 5324 KB Output is correct
29 Correct 6 ms 5360 KB Output is correct
30 Correct 6 ms 5424 KB Output is correct
31 Correct 6 ms 5288 KB Output is correct
32 Correct 6 ms 5420 KB Output is correct
33 Correct 6 ms 5420 KB Output is correct
34 Correct 7 ms 5452 KB Output is correct
35 Correct 6 ms 5452 KB Output is correct
36 Correct 5 ms 5236 KB Output is correct
37 Correct 6 ms 5324 KB Output is correct
38 Correct 5 ms 5420 KB Output is correct
39 Correct 6 ms 5196 KB Output is correct
40 Correct 7 ms 5340 KB Output is correct
41 Correct 6 ms 5196 KB Output is correct
42 Correct 7 ms 5288 KB Output is correct
43 Correct 6 ms 5428 KB Output is correct
44 Correct 6 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5068 KB Output is correct
2 Correct 4 ms 5068 KB Output is correct
3 Correct 4 ms 5064 KB Output is correct
4 Correct 4 ms 5068 KB Output is correct
5 Correct 4 ms 5068 KB Output is correct
6 Correct 5 ms 5068 KB Output is correct
7 Correct 4 ms 5068 KB Output is correct
8 Correct 5 ms 5032 KB Output is correct
9 Correct 5 ms 5068 KB Output is correct
10 Correct 5 ms 5068 KB Output is correct
11 Correct 4 ms 5044 KB Output is correct
12 Correct 4 ms 5068 KB Output is correct
13 Correct 4 ms 5068 KB Output is correct
14 Correct 4 ms 5068 KB Output is correct
15 Correct 4 ms 5068 KB Output is correct
16 Correct 4 ms 5020 KB Output is correct
17 Correct 4 ms 5068 KB Output is correct
18 Correct 5 ms 5068 KB Output is correct
19 Correct 4 ms 5068 KB Output is correct
20 Correct 4 ms 5068 KB Output is correct
21 Correct 4 ms 5068 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 6 ms 5324 KB Output is correct
24 Correct 6 ms 5324 KB Output is correct
25 Correct 7 ms 5324 KB Output is correct
26 Correct 6 ms 5292 KB Output is correct
27 Correct 7 ms 5324 KB Output is correct
28 Correct 7 ms 5324 KB Output is correct
29 Correct 6 ms 5360 KB Output is correct
30 Correct 6 ms 5424 KB Output is correct
31 Correct 6 ms 5288 KB Output is correct
32 Correct 6 ms 5420 KB Output is correct
33 Correct 6 ms 5420 KB Output is correct
34 Correct 7 ms 5452 KB Output is correct
35 Correct 6 ms 5452 KB Output is correct
36 Correct 5 ms 5236 KB Output is correct
37 Correct 6 ms 5324 KB Output is correct
38 Correct 5 ms 5420 KB Output is correct
39 Correct 6 ms 5196 KB Output is correct
40 Correct 7 ms 5340 KB Output is correct
41 Correct 6 ms 5196 KB Output is correct
42 Correct 7 ms 5288 KB Output is correct
43 Correct 6 ms 5428 KB Output is correct
44 Correct 6 ms 5196 KB Output is correct
45 Runtime error 10 ms 11032 KB Execution killed with signal 11
46 Halted 0 ms 0 KB -