Submission #1273730

#TimeUsernameProblemLanguageResultExecution timeMemory
1273730icebearMarathon Race 2 (JOI24_ho_t3)C++20
100 / 100
130 ms19708 KiB
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class T>
    bool minimize(T &a, const T &b) {
        if (a > b) return a = b, true;
        return false;
    }

template<class T>
    bool maximize(T &a, const T &b) {
        if (a < b) return a = b, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"

const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 5e5 + 5;
int n, q, m, l, x[N];
int p[N], w[N];
ll f[2][1005][1005];

int sum(int i, int j) {
    return n + 1 - w[j] + w[i - 1];
}

void init(void) {
    cin >> n >> l;
    FOR(i, 1, n) cin >> x[i];
    cin >> q;
}

void process(void) {
    sort(x + 1, x + n + 1);
    int j = 1, i = 1;
    while(i <= n) {
        while(j <= n && x[i] == x[j]) j++;
        m++;
        p[m] = x[i];
        w[m] = j - i;
        i = j;
    }
    FOR(i, 1, m) w[i] += w[i - 1];

    if (m > 1000) {
        while(q--) {
            cout << "No\n";
        }
        exit(0);
    }

    memset(f, 0x3f, sizeof f);
    f[0][1][m] = f[1][m][1] = 0;

    REP(k, 2) FORR(len, m, 2) FOR(i, 1, m - len + 1) {
        int j = i + len - 1;
        minimize(f[k][i + 1][j], f[k][i][j] + 1LL * (p[i + 1] - p[i]) * sum(i + 1, j));
        minimize(f[k][i][j - 1], f[k][j][i] + 1LL * (p[j] - p[i]) * sum(i, j - 1));
        minimize(f[k][j][i + 1], f[k][i][j] + 1LL * (p[j] - p[i]) * sum(i + 1, j));
        minimize(f[k][j - 1][i], f[k][j][i] + 1LL * (p[j] - p[j - 1]) * sum(i, j - 1));
    }

    while(q--) {
        int S, T, G;
        cin >> S >> T >> G;
        int pos = lower_bound(p + 1, p + m + 1, T) - p;
        ll ans = INF;
        REP(k, 2) FOR(i, max(1, pos - 1), min(m, pos + 1)) {
            ll cost = f[k][i][i] + 1LL * abs(p[i] - T) * (n + 1);
            cost += abs(S - p[k == 0 ? 1 : m]);
            minimize(ans, cost);
        }
        cout << (ans + n <= G ? "Yes\n" : "No\n");
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while(tc--) {
        init();
        process();
    }
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...