#pragma GCC optimize("O3") #include using namespace std; #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define print(var) std::cout<<#var<<"="<<(var)< #define vvi vector #define vvvi vector #define ll long long #define vll vector #define vvll vector #define vvvll vector #define vmi vector #define vvmi vector #define vvvmi vector #define vs vector #define pii pair #define vpii vector> #define bit(x,i)(((x)>>(i))&1) #define inf (1<<30) #define INF (1ll<<60) template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } inline double get_time() { using namespace std::chrono; return duration_cast(system_clock::now().time_since_epoch()).count(); } unsigned long xor128(void){ static unsigned long x=123456789,y=362436069,z=521288629,w=88675123; unsigned long t; t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } long long randInt(long long a,long long b){return a+xor128()%(b-a+1);} double randDouble(double a,double b){return a+(b-a)*xor128()/(double)ULONG_MAX;} double start_time; int n,m; int c[20],l[20]; vector a[20],b[20]; bool is_valid(int x,int y){ return 0<=x && x plan[50][50]; Bombplan(){} Bombplan(char AA[50][50]){ for(int i=0;i0){ int best_i,best_j,best_k; double best = (double)INF; for(int iter=0;iter<10000;iter++){ int i = randInt(0,n-1); int j = randInt(0,n-1); int k = randInt(0,m-1); int broken_cnt = 0; for(int x=0;x> dicided(n,vector(n)); vector que; for(int i=0;i> explode_list(){ set> res; for(int i=0;i> hist; int building = 0; int shop = 0; ll cost=0; int buy_cost=0; int move_cost=0; int nowx=0,nowy=0; queue que; State(){} State(char AA[50][50]){ for(int i=0;iy_dist; }); for(auto e:tmp){ que.push(e); } } pair> smart_route(int sx,int sy,int gx,int gy){ char x_ope = gx>sx ? 'D' : 'U'; int dx = gx>sx ? 1 : -1; char y_ope = gy>sy ? 'R' : 'L'; int dy = gy>sy ? 1 : -1; vvi dp(abs(gx-sx)+1,vi(abs(gy-sy)+1,inf)); dp[0][0] = 0; for(int i=0;i<=abs(gx-sx);i++)for(int j=0;j<=abs(gy-sy);j++){ if(i+1<=abs(gx-sx)){ chmin(dp[i+1][j],dp[i][j]+(A[sx+dx*(i+1)][sy+dy*j]!='.')+1); } if(j+1<=abs(gy-sy)){ chmin(dp[i][j+1],dp[i][j]+(A[sx+dx*i][sy+dy*(j+1)]!='.')+1); } } //dpから最短経路を復元 vector res(abs(gx-sx) + abs(gy-sy)); int i=abs(gx-sx),j=abs(gy-sy); int index = res.size() - 1; while(i>0 || j>0){ if(i>0 && dp[i-1][j]+(A[sx+dx*i][sy+dy*j]!='.')+1==dp[i][j]){ res[index] = x_ope; i--; } else{ res[index] = y_ope; j--; } index--; } int cost = dp[abs(gx-sx)][abs(gy-sy)]; return make_pair(cost,res); } //d:方向 void move(char d){ if(d=='U'){ hist.emplace_back(make_pair(1,0)); nowx--; } if(d=='D'){ hist.emplace_back(make_pair(1,1)); nowx++; } if(d=='L'){ hist.emplace_back(make_pair(1,2)); nowy--; } if(d=='R'){ hist.emplace_back(make_pair(1,3)); nowy++; } if(A[nowx][nowy]=='.'){ cost += (bomb_sum+1)*(bomb_sum+1); move_cost += (bomb_sum+1)*(bomb_sum+1); } else{ cost += 2*(bomb_sum+1)*(bomb_sum+1); move_cost += 2*(bomb_sum+1)*(bomb_sum+1); } } //x,y:目的地の座標 void move(int x,int y){ pair> route_result = smart_route(nowx, nowy, x, y); for (char direction : route_result.second) { move(direction); } } //piiに対応する座標に移動する void move(pii p){ move(p.first,p.second); } //爆弾を買う //i:爆弾の種類 void buy(int i){ assert(i>=0 && i=0 && i use_simulate(int i,int x,int y){ assert(i>=0 && i=(double)INF){ for(int i=0;i=(double)INF){ int max_iter = 5000; for(int iter=0;iterbroken_building) return (double)INF; else{ double eval = (double)usecost/(double)broken_building; if(center_shop_broken) eval *= 10; return eval; } } //差分評価 double diff_eval(State now, State nex){ int broken_building = now.building - nex.building; int usecost = nex.cost - now.cost; if(broken_building==0) return (double)INF; else if(nex.shop==0 && nex.building!=0) return (double)INF; else{ double eval = (double)usecost/(double)broken_building; if(nex.A[nex.center_shop_x][nex.center_shop_y]!='@') eval *= 10; return eval; } } //出力 void output(){ cout<>n>>m; for(int i=0;i>A[i][j]; } } for(int i=0;i>c[i]>>l[i]; for(int j=0;j>tmpa>>tmpb; a[i].emplace_back(tmpa); b[i].emplace_back(tmpb); } } } void solve(){ /* Bombplan bombplan(A); cerr<0){ state.one_step2(); cerr<1900) break; Bombplan new_bombplan = bombplan; new_bombplan.random_trans_plan(); int pre_score = bombplan.eval(); int new_score = new_bombplan.eval(); //温度関数 double temp = start_temp + (end_tmp-start_temp)*(now_time-start)/1900; //遷移確率関数 double prob = exp((pre_score-new_score)/temp); //遷移回数 if(prob>randDouble(0,1)){ //遷移 bombplan = new_bombplan; trans_cnt++; if(iter%500==1){ cerr<<"iter:"<