Submission #869834

#TimeUsernameProblemLanguageResultExecution timeMemory
869834DylanSmithFireworks (APIO16_fireworks)Java
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x),end(x) #define lb(x,y) lower_bound(all(x),y)-begin(x) mt19937 rng; void solve() { int N, M; cin >> N >> M; vector<vector<int>> adj(N); vector<int> len(N + M, 0); for (int i = 1; i < N + M; i++) { int u; cin >> u; u--; adj[u].pb(i); cin >> len[i]; } if (M == 0) { cout << 0 << "\n"; return; } vector<int> cnt(N + M, 0); for (int i = N; i < N + M; i++) { cnt[i] = 1; } for (int u = N - 1; u >= 0; u--) { for (int v : adj[u]) { cnt[u] += cnt[v]; } } vector<vector<ll>> x(N + M); vector<ll> y(N + M); for (int u = N + M - 1; u >= 0; u--) { if (!cnt[u]) continue; if (u >= N) { x[u].pb(0); x[u].pb(0); y[u] = 0; } else { vector<ll> srt; for (int v : adj[u]) { if (!cnt[v]) continue; for (ll n : x[v]) srt.pb(n); } sort(all(srt)); x[u].pb(srt[sz(srt) / 2 - 1]); x[u].pb(srt[sz(srt) / 2]); y[u] = 0; for (int v : adj[u]) { if (!cnt[v]) continue; if (x[u][0] <= x[v][0]) { y[u] += x[v][0] - x[u][0] + y[v]; } else if (x[u][0] <= x[v][1]) { y[u] += y[v]; } else { y[u] += x[u][0] - x[v][1] + y[v]; } } } x[u][0] += len[u]; x[u][1] += len[u]; } cout << y[0] << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); rng = mt19937(chrono::steady_clock::now().time_since_epoch().count()); solve(); return 0; }

Compilation message (stderr)

fireworks.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
fireworks.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
         ^
fireworks.java:5: error: class, interface, or enum expected
typedef long long ll;
^
fireworks.java:7: error: illegal character: '#'
#define pb push_back
^
fireworks.java:7: error: class, interface, or enum expected
#define pb push_back
        ^
fireworks.java:8: error: illegal character: '#'
#define sz(x) (int)x.size()
^
fireworks.java:9: error: illegal character: '#'
#define all(x) begin(x),end(x)
^
fireworks.java:10: error: illegal character: '#'
#define lb(x,y) lower_bound(all(x),y)-begin(x)
^
fireworks.java:14: error: class, interface, or enum expected
void solve() {
^
fireworks.java:15: error: class, interface, or enum expected
    int N, M; cin >> N >> M;
              ^
fireworks.java:16: error: class, interface, or enum expected
    vector<vector<int>> adj(N);
    ^
fireworks.java:17: error: class, interface, or enum expected
    vector<int> len(N + M, 0);
    ^
fireworks.java:18: error: class, interface, or enum expected
    for (int i = 1; i < N + M; i++) {
    ^
fireworks.java:18: error: class, interface, or enum expected
    for (int i = 1; i < N + M; i++) {
                    ^
fireworks.java:18: error: class, interface, or enum expected
    for (int i = 1; i < N + M; i++) {
                               ^
fireworks.java:19: error: class, interface, or enum expected
        int u; cin >> u; u--;
               ^
fireworks.java:19: error: class, interface, or enum expected
        int u; cin >> u; u--;
                         ^
fireworks.java:20: error: class, interface, or enum expected
        adj[u].pb(i);
        ^
fireworks.java:21: error: class, interface, or enum expected
        cin >> len[i];
        ^
fireworks.java:22: error: class, interface, or enum expected
    }
    ^
fireworks.java:25: error: class, interface, or enum expected
        return;
        ^
fireworks.java:26: error: class, interface, or enum expected
    }
    ^
fireworks.java:28: error: class, interface, or enum expected
    for (int i = N; i < N + M; i++) {
    ^
fireworks.java:28: error: class, interface, or enum expected
    for (int i = N; i < N + M; i++) {
                    ^
fireworks.java:28: error: class, interface, or enum expected
    for (int i = N; i < N + M; i++) {
                               ^
fireworks.java:30: error: class, interface, or enum expected
    }
    ^
fireworks.java:31: error: class, interface, or enum expected
    for (int u = N - 1; u >= 0; u--) {
                        ^
fireworks.java:31: error: class, interface, or enum expected
    for (int u = N - 1; u >= 0; u--) {
                                ^
fireworks.java:34: error: class, interface, or enum expected
        }
        ^
fireworks.java:37: error: class, interface, or enum expected
    vector<ll> y(N + M);
    ^
fireworks.java:38: error: class, interface, or enum expected
    for (int u = N + M - 1; u >= 0; u--) {
    ^
fireworks.java:38: error: class, interface, or enum expected
    for (int u = N + M - 1; u >= 0; u--) {
                            ^
fireworks.java:38: error: class, interface, or enum expected
    for (int u = N + M - 1; u >= 0; u--) {
                                    ^
fireworks.java:40: error: class, interface, or enum expected
        if (u >= N) {
        ^
fireworks.java:42: error: class, interface, or enum expected
            x[u].pb(0);
            ^
fireworks.java:43: error: class, interface, or enum expected
            y[u] = 0;
            ^
fireworks.java:44: error: class, interface, or enum expected
        } else {
        ^
fireworks.java:46: error: class, interface, or enum expected
            for (int v : adj[u]) {
            ^
fireworks.java:48: error: class, interface, or enum expected
                for (ll n : x[v]) srt.pb(n);
                ^
fireworks.java:49: error: class, interface, or enum expected
            }
            ^
fireworks.java:51: error: class, interface, or enum expected
            x[u].pb(srt[sz(srt) / 2 - 1]);
            ^
fireworks.java:52: error: class, interface, or enum expected
            x[u].pb(srt[sz(srt) / 2]);
            ^
fireworks.java:53: error: class, interface, or enum expected
            y[u] = 0;
            ^
fireworks.java:54: error: class, interface, or enum expected
            for (int v : adj[u]) {
            ^
fireworks.java:56: error: class, interface, or enum expected
                if (x[u][0] <= x[v][0]) {
                ^
fireworks.java:58: error: class, interface, or enum expected
                } else if (x[u][0] <= x[v][1]) {
                ^
fireworks.java:60: error: class, interface, or enum expected
                } else {
                ^
fireworks.java:62: error: class, interface, or enum expected
                }
                ^
fireworks.java:66: error: class, interface, or enum expected
        x[u][1] += len[u];
        ^
fireworks.java:67: error: class, interface, or enum expected
    }
    ^
fireworks.java:69: error: class, interface, or enum expected
}
^
fireworks.java:73: error: class, interface, or enum expected
    cin.tie(nullptr);
    ^
fireworks.java:74: error: class, interface, or enum expected
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());
    ^
fireworks.java:76: error: class, interface, or enum expected
    solve();
    ^
fireworks.java:78: error: class, interface, or enum expected
    return 0;
    ^
fireworks.java:79: error: class, interface, or enum expected
}
^
56 errors