Submission #42707

# Submission time Handle Problem Language Result Execution time Memory
42707 2018-03-03T00:52:20 Z imaxblue Fireworks (APIO16_fireworks) C++14
7 / 100
14 ms 14756 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, m, p, d;
ll c;
vector<pii> v[600006];
p3i ans[600005];
void dfs(int N, int D){
    vector<pii> t;
    int sz=0, cnt=0;
    fox(l, v[N].size()){
        dfs(v[N][l].x, v[N][l].y);
        t.pb(mp(ans[v[N][l].x].x.x, 1));
        t.pb(mp(ans[v[N][l].x].x.y, 1));
        sz+=2;
    }
    sort(t.begin(), t.end());
    ans[N].y=sz/2;
    fox(l, t.size()){
        cnt+=t[l].y;
        //cout << t[l].x << ' ' << t[l].y << ' ' << cnt<< endl;
        if (cnt*2>sz){
            ans[N].x.y=t[l].x;
            if (sz%4==0 && t[l].y==1){
                //cout<< "*";
                ans[N].x.x=t[l-1].x;
            } else ans[N].x.x=ans[N].x.y;
            break;
        }
    }
    fox(l, v[N].size()){
        if (ans[N].x.x<ans[v[N][l].x].x.x) c+=1LL*(ans[v[N][l].x].x.x-ans[N].x.x);
        else if (ans[N].x.x>ans[v[N][l].x].x.x) c+=1LL*(ans[N].x.x-ans[v[N][l].x].x.x);
    }
    if (N>n){
        ans[N]=mp(mp(0, 0), 1);
    }
    ans[N].x.x+=D;
    ans[N].x.y+=D;
    //cout << N << ' ' << ans[N].x.x << ' ' << ans[N].x.y << ' ' << ans[N].y << ' ' << c<< endl;
}

int main(){
    scanf("%i%i", &n, &m);
    fox1(l, n-1){
        scanf("%i%i", &p, &d);
        v[p].pb(mp(l+1, d));
    }
    fox1(l, m){
        scanf("%i%i", &p, &d);
        v[p].pb(mp(l+n, d));
    }
    dfs(1, 0);
    cout << c;
    return 0;
}

Compilation message

fireworks.cpp: In function 'void dfs(int, int)':
fireworks.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fireworks.cpp:37:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^
fireworks.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fireworks.cpp:45:5: note: in expansion of macro 'fox'
     fox(l, t.size()){
     ^
fireworks.cpp:18:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define fox(k, x) for (int k=0; k<x; ++k)
                                  ^
fireworks.cpp:57:5: note: in expansion of macro 'fox'
     fox(l, v[N].size()){
     ^
fireworks.cpp: In function 'int main()':
fireworks.cpp:70:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i", &n, &m);
                          ^
fireworks.cpp:72:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i", &p, &d);
                              ^
fireworks.cpp:76:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i%i", &p, &d);
                              ^
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14328 KB Output is correct
2 Correct 13 ms 14432 KB Output is correct
3 Correct 14 ms 14632 KB Output is correct
4 Correct 12 ms 14632 KB Output is correct
5 Correct 14 ms 14632 KB Output is correct
6 Correct 12 ms 14632 KB Output is correct
7 Correct 12 ms 14748 KB Output is correct
8 Correct 12 ms 14748 KB Output is correct
9 Correct 13 ms 14756 KB Output is correct
10 Correct 12 ms 14756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 14756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14328 KB Output is correct
2 Correct 13 ms 14432 KB Output is correct
3 Correct 14 ms 14632 KB Output is correct
4 Correct 12 ms 14632 KB Output is correct
5 Correct 14 ms 14632 KB Output is correct
6 Correct 12 ms 14632 KB Output is correct
7 Correct 12 ms 14748 KB Output is correct
8 Correct 12 ms 14748 KB Output is correct
9 Correct 13 ms 14756 KB Output is correct
10 Correct 12 ms 14756 KB Output is correct
11 Incorrect 12 ms 14756 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14328 KB Output is correct
2 Correct 13 ms 14432 KB Output is correct
3 Correct 14 ms 14632 KB Output is correct
4 Correct 12 ms 14632 KB Output is correct
5 Correct 14 ms 14632 KB Output is correct
6 Correct 12 ms 14632 KB Output is correct
7 Correct 12 ms 14748 KB Output is correct
8 Correct 12 ms 14748 KB Output is correct
9 Correct 13 ms 14756 KB Output is correct
10 Correct 12 ms 14756 KB Output is correct
11 Incorrect 12 ms 14756 KB Output isn't correct
12 Halted 0 ms 0 KB -