結果

問題 No.5016 Worst Mayor
ユーザー FplusFplusFFplusFplusF
提出日時 2023-04-29 15:45:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,700 ms / 2,000 ms
コード長 6,115 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 245,108 KB
実行使用メモリ 284,340 KB
スコア 18,742,723,009
平均クエリ数 400.00
最終ジャッジ日時 2023-04-29 15:46:57
合計ジャッジ時間 84,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,606 ms
283,700 KB
testcase_01 AC 1,610 ms
283,392 KB
testcase_02 AC 1,541 ms
284,192 KB
testcase_03 AC 1,616 ms
283,852 KB
testcase_04 AC 1,506 ms
283,768 KB
testcase_05 AC 1,608 ms
283,932 KB
testcase_06 AC 1,587 ms
283,944 KB
testcase_07 AC 1,679 ms
283,700 KB
testcase_08 AC 1,400 ms
284,036 KB
testcase_09 AC 1,328 ms
283,536 KB
testcase_10 AC 1,501 ms
284,104 KB
testcase_11 AC 1,684 ms
283,604 KB
testcase_12 AC 1,337 ms
284,160 KB
testcase_13 AC 1,601 ms
283,480 KB
testcase_14 AC 1,548 ms
284,172 KB
testcase_15 AC 1,537 ms
283,432 KB
testcase_16 AC 1,448 ms
284,232 KB
testcase_17 AC 1,293 ms
284,088 KB
testcase_18 AC 1,287 ms
283,528 KB
testcase_19 AC 1,364 ms
283,380 KB
testcase_20 AC 1,600 ms
283,644 KB
testcase_21 AC 1,369 ms
284,140 KB
testcase_22 AC 1,623 ms
283,724 KB
testcase_23 AC 1,282 ms
283,816 KB
testcase_24 AC 1,543 ms
284,108 KB
testcase_25 AC 1,614 ms
283,560 KB
testcase_26 AC 1,635 ms
283,564 KB
testcase_27 AC 1,414 ms
284,012 KB
testcase_28 AC 1,345 ms
283,568 KB
testcase_29 AC 1,484 ms
283,676 KB
testcase_30 AC 1,564 ms
283,768 KB
testcase_31 AC 1,622 ms
283,844 KB
testcase_32 AC 1,587 ms
283,572 KB
testcase_33 AC 1,512 ms
283,600 KB
testcase_34 AC 1,583 ms
283,576 KB
testcase_35 AC 1,463 ms
283,956 KB
testcase_36 AC 1,484 ms
283,644 KB
testcase_37 AC 1,566 ms
283,880 KB
testcase_38 AC 1,610 ms
283,840 KB
testcase_39 AC 1,696 ms
283,592 KB
testcase_40 AC 1,657 ms
284,340 KB
testcase_41 AC 1,700 ms
284,216 KB
testcase_42 AC 1,602 ms
283,968 KB
testcase_43 AC 1,461 ms
284,116 KB
testcase_44 AC 1,549 ms
283,896 KB
testcase_45 AC 1,537 ms
283,736 KB
testcase_46 AC 1,269 ms
283,860 KB
testcase_47 AC 1,635 ms
283,416 KB
testcase_48 AC 1,483 ms
284,096 KB
testcase_49 AC 1,336 ms
284,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    pair<vector<vector<int>>,int> dijkstra(vector<vector<pii>> &g){
        int score=0;
        vector<vector<int>> root_cnt(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,cnt=0;
                while(now!=i){
                    if(dist[now]-dist[prev[now]]==223) cnt++;
                    root_cnt[prev[now]][now]++;
                    now=prev[now];
                }
                score+=60*cnt*people[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);
        rep(i,14*14) people[i].resize(14*14,0);
        rep(i,input.n){
            people[input.s[i]][input.g[i]]++;
        }
        vector<int> score_sum={0};
        vector<pii> v;
        vector<vector<bool>> built(14*14,vector<bool>(14*14,false));
        int ns=-1,ng=-1;
        vector<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[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;
            }
            int now_score;
            tie(cnt,now_score)=dijkstra(g);
            score_sum.push_back(now_score);
            ns=ts;
            ng=tg;
            built[ns][ng]=true;
            built[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();
}
0