結果
| 問題 |
No.2826 Earthwork
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-07-25 19:18:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,109 ms / 5,000 ms |
| コード長 | 4,260 bytes |
| コンパイル時間 | 3,343 ms |
| コンパイル使用メモリ | 266,936 KB |
| 実行使用メモリ | 97,668 KB |
| 最終ジャッジ日時 | 2024-07-25 19:18:34 |
| 合計ジャッジ時間 | 27,138 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 40 |
ソースコード
#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 T_INF=numeric_limits<T>::max()> struct dijkstra{
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,(ll)4e18> 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)));
}
}
}
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";
}
}
FplusFplusF