답안 #409623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409623 2021-05-21T08:14:48 Z anime Fireworks (APIO16_fireworks) C++14
19 / 100
72 ms 12876 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%d %lld",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define umax(a,b) a = max(a,b);
#define umin(a,b) a = min(a,b);
#define endi puts("");
#define eps 1e-12
const int N = 1e5+12,INF=1e18+7;
int q[N],res,dp[1001][1001];
vector <pii> g[N],ver[N];
void dfs(int x,int gl){
    if (g[x].empty())ret ;
    for (pii to:g[x])
        dfs(to.fr,gl+1);
    int i,j;
    for (pii to:g[x]){


        for (i=0;i<=600;++i){
            if (dp[x][i] == INF) dp[x][i]=0;
            int mn = INF;
            for (j=0;j<=i;++j){

                mn = min(mn,dp[to.fr][i-j]+abs(to.sc-j));

            }
            dp[x][i] += mn;
        }

    }



}


main(){
    int n,m,i,j,ans=INF,sum=0;
    cin>>n>>m;
    for (i=0;i<=1000;++i){
        for (j=0;j<=1000;++j){
            dp[i][j] = INF;
        }
    }

    for (i=2;i<=m+n;++i){
        int x,y;
        cin>>x>>y;
        g[x].pb({i,y});
        if (i > n){
            dp[i][0] = 0;
        }
    }
    dfs(1,0);
    for (i=1;i<=1000;++i){
        ans = min(ans,dp[1][i]);
    }
    cout <<ans;
}



















Compilation message

fireworks.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:55:25: warning: unused variable 'sum' [-Wunused-variable]
   55 |     int n,m,i,j,ans=INF,sum=0;
      |                         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12840 KB Output is correct
2 Correct 15 ms 12768 KB Output is correct
3 Correct 19 ms 12848 KB Output is correct
4 Correct 27 ms 12848 KB Output is correct
5 Correct 32 ms 12808 KB Output is correct
6 Correct 34 ms 12828 KB Output is correct
7 Correct 39 ms 12824 KB Output is correct
8 Correct 44 ms 12832 KB Output is correct
9 Correct 47 ms 12824 KB Output is correct
10 Correct 52 ms 12808 KB Output is correct
11 Correct 59 ms 12876 KB Output is correct
12 Correct 61 ms 12804 KB Output is correct
13 Correct 65 ms 12828 KB Output is correct
14 Correct 68 ms 12748 KB Output is correct
15 Correct 72 ms 12748 KB Output is correct
16 Correct 70 ms 12812 KB Output is correct
17 Correct 72 ms 12832 KB Output is correct
18 Correct 70 ms 12748 KB Output is correct
19 Correct 71 ms 12828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 12748 KB Output isn't correct
2 Halted 0 ms 0 KB -