#pragma GCC optimize ("O3") #pragma GCC target ("avx") #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> A; vector>> plan; Bombplan(){} Bombplan(vector> AA):A(AA){ plan.resize(n,vector>(n)); greedy_all(); } //a[i][j]の爆破方法をランダムに決める void random_generate(int i,int j){ if(A[i][j]=='.') return; int k,x; do{ k = randInt(0,m-1); x = randInt(0,l[k]); }while(!is_valid(i-a[k][x],j-b[k][x])); plan[i][j] = make_tuple(k,i-a[k][x],j-b[k][x]); } //すべての位置の爆破方法をランダムに決める void random_all(){ for(int i=0;i> AA = A; int building = 0; 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> A; int center_shop_x; int center_shop_y; vector bomb; int bomb_sum=0; vector> hist; int building = 0; int shop = 0; ll cost=0; int nowx=0,nowy=0; queue que; State(){} State(vector> AA):A(AA){ bomb.resize(m); vpii tmp; int min_center_dist = inf; for(int i=0;iy_dist; }); for(auto e:tmp){ que.push(e); } } //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); else cost += 2*(bomb_sum+1)*(bomb_sum+1); } //x,y:目的地の座標 void move(int x,int y){ while(nowx!=x){ if(nowx=0 && i=0 && i=(double)INF){ for(int i=0;i=(double)INF){ int max_iter = (2500-building); for(int iter=0;iter> A; void IN(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>n>>m; A.resize(n); 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(){ State state(A); while(state.building>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:"<