結果
問題 | No.5016 Worst Mayor |
ユーザー | FplusFplusF |
提出日時 | 2023-04-29 15:25:51 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 6,822 bytes |
コンパイル時間 | 3,427 ms |
コンパイル使用メモリ | 242,980 KB |
実行使用メモリ | 206,176 KB |
スコア | 18,269,071,291 |
平均クエリ数 | 384.00 |
最終ジャッジ日時 | 2023-04-29 15:27:30 |
合計ジャッジ時間 | 95,956 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,882 ms
206,004 KB |
testcase_01 | AC | 1,842 ms
205,168 KB |
testcase_02 | AC | 1,782 ms
205,620 KB |
testcase_03 | AC | 1,865 ms
206,176 KB |
testcase_04 | AC | 1,741 ms
205,288 KB |
testcase_05 | AC | 1,828 ms
205,632 KB |
testcase_06 | AC | 1,833 ms
205,388 KB |
testcase_07 | AC | 1,980 ms
205,592 KB |
testcase_08 | AC | 1,558 ms
205,260 KB |
testcase_09 | AC | 1,450 ms
205,672 KB |
testcase_10 | AC | 1,697 ms
205,044 KB |
testcase_11 | AC | 1,967 ms
205,692 KB |
testcase_12 | AC | 1,522 ms
205,824 KB |
testcase_13 | AC | 1,911 ms
205,304 KB |
testcase_14 | AC | 1,792 ms
204,956 KB |
testcase_15 | AC | 1,694 ms
205,448 KB |
testcase_16 | AC | 1,594 ms
205,068 KB |
testcase_17 | AC | 1,395 ms
205,508 KB |
testcase_18 | AC | 1,376 ms
205,160 KB |
testcase_19 | AC | 1,541 ms
205,648 KB |
testcase_20 | AC | 1,814 ms
205,560 KB |
testcase_21 | AC | 1,509 ms
205,616 KB |
testcase_22 | AC | 1,891 ms
205,584 KB |
testcase_23 | AC | 1,339 ms
205,128 KB |
testcase_24 | AC | 1,739 ms
205,164 KB |
testcase_25 | AC | 1,910 ms
205,260 KB |
testcase_26 | AC | 1,911 ms
205,388 KB |
testcase_27 | AC | 1,569 ms
205,060 KB |
testcase_28 | AC | 1,479 ms
205,652 KB |
testcase_29 | AC | 1,693 ms
205,164 KB |
testcase_30 | AC | 1,849 ms
205,696 KB |
testcase_31 | AC | 1,900 ms
205,196 KB |
testcase_32 | AC | 1,833 ms
205,136 KB |
testcase_33 | AC | 1,717 ms
205,016 KB |
testcase_34 | AC | 1,838 ms
205,288 KB |
testcase_35 | AC | 1,653 ms
205,320 KB |
testcase_36 | AC | 1,622 ms
205,184 KB |
testcase_37 | AC | 1,815 ms
205,608 KB |
testcase_38 | AC | 1,836 ms
205,256 KB |
testcase_39 | AC | 1,974 ms
205,508 KB |
testcase_40 | AC | 1,983 ms
205,764 KB |
testcase_41 | TLE | - |
testcase_42 | AC | 1,955 ms
205,188 KB |
testcase_43 | AC | 1,641 ms
205,776 KB |
testcase_44 | AC | 1,738 ms
205,844 KB |
testcase_45 | AC | 1,754 ms
206,084 KB |
testcase_46 | AC | 1,333 ms
205,588 KB |
testcase_47 | AC | 1,849 ms
205,696 KB |
testcase_48 | AC | 1,630 ms
205,008 KB |
testcase_49 | AC | 1,467 ms
205,168 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; } 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<vector<int>> people; vector<vector<int>> root(vector<vector<pii>> &g){ vector<vector<int>> ret(14*14,vector<int>(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[i][j]==0) continue; int now=j; while(now!=i){ ret[prev[now]][now]++; now=prev[now]; } } } return ret; } int score(vector<vector<pii>> &g){ int ret=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[i][j]==0) continue; int now=j,cnt=0; while(now!=i){ if(dist[now]-dist[prev[now]]==223) cnt++; now=prev[now]; } ret+=60*cnt*people[i][j]; } } return ret; } 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); rep(i,14*14) people[i].resize(14*14,0); rep(i,input.n){ people[input.s[i]][input.g[i]]++; } int x=70; vector<int> score_sum(x+1,0); vector<pii> v(x); vector<vector<bool>> built(14*14,vector<bool>(14*14,false)); int ns=-1,ng=-1; rep(r,x){ vector<vector<int>> cnt=root(g); int max_cnt=0,ts=-1,tg=-1; rep(i,14*14){ rep(j,14*14){ if(cnt[i][j]==0) continue; if(built[i][j]) continue; if(max_cnt<cnt[i][j]){ max_cnt=cnt[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; } score_sum[r+1]=score(g); ns=ts; ng=tg; built[ns][ng]=true; built[ng][ns]=true; v[r]={ns,ng}; } 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(); }