結果
問題 | No.2826 Earthwork |
ユーザー | FplusFplusF |
提出日時 | 2024-07-25 18:00:25 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,177 bytes |
コンパイル時間 | 3,674 ms |
コンパイル使用メモリ | 268,704 KB |
実行使用メモリ | 92,884 KB |
最終ジャッジ日時 | 2024-07-25 18:00:45 |
合計ジャッジ時間 | 19,017 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,376 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } template<class T,T IN_INF=-1> struct dijkstra{ const T T_INF=IN_INF!=-1?IN_INF:numeric_limits<T>::max(); int n; vector<vector<pair<int,T>>> g; vector<T> dist; vector<int> prev_idx; dijkstra(int n_):n(n_),g(n),dist(n,T_INF),prev_idx(n){} void add_edge(int u,int v,T cost,bool undirected=false){ assert(0<=u&&u<n); assert(0<=v&&v<n); g[u].emplace_back(v,cost); if(undirected) g[v].emplace_back(u,cost); } void solve(vector<int> s){ for(int i=0;i<n;i++) dist[i]=T_INF; priority_queue<pair<T,int>,vector<pair<T,int>>,greater<pair<T,int>>> pq; for(auto i:s){ dist[i]=0; pq.push({0,i}); } while(!pq.empty()){ auto [d,i]=pq.top(); pq.pop(); if(d!=dist[i]) continue; for(auto [ti,td]:g[i]){ if(dist[i]+td<dist[ti]){ dist[ti]=dist[i]+td; prev_idx[ti]=i; pq.push({dist[ti],ti}); } } } } void solve(int s){ solve((vector<int>){s}); } bool path_exist(int i){ if(dist[i]==T_INF) return false; return true; } T get_dist(int i){ return dist[i]; } vector<int> get_path(int i){ if(!path_exist(i)) return {}; vector<int> ret={i}; while(dist[i]!=0){ i=prev_idx[i]; ret.push_back(i); } reverse(all(ret)); return ret; } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; vector<vector<ll>> h(n,vector<ll>(n)); rep(i,n){ rep(j,n){ cin >> h[i][j]; } } vector<string> s(n); rep(i,n) cin >> s[i]; vector<vector<ll>> a(n-1,vector<ll>(n)),b(n,vector<ll>(n-1)); rep(i,n-1){ rep(j,n){ cin >> a[i][j]; a[i][j]*=abs(h[i][j]+h[i+1][j]); } } rep(i,n){ rep(j,n-1){ cin >> b[i][j]; b[i][j]*=abs(h[i][j]+h[i][j+1]); } } dijkstra<ll,INF> g(n*n+1); auto to=[&](ll i,ll j){ return i*n+j; }; rep(i,n-1){ rep(j,n){ ll p=h[i][j]+h[i+1][j]; ll l=-p-a[i][j]*abs(p),r=-p+a[i][j]*abs(p); if((i+j)%2==0){ g.add_edge(to(i,j),to(i+1,j),-l); g.add_edge(to(i+1,j),to(i,j),r); }else{ g.add_edge(to(i,j),to(i+1,j),r); g.add_edge(to(i+1,j),to(i,j),-l); } } } rep(i,n){ rep(j,n-1){ ll p=h[i][j]+h[i][j+1]; ll l=-p-b[i][j]*abs(p),r=-p+b[i][j]*abs(p); if((i+j)%2==0){ g.add_edge(to(i,j),to(i,j+1),-l); g.add_edge(to(i,j+1),to(i,j),r); }else{ g.add_edge(to(i,j),to(i,j+1),r); g.add_edge(to(i,j+1),to(i,j),-l); } } } rep(i,n){ rep(j,n){ if(s[i][j]=='=') g.add_edge(n*n,to(i,j),0); if(s[i][j]=='-'&&(i+j)%2==0) g.add_edge(n*n,to(i,j),0); if(s[i][j]=='+'&&(i+j)%2==1) g.add_edge(n*n,to(i,j),0); } } g.solve(n*n); ll q; cin >> q; while(q--){ ll r,c,e; cin >> r >> c >> e; r--; c--; ll d=g.get_dist(to(r,c)); bool ok=false; if((r+c)%2==0&&e<=h[r][c]-d) ok=true; if((r+c)%2==1&&e<=h[r][c]+d) ok=true; if(ok) cout << "Yes\n"; else cout << "No\n"; } }