답안 #23562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23562 2017-05-12T15:12:04 Z TAMREF Fireworks (APIO16_fireworks) C++11
컴파일 오류
0 ms 0 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 vis[303];
ll D[303][303][303];
void dfs(int x){
    vis[x]=true;
    for(pii u : G[x]){
        if(!dfs[u.va]){
            dfs(u);
        }
    }
}
void case2(){
    dfs(1);
    for(int i=0;i<=300;i++) for(int j=0;j<=300;j++) for(int k=0;k<=300;k++) D[i][j][k]=INF;
    ll C=INF;
    for(int i=0;i<=300;i++) for(int j=0;j<=300;j++) for(int k=0;k<=300;k++) C=min(C,D[i][j][k]);
    printf("%lld\n",C);
}
int main(){
    input();
    if(N==1) case1();
    else case2();
}

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 dfs(int)':
fireworks.cpp:43:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
         if(!dfs[u.va]){
                     ^
fireworks.cpp:44:18: error: cannot convert 'pii {aka std::pair<int, int>}' to 'int' for argument '1' to 'void dfs(int)'
             dfs(u);
                  ^
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);
                            ^