# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
172730 | 2020-01-02T13:22:52 Z | Ruxandra985 | Fireworks (APIO16_fireworks) | C++14 | 9 ms | 7416 KB |
#include <bits/stdc++.h> #define DIMN 300010 using namespace std; vector <pair <long long,long long> > v[DIMN]; pair <long long,long long> sol[DIMN]; long long sum[DIMN] , n , m; long long modul (long long x){ if (x > 0) return x; return -x; } FILE *fin = stdin; FILE *fout = stdout; long long check (long long x , long long nod){ long long i , vecin , val=0; val = 0; for (i=0;i<v[nod].size();i++){ vecin = v[nod][i].first; val += sol[vecin].second + modul (x - sol[vecin].first - v[nod][i].second); } return val; } void dfs (long long nod){ long long i , vecin , s , val , st , dr , mid , op , x, y; for (i=0;i<v[nod].size();i++){ vecin = v[nod][i].first; sum[nod] += v[nod][i].second; dfs(vecin); } if (nod > n){ /// e exploziv sol[nod] = make_pair(0 , sum[nod]); /// 0 e timpul si sum[nod] e costul } else { /// e doar punct de intersectie s = 0; for (i=0;i<v[nod].size();i++){ vecin = v[nod][i].first; s += v[nod][i].second + sol[vecin].first; } /// fa cautare ternara st = 0; dr = 1000000000000000000; op = 0; while (op<=100){ mid = (st + dr)/2; x = check(mid-1 , nod); y = check(mid , nod); if (x < y) dr = mid; else st = mid; op++; } mid = (st + dr)/2; sol[nod] = make_pair(mid , check(mid , nod)); } } int main() { long long tot , i , x , y; fscanf (fin,"%lld%lld",&n,&m); tot = n + m; for (i=2;i<=tot;i++){ fscanf (fin,"%lld%lld",&x,&y); v[x].push_back(make_pair(i,y)); } dfs(1); fprintf (fout,"%lld",sol[1].second); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 8 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7416 KB | Output is correct |
4 | Correct | 9 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7416 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 8 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 9 ms | 7416 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 7416 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 8 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7416 KB | Output is correct |
4 | Correct | 9 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7416 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 8 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 9 ms | 7416 KB | Output is correct |
11 | Incorrect | 8 ms | 7416 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 7416 KB | Output is correct |
2 | Correct | 8 ms | 7416 KB | Output is correct |
3 | Correct | 9 ms | 7416 KB | Output is correct |
4 | Correct | 9 ms | 7416 KB | Output is correct |
5 | Correct | 9 ms | 7416 KB | Output is correct |
6 | Correct | 9 ms | 7416 KB | Output is correct |
7 | Correct | 8 ms | 7416 KB | Output is correct |
8 | Correct | 9 ms | 7416 KB | Output is correct |
9 | Correct | 9 ms | 7416 KB | Output is correct |
10 | Correct | 9 ms | 7416 KB | Output is correct |
11 | Incorrect | 8 ms | 7416 KB | Output isn't correct |
12 | Halted | 0 ms | 0 KB | - |