結果

問題 No.5017 Tool-assisted Shooting
ユーザー FplusFplusFFplusFplusF
提出日時 2023-07-16 19:11:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 8,171 bytes
コンパイル時間 3,830 ms
コンパイル使用メモリ 239,040 KB
実行使用メモリ 34,268 KB
スコア 0
最終ジャッジ日時 2023-07-16 19:11:55
合計ジャッジ時間 10,368 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
testcase_94 -- -
testcase_95 -- -
testcase_96 -- -
testcase_97 -- -
testcase_98 -- -
testcase_99 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
using pii=pair<int,int>;
using tii=tuple<int,int,int>;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int H=60,W=25;
struct Input{
    int n;
    vector<int> h,p,x;
    void input_cin(){
        cin >> n;
        if(n==-1) exit(0);
        h.assign(n,0);
        p.assign(n,0);
        x.assign(n,0);
        rep(i,n) cin >> h[i] >> p[i] >> x[i];
    }
}Input;
struct shooter{
    int j;
    int l;
    int s;
};
struct enemy{
    int fh;
    int h;
    int p;
};
struct state{
    int turn;
    int point;
    vector<vector<enemy>> grid;
    shooter me;
    string root;
};
bool operator<(const state &a,const state &b){
    return (double)a.point/(double)a.turn<(double)b.point/(double)b.turn;
}
struct solver{
    string beam_search(state first_state,int width,int depth){
        priority_queue<state> now_beam,copy_now_beam;
        now_beam.push(first_state);
        rep(d,depth){
            copy_now_beam=now_beam;
            priority_queue<state> next_beam;
            rep(w,width){
                if(now_beam.empty()) break;
                state now_state=now_beam.top();
                now_beam.pop();
                rep(i,H){
                    rep(j,W){
                        if(0<now_state.grid[i][j].h){
                            bool ok=true;
                            for(int k=i+1;k<H;k++){
                                if(0<now_state.grid[k][j].h) ok=false;
                            }
                            if(!ok) continue;
                            int n=H-i,z=abs(j-now_state.me.j);
                            vector<vector<pii>> dp(n+1,vector<pii>(z+1,{-1,-1}));
                            dp[0][0]={-2,-2};
                            rep(ii,n){
                                rep(jj,z+1){
                                    if(dp[ii][jj]==pair<int,int>({-1,-1})) continue;
                                    if(now_state.me.j<j){
                                        if(0<=H-1-ii&&H-1-ii<H&&0<=H-1-(ii+1)&&H-1-(ii+1)<H&&now_state.grid[H-1-ii][now_state.me.j+jj].h==0&&now_state.grid[H-1-(ii+1)][now_state.me.j+jj].h==0) dp[ii+1][jj]={ii,jj};
                                        if(jj+1<=z&&0<=H-1-ii&&H-1-ii<H&&0<=H-1-(ii+1)&&H-1-(ii+1)<H&&now_state.grid[H-1-ii][now_state.me.j+(jj+1)].h==0&&now_state.grid[H-1-(ii+1)][now_state.me.j+(jj+1)].h==0) dp[ii+1][jj+1]={ii,jj};
                                    }else{
                                        if(0<=H-1-ii&&H-1-ii<H&&0<=H-1-(ii+1)&&H-1-(ii+1)<H&&now_state.grid[H-1-ii][now_state.me.j-jj].h==0&&now_state.grid[H-1-(ii+1)][now_state.me.j-jj].h==0) dp[ii+1][jj]={ii,jj};
                                        if(jj+1<=z&&0<=H-1-ii&&H-1-ii<H&&0<=H-1-(ii+1)&&H-1-(ii+1)<H&&now_state.grid[H-1-ii][now_state.me.j-(jj+1)].h==0&&now_state.grid[H-1-(ii+1)][now_state.me.j-(jj+1)].h==0) dp[ii+1][jj+1]={ii,jj};
                                    }
                                }
                            }
                            int tx=-1;
                            pii pa={-1,-1};
                            rep(ii,n+1){
                                if(dp[ii][z]!=pair<int,int>({-1,-1})){
                                    tx=ii;
                                    pa={ii,z};
                                    break;
                                }
                            }
                            
                            if(tx==-1||0<now_state.grid[i][j].h-(H-1-i-tx)*now_state.me.l) continue;
                            state new_state=now_state;
                            int nt=tx+(now_state.grid[i][j].h+now_state.me.l-1)/now_state.me.l;
                            string now_root;
                            while(pa!=pair<int,int>({0,0})){
                                pii new_pa=dp[pa.first][pa.second];
                                if(new_pa.second!=pa.second){
                                    if(new_state.me.j<j) now_root.push_back('R');
                                    else now_root.push_back('L');
                                }else{
                                    now_root.push_back('S');
                                }
                                pa=new_pa;
                            }
                            reverse(all(now_root));
                            rep(ii,nt-tx) now_root.push_back('S');
                            for(auto &c:now_root){
                                new_state.turn++;
                                if(c=='L') new_state.me.j--;
                                if(c=='R') new_state.me.j++;
                                for(int ii=H-1;0<=ii;ii--){
                                    rep(jj,W){
                                        new_state.grid[ii][jj]={0,0,0};
                                        if(0<=ii-1) new_state.grid[ii][jj]=new_state.grid[ii-1][jj];
                                    }
                                }
                                for(int i=H-2;0<=i;i--){
                                    if(0<new_state.grid[i][new_state.me.j].h){
                                        new_state.grid[i][new_state.me.j].h-=new_state.me.l;
                                        if(new_state.grid[i][new_state.me.j].h<=0){
                                            new_state.point+=new_state.grid[i][new_state.me.j].fh;
                                            new_state.grid[i][new_state.me.j].fh=0;
                                            new_state.grid[i][new_state.me.j].h=0;
                                            new_state.me.s+=new_state.grid[i][new_state.me.j].p;
                                            new_state.grid[i][new_state.me.j].p=0;
                                        }
                                        break;
                                    }
                                }
                                new_state.me.l=1+new_state.me.s/100;
                            }
                            new_state.root+=now_root;
                            next_beam.push(new_state);
                        }
                    }
                }
                if(next_beam.empty()){
                    return copy_now_beam.top().root;
                }
                now_beam=next_beam;
                
            }
        }
        return now_beam.top().root;
    }
    void solve(){
        int score=0;
        shooter me={12,1,0};
        vector<vector<enemy>> grid(H,vector<enemy>(W,{0,0,0}));
        string root;
        rep(t,1000){
            for(int i=H-2;0<=i;i--){
                rep(j,W){
                    grid[i+1][j]=grid[i][j];
                    grid[i][j]={0,0,0};
                }
            }
            Input.input_cin();
            rep(i,Input.n){
                grid[0][Input.x[i]].fh=Input.h[i];
                grid[0][Input.x[i]].h=Input.h[i];
                grid[0][Input.x[i]].p=Input.p[i];
            }
            state first_state={0,0,grid,me,""};
                root=beam_search(first_state,2,2);
                reverse(all(root));
            if(root.empty()){
                cout << "S" << endl;
            }else{
                cout << root.back() << endl;
                if(root.back()=='L') me.j--;
                if(root.back()=='R') me.j++;
                root.pop_back();
            }
            for(int i=H-2;0<=i;i--){
                if(0<grid[i][me.j].h){
                    grid[i][me.j].h-=me.l;
                    if(grid[i][me.j].h<=0){
                        score+=grid[i][me.j].fh;
                        grid[i][me.j].fh=0;
                        grid[i][me.j].h=0;
                        me.s+=grid[i][me.j].p;
                        grid[i][me.j].p=0;
                    }
                    break;
                }
            }
            me.l=1+me.s/100;
        }
    }
}Solver;
int main(){
    //提出時消す
    rep(i,25){
        int p;
        cin >> p;
    }
    Solver.solve();
}
0