Submission #1214733

#TimeUsernameProblemLanguageResultExecution timeMemory
1214733trimkusMarathon Race 2 (JOI24_ho_t3)C++20
62 / 100
1594 ms31944 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int a[2000]; int n; int dp[2000][2000][2]; int solve_better(int left, int right, int g, int side) { if (left > right) { if (side == 0) { return (n + 1) * abs(a[left - 1] - g); } return (n + 1) * abs(a[right + 1] - g); } if (dp[left][right][side] != -1) return dp[left][right][side]; int cnt = 1 + left + (n - right - 1); int pos = -1; if (side == 0) { pos = a[left - 1]; } else { pos = a[right + 1]; } return dp[left][right][side] = min(solve_better(left + 1, right, g, 0) + cnt * abs(pos - a[left]), solve_better(left, right - 1, g, 1) + cnt * abs(pos - a[right])); } int main() { ios::sync_with_stdio(0); cin.tie(0); int l; cin >> n >> l; for (int i = 0; i < n; ++i) { int x; cin >> x; a[i] = x; } sort(a, a + n); int q; cin >> q; while (q--) { int s, g, t; cin >> s >> g >> t; //~ int exp = brute(s, g); int best = INT_MAX; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) for (int k = 0; k < 2; ++k) dp[i][j][k] = -1; best = solve_better(1, n - 1, g, 0) + abs(s - a[0]); best = min(best, solve_better(0, n - 2, g, 1) + abs(s - a[n - 1])); best += n; //~ cout << exp << " ?= " << best << "\n"; cout << (best <= t ? "Yes\n" : "No\n"); } }
#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...