제출 #691544

#제출 시각아이디문제언어결과실행 시간메모리
691544saayan007경주 (Race) (IOI11_race)C++17
31 / 100
394 ms196632 KiB
#include "race.h" #include <bits/stdc++.h> using namespace std; #warning notusing64bitint using ll = int; using pi = pair<int, int>; using pl = pair<int, int>; using vi = vector<int>; using vl = vector<int>; using vpi = vector<pair<int, int>>; using vpl = vector<pair<int, int>>; #define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i) #define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i) #define fr first #define sc second #define mp make_pair #define pb emplace_back #define nl "\n" #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const ll mxn = 2e5L + 1; ll k; vpl adj[mxn]; ll dp[mxn][101]; ll sm[mxn][101]; int ans = mxn; void dfs(ll cur, ll src) { for(auto [ch, wt] : adj[cur]) { if(ch != src) { dfs(ch, cur); fur(j, 1, k) { if(j - wt >= 0) { if(dp[cur][j] > 1 + dp[ch][j - wt]) { sm[cur][j] = dp[cur][j]; dp[cur][j] = 1 + dp[ch][j - wt]; } else if(sm[cur][j] > 1 + dp[ch][j - wt]) { sm[cur][j] = 1 + dp[ch][j - wt]; } } } } } dp[cur][0] = 0; } void solve(ll cur, ll src) { ans = min(ans, dp[cur][k]); for(auto [ch, wt] : adj[cur]) { if(ch != src) { fur(j, 1, k - 1) { if(j - wt < 0) continue; ll here = dp[ch][j - wt] + 1; ll there = dp[cur][k - j]; if(k - j - wt >= 0 && dp[ch][k - j - wt] + 1 == there) there = sm[cur][k - j]; ans = min(ans, here + there); } solve(ch, cur); } } } int best_path(int N, int K, int H[][2], int L[]) { k = K; fur(i, 0, N - 2) { ++H[i][0]; ++H[i][1]; adj[H[i][0]].pb(H[i][1], L[i]); adj[H[i][1]].pb(H[i][0], L[i]); } fur(i, 0, N) { fur(j, 0, k) { dp[i][j] = sm[i][j] = mxn; } } dfs(1, -1); // fur(i, 1, N) { // fur(j, 0, k) { // cout << dp[i][j] << ' '; // } // cout << nl; // } // cout << nl; // fur(i, 1, N) { // fur(j, 0, k) { // cout << sm[i][j] << ' '; // } // cout << nl; // } // cout << nl; solve(1, -1); if(ans == mxn) ans = -1; return ans; }

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

race.cpp:4:2: warning: #warning notusing64bitint [-Wcpp]
    4 | #warning notusing64bitint
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...