結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー fumofumofunifumofumofuni
提出日時 2023-08-18 23:59:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,772 bytes
コンパイル時間 2,432 ms
コンパイル使用メモリ 211,908 KB
実行使用メモリ 356,028 KB
最終ジャッジ日時 2023-08-18 23:59:50
合計ジャッジ時間 5,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 24 ms
24,664 KB
testcase_04 AC 27 ms
24,256 KB
testcase_05 AC 23 ms
23,464 KB
testcase_06 AC 26 ms
25,172 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 399 ms
355,696 KB
testcase_11 AC 370 ms
355,776 KB
testcase_12 AC 429 ms
356,028 KB
testcase_13 AC 369 ms
355,776 KB
testcase_14 AC 372 ms
355,660 KB
testcase_15 AC 28 ms
29,420 KB
testcase_16 AC 27 ms
29,012 KB
testcase_17 AC 27 ms
29,380 KB
testcase_18 AC 28 ms
29,336 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,h,x;cin >> n >> h >> x;if(h>3000)h=3000;
    vl valid;
    ll g;cin >> g;
    vl gs(g);
    rep(i,g){
        ll x;cin >> x;gs[i]=x;
        for(ll i=-8;i<=8;i++){
            if(x+i>=0&&x+i<=n)valid.emplace_back(x+i);
        }
    }
    ll b;cin >> b;
    vl bs(b);
    rep(i,b){
        ll x;cin >> x;bs[i]=x;
        for(ll i=-8;i<=8;i++){
            if(x+i>=0&&x+i<=n)valid.emplace_back(x+i);
        }
    }
    valid.emplace_back(0);valid.emplace_back(n);
    sort(all(valid));valid.erase(unique(all(valid)),valid.end());
    ll m=valid.size();
    vvl dp(m,vl(h+1,-INF));dp[0][0]=0;
    //return 0;
    rep(i,m-1){
        ll to=valid[i+1];
        if(binary_search(all(gs),to)){
            rep(j,h+1){
                chmax(dp[i+1][j],dp[i][j]+1);
            }
        }
        else if(binary_search(all(bs),to)){
            rep(j,h+1){
                chmax(dp[i+1][j],dp[i][j]-1);
            }
        }
        else {
            rep(j,h+1){
                chmax(dp[i+1][j],dp[i][j]);
            }
        }
        ll nx=valid[i]+x;
        ll idx=-1;
        for(ll j=i;j<m;j++){
            if(nx<valid[j])break;
            if(nx==valid[j])idx=j;
        }
        to=nx;
        if(idx==-1)continue;
        if(binary_search(all(gs),to)){
            rep(j,h){
                chmax(dp[idx][j+1],dp[i][j]+1);
            }
        }
        else if(binary_search(all(bs),to)){
            rep(j,h){
                chmax(dp[idx][j+1],dp[i][j]-1);
            }
        }
        else {
            rep(j,h){
                chmax(dp[idx][j+1],dp[i][j]);
            }
        }
    }
    cout << *max_element(all(dp[m-1])) << endl;
}



0