結果
問題 | No.5016 Worst Mayor |
ユーザー | FplusFplusF |
提出日時 | 2023-04-29 16:44:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,714 ms / 2,000 ms |
コード長 | 6,108 bytes |
コンパイル時間 | 3,314 ms |
コンパイル使用メモリ | 238,880 KB |
実行使用メモリ | 284,108 KB |
スコア | 19,523,311,071 |
平均クエリ数 | 400.00 |
最終ジャッジ日時 | 2023-04-29 16:45:28 |
合計ジャッジ時間 | 86,358 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,544 ms
283,736 KB |
testcase_01 | AC | 1,668 ms
283,260 KB |
testcase_02 | AC | 1,523 ms
283,484 KB |
testcase_03 | AC | 1,594 ms
283,212 KB |
testcase_04 | AC | 1,537 ms
283,416 KB |
testcase_05 | AC | 1,548 ms
283,876 KB |
testcase_06 | AC | 1,606 ms
283,448 KB |
testcase_07 | AC | 1,673 ms
283,756 KB |
testcase_08 | AC | 1,357 ms
283,472 KB |
testcase_09 | AC | 1,347 ms
283,856 KB |
testcase_10 | AC | 1,520 ms
283,192 KB |
testcase_11 | AC | 1,661 ms
283,892 KB |
testcase_12 | AC | 1,677 ms
283,804 KB |
testcase_13 | AC | 1,511 ms
283,436 KB |
testcase_14 | AC | 1,630 ms
283,944 KB |
testcase_15 | AC | 1,499 ms
283,448 KB |
testcase_16 | AC | 1,595 ms
283,536 KB |
testcase_17 | AC | 1,394 ms
283,948 KB |
testcase_18 | AC | 1,583 ms
283,184 KB |
testcase_19 | AC | 1,388 ms
283,152 KB |
testcase_20 | AC | 1,620 ms
283,420 KB |
testcase_21 | AC | 1,544 ms
283,968 KB |
testcase_22 | AC | 1,594 ms
283,648 KB |
testcase_23 | AC | 1,494 ms
283,788 KB |
testcase_24 | AC | 1,537 ms
283,748 KB |
testcase_25 | AC | 1,635 ms
283,712 KB |
testcase_26 | AC | 1,713 ms
283,276 KB |
testcase_27 | AC | 1,488 ms
283,264 KB |
testcase_28 | AC | 1,311 ms
283,900 KB |
testcase_29 | AC | 1,600 ms
283,888 KB |
testcase_30 | AC | 1,631 ms
283,196 KB |
testcase_31 | AC | 1,628 ms
283,252 KB |
testcase_32 | AC | 1,672 ms
284,108 KB |
testcase_33 | AC | 1,569 ms
283,992 KB |
testcase_34 | AC | 1,576 ms
283,408 KB |
testcase_35 | AC | 1,558 ms
283,652 KB |
testcase_36 | AC | 1,537 ms
283,276 KB |
testcase_37 | AC | 1,672 ms
283,664 KB |
testcase_38 | AC | 1,625 ms
283,848 KB |
testcase_39 | AC | 1,714 ms
283,896 KB |
testcase_40 | AC | 1,681 ms
283,372 KB |
testcase_41 | AC | 1,706 ms
283,400 KB |
testcase_42 | AC | 1,628 ms
283,864 KB |
testcase_43 | AC | 1,432 ms
283,524 KB |
testcase_44 | AC | 1,614 ms
283,444 KB |
testcase_45 | AC | 1,511 ms
283,324 KB |
testcase_46 | AC | 1,357 ms
283,700 KB |
testcase_47 | AC | 1,627 ms
283,268 KB |
testcase_48 | AC | 1,565 ms
283,752 KB |
testcase_49 | AC | 1,402 ms
283,192 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,1,0,-1},pj={1,0,-1,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)]; 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(); }