| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1349659 | retarde | Marathon Race 2 (JOI24_ho_t3) | C++20 | 1599 ms | 126568 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = (int)4e18;
const bool tc = false;
const int mxn = 2005;
int dp[mxn][mxn][2][2];
int x[mxn], cnt[mxn], ps[mxn];
inline void solve() {
int N, L;
cin >> N >> L;
vi tmp(N);
for (int i = 0; i < N; i++) cin >> tmp[i];
sort(all(tmp));
int n = 0;
for (int v : tmp) {
if (n == 0 || x[n] != v) {
x[++n] = v;
cnt[n] = 1;
} else {
cnt[n]++;
}
}
ps[0] = 0;
for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + cnt[i];
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j++) {
for (int k = 0; k < 2; k++) {
for (int t = 0; t < 2; t++) {
dp[i][j][k][t] = inf;
}
}
}
}
dp[1][n][0][0] = 0;
dp[1][n][1][1] = 0;
dp[1][n][0][1] = x[n] - x[1];
dp[1][n][1][0] = x[n] - x[1];
for (int len = n; len >= 2; len--) {
for (int l = 1; l + len - 1 <= n; l++) {
int r = l + len - 1;
int multL = N - (ps[r] - ps[l]) + 1;
int multR = N - (ps[r - 1] - ps[l - 1]) + 1;
for (int t = 0; t < 2; t++) {
dp[l + 1][r][0][t] = min(dp[l + 1][r][0][t],
dp[l][r][0][t] + multL * (x[l + 1] - x[l]));
dp[l + 1][r][1][t] = min(dp[l + 1][r][1][t],
dp[l][r][0][t] + multL * (x[r] - x[l]));
dp[l][r - 1][0][t] = min(dp[l][r - 1][0][t],
dp[l][r][1][t] + multR * (x[r] - x[l]));
dp[l][r - 1][1][t] = min(dp[l][r - 1][1][t],
dp[l][r][1][t] + multR * (x[r] - x[r - 1]));
}
}
}
int q;
cin >> q;
while (q--) {
int s, e, t;
cin >> s >> e >> t;
int ans = inf;
for (int j = 1; j <= n; j++) {
int ansL = min(dp[j][j][0][0], dp[j][j][1][0]) + abs(s - x[1]);
int ansR = min(dp[j][j][0][1], dp[j][j][1][1]) + abs(s - x[n]);
int f = (N + 1) * abs(x[j] - e);
int cur = min(ansL, ansR) + f;
ans = min(ans, cur);
}
ans += N;
// cout << ans << '\n';
cout << (ans <= t ? "Yes\n" : "No\n");
}
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
int t = 1;
if (tc) cin >> t;
while (t--) solve();
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
