제출 #1166814

#제출 시각아이디문제언어결과실행 시간메모리
1166814SmuggingSpunFireworks (APIO16_fireworks)C++20
7 / 100
4 ms328 KiB
#include<bits/stdc++.h> #define taskname "B" using namespace std; typedef long long ll; template<class T>bool minimize(T& a, T b){ if(a > b){ a = b; return true; } return false; } int n, m; namespace sub1{ void solve(){ vector<int>a(m); for(int& x : a){ cin >> x >> x; } sort(a.begin(), a.end()); int median = a[m >> 1]; ll ans = 0; for(int& x : a){ ans += abs(x - median); } cout << ans; } } namespace sub2{ const int lim = 305; const int INF = 1e9; vector<pair<int, int>>g[lim]; int ans = 0; vector<int>dfs(int s){ if(s > n){ return vector<int>(1, 0); } vector<vector<int>>a; for(auto& [d, w] : g[s]){ vector<int>value = dfs(d); for(int& x : value){ x += w; } a.emplace_back(value); } int opt = INF; vector<int>ret; for(int i = 0; i < 10001; i++){ int cur = 0; for(auto& ve : a){ int cost = INF; for(int& x : ve){ minimize(cost, abs(x - i)); } cur += cost; } if(minimize(opt, cur)){ ret.clear(); } if(opt == cur){ ret.emplace_back(i); } } ans += opt; return ret; } void solve(){ for(int i = 2; i <= n + m; i++){ int p, c; cin >> p >> c; g[p].emplace_back(i, c); } dfs(1); cout << ans; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> m; if(n == 1){ sub1::solve(); } else if(n + m <= 200){ sub2::solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

fireworks.cpp: In function 'int main()':
fireworks.cpp:79:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...