답안 #1118191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1118191 2024-11-25T05:23:00 Z hphehe Bodyguard (JOI21_bodyguard) C++17
0 / 100
1863 ms 1658448 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 = 12004, bound2 = 6004;
    vector<vll> dp(bound1 + 5, vll(bound2 + 5, -1));
    vector<vi> best1(bound1 + 5, vi(bound2 + 5));
    vector<vi> best2 = best1;
    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){
                best1[t][x] = max(best1[t][x], c);
                ++t;
            }
        }
        else{
            for(int x = a - 1; x >= b; --x){
                best2[t][x] = max(best2[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] + best1[t][x - 1]);
            if(x + 1 <= bound2 && dp[t + 1][x + 1] != -1) f = max(f, dp[t + 1][x + 1] + best2[t][x]);
        }
    }
    while(q--){
        int p, x; cin >> p >> x;
        p *= 2, x *= 2;
        cout << max(0LL, 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
**/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1863 ms 1170308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1450 ms 1658448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1450 ms 1658448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1450 ms 1658448 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1863 ms 1170308 KB Output isn't correct
2 Halted 0 ms 0 KB -