제출 #784097

#제출 시각아이디문제언어결과실행 시간메모리
784097ZHIRDILBILDIZ사이버랜드 (APIO23_cyberland)C++17
21 / 100
599 ms23016 KiB
#include<bits/stdc++.h> #include "cyberland.h" #define ll long long #define fi first #define se second using namespace std ; const int N = 1e5 ; bool us[N] ; double dist[N], ds[3][31] ; vector<int> abu ; vector<pair<int, int>> v[N] ; set<pair<double, int>> s ; set<pair<pair<double, int>, int>> pq ; void deikstra() { for(int i = 0 ; i < N ; i++) dist[i] = 1e18 ; for(auto i : s) dist[i.se] = 0 ; while(s.size()) { pair<double, int> p = *s.begin() ; s.erase(s.begin()) ; if(us[p.se]) continue ; us[p.se] = 1 ; for(auto i : v[p.se]) { if(us[i.fi] || dist[i.fi] <= p.fi + i.se) continue ; dist[i.fi] = p.fi + i.se ; s.insert({dist[i.fi], i.fi}) ; } } } void for_more_point(int n, int k) { for(int i = 0 ; i < n ; i++) for(int j = 0 ; j <= k ; j++) ds[i][j] = 1e18 ; ds[0][k] = 0 ; pq.insert({{0, 0}, k}) ; while(pq.size()) { auto p = *pq.begin() ; double dis = p.fi.fi ; int city = p.fi.se, kn = p.se ; pq.erase(pq.begin()) ; if(us[city]) continue ; for(auto i : v[city]) { if(dis + i.se < ds[i.fi][kn]) { ds[i.fi][kn] = dis + i.se ; pq.insert({{ds[i.fi][kn], i.fi}, kn}) ; } if(kn && !abu[i.fi] && ds[i.fi][kn - 1]) { ds[i.fi][kn - 1] = 0 ; pq.insert({{0, i.fi}, kn - 1}) ; } if(kn && abu[i.fi] == 2 && ds[i.fi][kn - 1] >= (dis + i.se) / 2) { ds[i.fi][kn - 1] = (dis + i.se) / 2 ; pq.insert({{ds[i.fi][kn - 1], i.fi}, kn - 1}) ; } } } } double solve(int n, int m, int k, int h, vector<int> x, vector<int> y, vector<int> c, vector<int> arr) { bool flag1 = 0, flag2 = 0, flag3 = 0 ; s.clear() ; for(int i = 0 ; i < n ; i++) { us[i] = 0 ; dist[i] = 0 ; v[i].clear() ; if(arr[i] != 1)flag1 = 1 ; if(arr[i] == 2)flag2 = 1 ; } for(int i = 0 ; i < m ; i++) { if(x[i] != i && y[i] != i + 1) v[x[i]].push_back({y[i], c[i]}) ; v[y[i]].push_back({x[i], c[i]}) ; } if(!flag1) { s.insert({0, 0}) ; deikstra() ; if(dist[h] == 1e18) return -1 ; else return dist[h] ; } if(!flag2) { us[h] = 1 ; s.insert({0, 0}) ; deikstra() ; for(int i = 0 ; i < n ; i++) { if(us[i] && !arr[i] || !i) s.insert({0, i}) ; us[i] = 0 ; } deikstra() ; if(dist[h] == 1e18) return -1 ; else return dist[h] ; } if(!flag3 && m == n - 1) { double ans = 0 ; double pref[m] = {} ; pref[0] = c[0] ; deque<int> d[3] ; d[0].push_back(0) ; for(int i = 0 ; i < n ; i++) d[arr[i]].push_back(i) ; d[1].clear() ; while(d[0].size() > 1) d[0].pop_front() ; while(d[2].size() && d[2][0] < d[0][0]) d[2].pop_front() ; for(int i = 1 ; i < m ; i++) pref[i] = pref[i - 1] + c[i] ; int ls = -1 ; for(int i : d[2]) { if(ls != -1) ans = (ans + pref[i - 1] - pref[ls]) / 2 ; else ans = (ans + pref[i - 1]) / 2 ; ls = i - 1 ; } return ans ; } if(n <= 3) { abu = arr ; us[h] = 1 ; for_more_point(n, k) ; double ans = 1e18 ; for(int i = 0 ; i <= k ; i++) ans = min(ans, ds[h][i]) ; if(ans == 1e18)return -1 ; else return ans ; } } //signed main() //{ // freopen("rsub4_01.in", "r", stdin) ; // ios_base::sync_with_stdio( 0 ) ; // cin.tie( 0 ) ; // cout.tie( 0 ) ; // int t ; // cin >> t ; // while(t--) // { // int n, m, k, h ; // cin >> n >> m >> k >> h ; // vector<int> a(m), b(m), c(m), arr(n) ; // for(int i = 0 ; i < n ; i++) // cin >> arr[i] ; // for(int i = 0 ; i < m ; i++) // cin >> a[i] >> b[i] >> c[i] ; // cout << fixed << setprecision(9) << solve(n, m, k, h, a, b, c, arr) << '\n' ; // } // return 0 ; //}

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

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:105:22: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  105 |             if(us[i] && !arr[i] || !i)
cyberland.cpp:153:1: warning: control reaches end of non-void function [-Wreturn-type]
  153 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...