Submission #1118176

# Submission time Handle Problem Language Result Execution time Memory
1118176 2024-11-25T04:58:06 Z hphehe Bodyguard (JOI21_bodyguard) C++17
0 / 100
2642 ms 2097156 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
#define FOR(i, a) for (int i=0; i<(a); i++)
#define all(x) x.begin(), x.end()
#define gcd __gcd
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
//const int dr[4] = {-1, 0, 1, 0}, dc[4] = {0, 1, 0, -1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 3005;
struct motor{
    int t, a, b, c;
} xe[N];

int n, q;

void sub1(){
    int bound1 = 24004, bound2 = 6004;
    vector<vll> dp(bound1 + 5, vll(bound2 + 5, -1));
    vector<vi> best(bound1 + 5, vi(bound2 + 5));
    for(int i = 1; i <= n; ++i){
        int t = xe[i].t, a = xe[i].a, b = xe[i].b, c = xe[i].c;
        t *= 2, a *= 2, b *= 2;
        c /= 2;
        if(a <= b){
            for(int x = a; x < b; ++x){
                best[t][x] = max(best[t][x], c);
                ++t;
            }
        }
        else{
            for(int x = a - 1; x >= b; --x){
                best[t][x] = max(best[t][x], c);
                ++t;
            }
        }
    }
    dp[bound1][1] = 0;
    for(int t = bound1 - 1; t >= 0; --t){
        for(int x = 1; x <= bound2; ++x){
            ll &f = dp[t][x];
            if(dp[t + 1][x] != -1) f = max(f, dp[t + 1][x]);
            if(x - 1 >= 0 && dp[t + 1][x - 1] != -1) f = max(f, dp[t + 1][x - 1] + best[t][x - 1]);
            if(x + 1 <= bound2 && dp[t + 1][x + 1] != -1) f = max(f, dp[t + 1][x + 1] + best[t][x]);
        }
    }
    while(q--){
        int p, x; cin >> p >> x;
        p *= 2, x *= 2;
        cout << dp[p][x] << "\n";
    }
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; ++i){
        int t, a, b, c; cin >> t >> a >> b >> c;
        xe[i] = {t, a, b, c};
    }
    sub1();
    return 0;
}
/**
2 2
1 2 1 4
3 1 3 2
1 2
3 3

3 2
3 1 5 2
1 4 1 4
4 2 4 4
2 2
6 3
**/
# Verdict Execution time Memory Grader output
1 Incorrect 2642 ms 1756096 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2561 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2561 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2561 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2642 ms 1756096 KB Output isn't correct
2 Halted 0 ms 0 KB -