Submission #1004804

#TimeUsernameProblemLanguageResultExecution timeMemory
1004804victor_gaoMarathon Race 2 (JOI24_ho_t3)C++17
62 / 100
1574 ms133012 KiB
//#pragma GCC optimize("Ofast,unroll-loops,O3") //#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native") #include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define x first #define y second #define N 2015 using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, L, arr[N], dpl[N][N][2], dpr[N][N][2]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cin >> n >> L; for (int i = 1; i <= n; i++) cin >> arr[i]; sort(arr + 1, arr + 1 + n); for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++){ dpl[i][j][0] = dpl[i][j][1] = 5e18; dpr[i][j][0] = dpr[i][j][1] = 5e18; } dpl[1][n][0] = 0, dpl[1][n][1] = arr[n] - arr[1]; dpr[1][n][0] = arr[n] - arr[1], dpr[1][n][1] = 0; for (int j = n - 1; j >= 1; j--){ for (int i = 1; i <= n - j + 1; i++){ dpl[i][j][0] = dpl[i - 1][j + 1][0] + (arr[i] - arr[i - 1]) * (n - j + 1); dpl[i][j][1] = dpl[i][j + 1][1] + (arr[i + j] - arr[i + j - 1]) * (n - j + 1); dpl[i][j][0] = min(dpl[i][j][0], dpl[i][j][1] + (arr[i + j - 1] - arr[i]) * (n - j + 1)); dpl[i][j][1] = min(dpl[i][j][1], dpl[i][j][0] + (arr[i + j - 1] - arr[i]) * (n - j + 1)); dpr[i][j][0] = dpr[i - 1][j + 1][0] + (arr[i] - arr[i - 1]) * (n - j + 1); dpr[i][j][1] = dpr[i][j + 1][1] + (arr[i + j] - arr[i + j - 1]) * (n - j + 1); dpr[i][j][0] = min(dpr[i][j][0], dpr[i][j][1] + (arr[i + j - 1] - arr[i]) * (n - j + 1)); dpr[i][j][1] = min(dpr[i][j][1], dpr[i][j][0] + (arr[i + j - 1] - arr[i]) * (n - j + 1)); } } // cerr << "from left :\n"; // for (int i = 1; i <= n; i++){ // for (int j = i; j <= n; j++){ // cerr << i << " ~ " << j << " -> " << dpl[i][j - i + 1][0] << ", " << dpl[i][j - i + 1][1] << '\n'; // } // } // cerr << "from right :\n"; // for (int i = 1; i <= n; i++){ // for (int j = i; j <= n; j++){ // cerr << i << " ~ " << j << " -> " << dpr[i][j - i + 1][0] << ", " << dpr[i][j - i + 1][1] << '\n'; // } // } int q; cin >> q; while (q--){ int s, t, T, ans = 5e18; cin >> s >> t >> T; for (int i = 1; i <= n; i++){ int ans1 = dpl[i][1][0] + abs(arr[i] - t) * (n + 1) + abs(arr[1] - s); int ans2 = dpr[i][1][0] + abs(arr[i] - t) * (n + 1) + abs(arr[n] - s); ans = min({ans, ans1, ans2}); } if (ans + n <= T) cout << "Yes\n"; else cout << "No\n"; // cout << ans + n << " " << T << '\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...