제출 #407191

#제출 시각아이디문제언어결과실행 시간메모리
407191rocks03Shortcut (IOI16_shortcut)C++14
23 / 100
2087 ms292 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define pb push_back #define SZ(x) ((int)(x).size()) #define all(x) x.begin(), x.end() #define debug(x) cout << #x << ": " << x << " " #define nl cout << "\n" #define rep(i, a, b) for(int i = (a); i <= (b); i++) #define per(i, a, b) for(int i = (a); i >= (b); i--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long find_shortcut(int N, vector<int> l, vector<int> p, int C){ vector<ll> D(N), P(N); rep(i, 0, N - 1){ if(i) D[i] = D[i - 1] + l[i - 1]; P[i] = p[i]; } auto dist = [&](int i, int j, int l, int r){ ll ans; if(i == j){ ans = 0; return ans; } if(i <= j && j <= l && l <= r){ ans = (D[j] + P[j]) - (D[i] - P[i]); return ans; } if(i <= l && l <= j && j <= r){ ans = min(D[j], D[l] + C + D[r] - D[j]) - (D[i] - P[i]) + P[j]; return ans; } if(i <= l && l <= r && r <= j){ ans = min(D[j], D[l] + C + D[j] - D[r]) - (D[i] - P[i]) + P[j]; return ans; } if(l <= i && i <= r && r <= j){ ans = D[j] + min(-D[i], +D[i] - D[l] - D[r] + C) + P[j] + P[i]; return ans; } if(l <= r && r <= i && i <= j){ ans = (D[j] + P[j]) - (D[i] - P[i]); return ans; } if(l <= i && i <= j && j <= r){ ans = min(D[i] - D[l] + C + D[r] - D[j], D[j] - D[i]) + P[j] + P[i]; return ans; } assert(false); return ans; }; auto diameter = [&](int l, int r){ ll ans = 0; rep(i, 0, N - 1){ rep(j, i + 1, N - 1){ ans = max(ans, dist(i, j, l, r)); } } return ans; }; ll ans = LLONG_MAX; rep(i, 0, N - 1){ rep(j, i + 1, N - 1){ ans = min(ans, diameter(i, j)); } } return ans; }
#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...