結果
問題 | No.2213 Neq Move |
ユーザー |
![]() |
提出日時 | 2023-02-11 05:05:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,696 bytes |
コンパイル時間 | 1,933 ms |
コンパイル使用メモリ | 206,672 KB |
最終ジャッジ日時 | 2025-02-10 14:10:14 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 5 |
ソースコード
#define rep(i, n) for (int i = 0; i < (int)(n); i++)#define ALL(v) v.begin(), v.end()typedef long long ll;#include <bits/stdc++.h>using namespace std;const ll INF=1LL<<60;struct Edge{int to;ll w;Edge(int to,ll w) : to(to),w(w) {}};using Graph=vector<vector<Edge>>;using pli=pair<ll,int>;template<class T> bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}vector<ll> dijkstra(Graph G,int s){int n=G.size();vector<ll> dist(n,INF);dist[s]=0;priority_queue<pli,vector<pli>,greater<pli>> que;que.push({dist[s],s});while(!que.empty()){int v=que.top().second;ll d=que.top().first;que.pop();if(d>dist[v]) continue;for(auto e:G[v]){if(chmin(dist[e.to],dist[v]+e.w)){que.push({dist[e.to],e.to});}}}return dist;}int main(){ios::sync_with_stdio(false);std::cin.tie(nullptr);int t;cin>>t;while(t--){Graph G(6);ll a,b,c,d;cin>>a>>b>>c>>d;G[0].push_back(Edge(3,1));G[0].push_back(Edge(4,1));if(a>b && c>d && c>=a && d>=b) G[0].push_back(Edge(5,c+d-a-b));if(a<b && c<d && c>=a && d>=b) G[0].push_back(Edge(5,c+d-a-b));G[1].push_back(Edge(2,3));G[2].push_back(Edge(1,3));if(c>d) G[1].push_back(Edge(5,c+d-1));else G[2].push_back(Edge(5,c+d-1));if(a>1) G[3].push_back(Edge(2,2));if(b>1) G[4].push_back(Edge(1,2));if(a==1) G[3].push_back(Edge(1,0));if(b==1) G[4].push_back(Edge(2,0));if(c>d && c>=a) G[3].push_back(Edge(5,c+d-a));if(c<d && d>=b) G[4].push_back(Edge(5,c+d-b));vector<ll> dis=dijkstra(G,0);cout<<dis[5]<<'\n';}return 0;}