結果
| 問題 |
No.5017 Tool-assisted Shooting
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2023-07-16 19:11:44 |
| 言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 99 |
ソースコード
#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();
}
FplusFplusF