結果
問題 | No.5016 Worst Mayor |
ユーザー | FplusFplusF |
提出日時 | 2023-04-29 16:52:30 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,724 ms / 2,000 ms |
コード長 | 6,125 bytes |
コンパイル時間 | 3,353 ms |
コンパイル使用メモリ | 239,404 KB |
実行使用メモリ | 284,132 KB |
スコア | 20,132,671,845 |
平均クエリ数 | 400.00 |
最終ジャッジ日時 | 2023-04-29 16:55:35 |
合計ジャッジ時間 | 87,924 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,538 ms
284,056 KB |
testcase_01 | AC | 1,618 ms
283,408 KB |
testcase_02 | AC | 1,525 ms
283,280 KB |
testcase_03 | AC | 1,611 ms
283,816 KB |
testcase_04 | AC | 1,506 ms
283,416 KB |
testcase_05 | AC | 1,473 ms
283,264 KB |
testcase_06 | AC | 1,664 ms
283,396 KB |
testcase_07 | AC | 1,695 ms
283,848 KB |
testcase_08 | AC | 1,461 ms
283,380 KB |
testcase_09 | AC | 1,426 ms
283,424 KB |
testcase_10 | AC | 1,500 ms
283,856 KB |
testcase_11 | AC | 1,717 ms
283,616 KB |
testcase_12 | AC | 1,707 ms
283,724 KB |
testcase_13 | AC | 1,607 ms
283,628 KB |
testcase_14 | AC | 1,585 ms
283,388 KB |
testcase_15 | AC | 1,525 ms
283,752 KB |
testcase_16 | AC | 1,546 ms
283,396 KB |
testcase_17 | AC | 1,450 ms
283,308 KB |
testcase_18 | AC | 1,626 ms
283,384 KB |
testcase_19 | AC | 1,296 ms
284,132 KB |
testcase_20 | AC | 1,666 ms
283,844 KB |
testcase_21 | AC | 1,641 ms
283,936 KB |
testcase_22 | AC | 1,543 ms
283,696 KB |
testcase_23 | AC | 1,462 ms
283,304 KB |
testcase_24 | AC | 1,574 ms
283,948 KB |
testcase_25 | AC | 1,638 ms
283,320 KB |
testcase_26 | AC | 1,706 ms
283,792 KB |
testcase_27 | AC | 1,585 ms
283,296 KB |
testcase_28 | AC | 1,545 ms
283,796 KB |
testcase_29 | AC | 1,548 ms
283,852 KB |
testcase_30 | AC | 1,624 ms
283,432 KB |
testcase_31 | AC | 1,663 ms
283,840 KB |
testcase_32 | AC | 1,642 ms
283,724 KB |
testcase_33 | AC | 1,599 ms
284,116 KB |
testcase_34 | AC | 1,706 ms
283,452 KB |
testcase_35 | AC | 1,614 ms
283,796 KB |
testcase_36 | AC | 1,643 ms
283,344 KB |
testcase_37 | AC | 1,695 ms
283,244 KB |
testcase_38 | AC | 1,708 ms
283,524 KB |
testcase_39 | AC | 1,724 ms
283,640 KB |
testcase_40 | AC | 1,626 ms
283,476 KB |
testcase_41 | AC | 1,693 ms
283,332 KB |
testcase_42 | AC | 1,626 ms
283,952 KB |
testcase_43 | AC | 1,531 ms
283,664 KB |
testcase_44 | AC | 1,642 ms
283,844 KB |
testcase_45 | AC | 1,669 ms
283,608 KB |
testcase_46 | AC | 1,281 ms
283,316 KB |
testcase_47 | AC | 1,683 ms
283,580 KB |
testcase_48 | AC | 1,541 ms
284,004 KB |
testcase_49 | AC | 1,644 ms
283,836 KB |
ソースコード
#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; } } vector<int> pi={0,0,1,-1},pj={1,-1,0,0}; int to(int i,int j){ return i*14+j; } int to2(int i,int j){ return i*14*14+j; } pii back(int x){ return {x/14,x%14}; } struct input{ int n,t; vector<int> s,g; void input_cin(){ cin >> n >> t; s.resize(n); g.resize(n); rep(i,n){ int a,b,c,d; cin >> a >> b >> c >> d; a--; b--; c--; d--; s[i]=to(a,b); g[i]=to(c,d); } } }input; struct solver{ vector<int> people; pair<vector<int>,int> dijkstra(vector<vector<pii>> &g){ int score=0; vector<int> root_cnt(14*14*14*14,0); rep(i,14*14){ vector<int> dist(14*14,INF); vector<int> prev(14*14); priority_queue<pii> pq; dist[i]=0; pq.push({i,i}); while(!pq.empty()){ int x,d; tie(x,d)=pq.top(); pq.pop(); for(auto &[to,w]:g[x]){ if(dist[x]+w<dist[to]){ dist[to]=dist[x]+w; prev[to]=x; pq.push({to,dist[x]+w}); } } } rep(j,14*14){ if(people[to2(i,j)]==0) continue; int now=j,cnt=0; while(now!=i){ if(dist[now]-dist[prev[now]]==223) cnt++; root_cnt[to2(prev[now],now)]+=people[to2(i,j)]*people[to2(i,j)]; now=prev[now]; } score+=60*cnt*people[to2(i,j)]; } } return {root_cnt,score}; } void solve(){ vector<vector<pii>> g(14*14); rep(i,14){ rep(j,14){ rep(k,4){ int ti=i+pi[k],tj=j+pj[k]; if(ti<0||14<=ti||tj<0||14<=tj) continue; g[to(i,j)].emplace_back(to(ti,tj),1000); } } } people.resize(14*14*14*14); rep(i,input.n){ people[to2(input.s[i],input.g[i])]++; } vector<int> score_sum={0}; vector<pii> v; vector<bool> built(14*14*14*14,false); int ns=-1,ng=-1; vector<int> cnt=dijkstra(g).first; rep(r,100){; int max_cnt=0,ts=-1,tg=-1; rep(i,14*14){ rep(j,14*14){ if(cnt[to2(i,j)]==0) continue; if(built[to2(i,j)]) continue; if(max_cnt<cnt[to2(i,j)]){ max_cnt=cnt[to2(i,j)]; ts=i; tg=j; } } } if(ts==-1||tg==-1) break; for(auto &[to,w]:g[ts]){ if(to==tg) w=223; } for(auto &[to,w]:g[tg]){ if(to==ts) w=223; } int now_score; tie(cnt,now_score)=dijkstra(g); score_sum.push_back(now_score); ns=ts; ng=tg; built[to2(ns,ng)]=true; built[to2(ng,ns)]=true; v.emplace_back(ns,ng); } int x=v.size(); vector<vector<vector<int>>> dp(input.t+1,vector<vector<int>>(input.t+1,vector<int>(x,-INF))); vector<vector<vector<tii>>> prev(input.t+1,vector<vector<tii>>(input.t+1,vector<tii>(x))); dp[0][1][0]=1e6; rep(i,input.t){ rep(j,input.t+1){ rep(k,x){ if(dp[i][j][k]==-INF) continue; if(0<j&&k+1<x){ int cost=1e7/sqrt(j); if(cost<=dp[i][j][k]&&dp[i+1][j][k+1]<dp[i][j][k]-cost+score_sum[k+1]){ dp[i+1][j][k+1]=dp[i][j][k]-cost+score_sum[k]; prev[i+1][j][k+1]={i,j,k}; } } if(j+1<input.t){ if(dp[i+1][j+1][k]<dp[i][j][k]+score_sum[k]){ dp[i+1][j+1][k]=dp[i][j][k]+score_sum[k]; prev[i+1][j+1][k]={i,j,k}; } } if(dp[i+1][j][k]<dp[i][j][k]+50000+score_sum[k]){ dp[i+1][j][k]=dp[i][j][k]+50000+score_sum[k]; prev[i+1][j][k]={i,j,k}; } } } } int max_score=-INF,ni=input.t,nj=-1,nk=-1; rep(i,input.t+1){ rep(j,x){ if(max_score<dp[input.t][i][j]){ max_score=dp[input.t][i][j]; nj=i; nk=j; } } } vector<int> ans; while(ni!=0){ int ti,tj,tk; tie(ti,tj,tk)=prev[ni][nj][nk]; if(tk!=nk){ ans.push_back(0); }else if(tj!=nj){ ans.push_back(1); }else{ ans.push_back(2); } ni=ti; nj=tj; nk=tk; } reverse(all(ans)); int now=0; rep(i,input.t){ int cin_u,cin_v; cin >> cin_u >> cin_v; if(ans[i]==0){ int s,t; tie(s,t)=v[now]; int o,p,q,r; tie(o,p)=back(s); tie(q,r)=back(t); cout << ans[i]+1 << " " << o+1 << " " << p+1 << " " << q+1 << " " << r+1 << endl; now++; }else{ cout << ans[i]+1 << endl; } } } }solver; int main(){ input.input_cin(); solver.solve(); }