結果
問題 |
No.5017 Tool-assisted Shooting
|
ユーザー |
![]() |
提出日時 | 2023-07-16 19:18:17 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,521 ms / 2,000 ms |
コード長 | 7,135 bytes |
コンパイル時間 | 3,419 ms |
コンパイル使用メモリ | 239,520 KB |
実行使用メモリ | 25,620 KB |
スコア | 3,588,007 |
平均クエリ数 | 1000.00 |
最終ジャッジ日時 | 2023-07-16 19:20:48 |
合計ジャッジ時間 | 143,838 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge9 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 100 |
ソースコード
#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; new_state.turn+=nt; new_state.point+=now_state.grid[i][j].fh; new_state.me.l=1+new_state.point/100; new_state.grid[i][j]={0,0,0}; for(int ii=H-1;0<=ii;ii--){ rep(jj,W){ new_state.grid[ii][jj]={0,0,0}; if(0<=ii-nt) new_state.grid[ii][jj]=new_state.grid[ii-nt][jj]; } } 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'); new_state.root+=now_root; //cerr << new_state.root << endl; 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,5,5); 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(){ Solver.solve(); }