Submission #701046

# Submission time Handle Problem Language Result Execution time Memory
701046 2023-02-19T21:24:27 Z Kahou Constellation 3 (JOI20_constellation3) C++14
35 / 100
1500 ms 20928 KB
/* In the name of God, aka Allah */
// Believe me - Takeshi Abo
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define mk make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 2e5 + 50;
ll n, m, a[N], pr[N], dp[N][2], par[N];
vector<pair<ll, pll>> vc;
ll adj[N][2];

void solve() {
        cin >> n;
        for (int i = 1; i <= n; i++) {
                cin >> a[i];
        }
        cin >> m;
        ll sm = 0;
        for (int i = 1; i <= m; i++) {
                ll x, y, w;
                cin >> x >> y >> w;
                vc.push_back({y, {-w, x}});
                sm += w;
        }
        for (int i = 1; i <= n; i++) {
                vc.push_back({a[i], {0, i}});
        }
        sort(vc.begin(), vc.end());
        a[0] = a[n+1] = N;
        for (int i = 1; i <= n+1; i++) {
                pr[i] = i-1;
                while (pr[i] > 0 && a[pr[i]] <= a[i]) {
                        if (a[pr[pr[i]]] > a[i]) {
                                par[pr[i]] = i;
                                adj[i][0] = pr[i];
                        }
                        else {
                                par[pr[i]] = pr[pr[i]];
                                adj[pr[pr[i]]][1] = pr[i];
                        }
                        pr[i] = pr[pr[i]];
                }
        }
        for (auto P: vc) {
                ll y = P.F;
                ll x = P.S.S;
                ll w = -P.S.F;
                ll tmp = dp[x][0] + dp[x][1] + w;
                ll u = par[x];
                while (a[u] < y) {
                        tmp += dp[u][u>x];
                        u = par[u];
                }
                dp[u][u<x] = max(dp[u][u<x], tmp);
        }
        cout << sm-dp[0][1] << endl;
}
int main() {
        ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        solve();
        return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 4 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 1 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 3 ms 596 KB Output is correct
33 Correct 2 ms 596 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 2 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 4 ms 596 KB Output is correct
38 Correct 1 ms 596 KB Output is correct
39 Correct 1 ms 596 KB Output is correct
40 Correct 3 ms 596 KB Output is correct
41 Correct 2 ms 596 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 3 ms 596 KB Output is correct
44 Correct 2 ms 596 KB Output is correct
45 Correct 147 ms 20508 KB Output is correct
46 Correct 131 ms 20320 KB Output is correct
47 Correct 140 ms 20156 KB Output is correct
48 Correct 133 ms 20540 KB Output is correct
49 Correct 139 ms 19968 KB Output is correct
50 Correct 129 ms 20464 KB Output is correct
51 Correct 134 ms 20024 KB Output is correct
52 Correct 137 ms 20928 KB Output is correct
53 Correct 131 ms 20804 KB Output is correct
54 Execution timed out 1583 ms 19344 KB Time limit exceeded
55 Halted 0 ms 0 KB -