結果
問題 | No.2826 Earthwork |
ユーザー | FplusFplusF |
提出日時 | 2024-07-25 19:09:08 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,360 bytes |
コンパイル時間 | 3,656 ms |
コンパイル使用メモリ | 267,188 KB |
実行使用メモリ | 97,796 KB |
最終ジャッジ日時 | 2024-07-25 19:09:41 |
合計ジャッジ時間 | 31,748 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 20 ms
5,248 KB |
testcase_02 | AC | 1,095 ms
97,292 KB |
testcase_03 | AC | 103 ms
12,228 KB |
testcase_04 | AC | 888 ms
82,692 KB |
testcase_05 | WA | - |
testcase_06 | AC | 529 ms
53,472 KB |
testcase_07 | AC | 715 ms
66,748 KB |
testcase_08 | AC | 1,050 ms
97,152 KB |
testcase_09 | AC | 1,156 ms
97,680 KB |
testcase_10 | AC | 1,092 ms
97,168 KB |
testcase_11 | WA | - |
testcase_12 | AC | 19 ms
5,376 KB |
testcase_13 | AC | 342 ms
33,000 KB |
testcase_14 | AC | 1,276 ms
97,540 KB |
testcase_15 | AC | 254 ms
27,208 KB |
testcase_16 | AC | 399 ms
53,772 KB |
testcase_17 | AC | 145 ms
17,396 KB |
testcase_18 | AC | 408 ms
51,884 KB |
testcase_19 | AC | 153 ms
23,432 KB |
testcase_20 | AC | 884 ms
80,172 KB |
testcase_21 | WA | - |
testcase_22 | AC | 739 ms
64,856 KB |
testcase_23 | AC | 652 ms
63,756 KB |
testcase_24 | AC | 1,135 ms
97,280 KB |
testcase_25 | AC | 321 ms
66,744 KB |
testcase_26 | AC | 761 ms
65,220 KB |
testcase_27 | AC | 8 ms
5,376 KB |
testcase_28 | AC | 1,262 ms
97,796 KB |
testcase_29 | AC | 65 ms
10,956 KB |
testcase_30 | AC | 35 ms
6,884 KB |
testcase_31 | AC | 70 ms
10,248 KB |
testcase_32 | AC | 14 ms
5,376 KB |
testcase_33 | AC | 660 ms
54,384 KB |
testcase_34 | AC | 1,070 ms
97,288 KB |
testcase_35 | AC | 258 ms
25,896 KB |
testcase_36 | AC | 1,168 ms
97,668 KB |
testcase_37 | AC | 1,173 ms
97,548 KB |
testcase_38 | AC | 518 ms
50,184 KB |
testcase_39 | WA | - |
testcase_40 | AC | 27 ms
6,220 KB |
ソースコード
#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=0> struct dijkstra{ const T T_INF=IN_INF!=0?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]; } } rep(i,n){ rep(j,n-1){ cin >> b[i][j]; } } auto to=[&](ll i,ll j){ return i*n+j; }; vector<vector<ll>> mx(n,vector<ll>(n,-INF)); rep(t,2){ dijkstra<ll,INF> g(n*n+1); 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==t){ 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==t){ 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==t) g.add_edge(n*n,to(i,j),0); if(s[i][j]=='+'&&(i+j)%2!=t) g.add_edge(n*n,to(i,j),0); } } g.solve(n*n); rep(i,n){ rep(j,n){ if((i+j)%2==t) chmax(mx[i][j],h[i][j]+g.get_dist(to(i,j))); else chmax(mx[i][j],h[i][j]-g.get_dist(to(i,j))); } } } ll q; cin >> q; while(q--){ ll r,c,e; cin >> r >> c >> e; r--; c--; if(e<=mx[r][c]) cout << "Yes\n"; else cout << "No\n"; } }