Submission #23563

# Submission time Handle Problem Language Result Execution time Memory
23563 2017-05-12T15:12:45 Z TAMREF Fireworks (APIO16_fireworks) C++11
7 / 100
3 ms 9052 KB
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=1<<45;
const int MX=300005;
int N,M;
vector<pii> G[300005];
void input(){
    scanf("%d%d",&N,&M);
    for(int i=2,x,y;i<=N+M;i++){
        scanf("%d%d",&x,&y);
        G[i].push_back(make_pair(x,y));
        G[x].push_back(make_pair(i,y));
    }
}
void case1(){
    int p=0,q,r,s=INT_MAX;
    auto pro = [=](int x)->ll{
        ll S=0;
        for(pii u : G[1]){
            S+=llabs((ll)u.vb-x);
            //cout<<u.va<<' '<<u.vb<<" : "<<S<<endl;
        }
        return S;
    };
    while(p<s){
        q=p+(s-p)/3,r=s-(s-p)/3;
        if(pro(q)<=pro(r)) s=r-1;
        else p=q+1;
    }
    printf("%lld\n",pro(p));
    exit(0);
}

int main(){
    input();
    if(N==1) case1();
    else return 0;
}

Compilation message

fireworks.cpp:7:17: warning: left shift count >= width of type [-Wshift-count-overflow]
 const ll INF=1<<45;
                 ^
fireworks.cpp: In function 'void input()':
fireworks.cpp:12:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&N,&M);
                        ^
fireworks.cpp:14:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&x,&y);
                            ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9052 KB Output is correct
2 Correct 0 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 0 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 0 ms 9052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 9052 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9052 KB Output is correct
2 Correct 0 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 0 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 0 ms 9052 KB Output is correct
11 Incorrect 0 ms 9052 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9052 KB Output is correct
2 Correct 0 ms 9052 KB Output is correct
3 Correct 3 ms 9052 KB Output is correct
4 Correct 3 ms 9052 KB Output is correct
5 Correct 3 ms 9052 KB Output is correct
6 Correct 0 ms 9052 KB Output is correct
7 Correct 3 ms 9052 KB Output is correct
8 Correct 3 ms 9052 KB Output is correct
9 Correct 3 ms 9052 KB Output is correct
10 Correct 0 ms 9052 KB Output is correct
11 Incorrect 0 ms 9052 KB Output isn't correct
12 Halted 0 ms 0 KB -