結果

問題 No.1638 Robot Maze
ユーザー noya2noya2
提出日時 2021-08-06 22:07:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 6,238 bytes
コンパイル時間 4,891 ms
コンパイル使用メモリ 291,824 KB
実行使用メモリ 6,516 KB
最終ジャッジ日時 2023-10-17 03:30:04
合計ジャッジ時間 6,558 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 8 ms
6,516 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 6 ms
5,196 KB
testcase_15 AC 4 ms
4,668 KB
testcase_16 AC 4 ms
4,668 KB
testcase_17 AC 4 ms
4,668 KB
testcase_18 AC 4 ms
4,668 KB
testcase_19 AC 5 ms
4,668 KB
testcase_20 AC 5 ms
4,668 KB
testcase_21 AC 5 ms
4,684 KB
testcase_22 AC 5 ms
4,684 KB
testcase_23 AC 5 ms
4,684 KB
testcase_24 AC 4 ms
4,684 KB
testcase_25 AC 5 ms
4,684 KB
testcase_26 AC 5 ms
4,684 KB
testcase_27 AC 4 ms
4,684 KB
testcase_28 AC 5 ms
4,684 KB
testcase_29 AC 5 ms
4,684 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 7 ms
5,460 KB
testcase_33 AC 7 ms
5,472 KB
testcase_34 AC 8 ms
5,988 KB
testcase_35 AC 8 ms
5,460 KB
testcase_36 AC 8 ms
5,988 KB
testcase_37 AC 7 ms
5,460 KB
testcase_38 AC 7 ms
5,460 KB
testcase_39 AC 8 ms
5,988 KB
testcase_40 AC 7 ms
5,460 KB
testcase_41 AC 7 ms
5,724 KB
testcase_42 AC 8 ms
5,724 KB
testcase_43 AC 8 ms
5,724 KB
testcase_44 AC 8 ms
5,724 KB
testcase_45 AC 8 ms
5,724 KB
testcase_46 AC 8 ms
5,988 KB
testcase_47 AC 8 ms
5,724 KB
testcase_48 AC 8 ms
5,988 KB
testcase_49 AC 7 ms
5,460 KB
testcase_50 AC 7 ms
5,724 KB
testcase_51 AC 8 ms
5,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
/*
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using bint = mp::cpp_int;
*/
#include <atcoder/all>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
#define repb(i,n) for (int i = int(n)-1; i >= 0; --i)
#define fi first
#define se second
#define endl "\n"
using namespace std;
using namespace atcoder;
//using namespace internal;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
const int INF = 1001001007;
const long long mod1 = 1000000007LL;
const long long mod2 = 998244353LL;
const ll inf = 2e18;
const ld pi = 3.14159265358979323;
template<typename T>void priv(vector<T> &v){if(v.size()==0){cout<<endl;}else{rep(i,v.size()-1)cout<<v[i]<<" ";cout<<v[v.size()-1]<<endl;}}
template<typename T>void privv(vector<vector<T>> &v){rep(i,v.size()){rep(j,v[i].size()-1)cout<<v[i][j]<<" ";cout<<v[i][v[i].size()-1]<<endl;}}
template<typename T>bool range(T a,T b,T x){return (a<=x&&x<b);}
template<typename T>bool rrange(pair<T,T> a,pair<T,T> b,pair<T,T> x){return (range(a.fi,b.fi,x.fi)&&range(a.se,b.se,x.se));}
template<typename T>void rev(vector<T> &v){reverse(v.begin(),v.end());}
template<typename T>void sor(vector<T> &v, int f=0){sort(v.begin(),v.end());if(f!=0) rev(v);}
template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<typename T>void eru(vector<T> &v){sor(v);v.erase(unique(v.begin(),v.end()),v.end());}
template<typename T>T cel(T a,T b){if (a%b==0)return a/b;return a/b +1;}
template<typename T,typename U> void pout(pair<T,U> p){cout<<p.fi<<" "<<p.se<<endl;}
template<typename T>void myswap(T &a,T &b){if(a>b)swap(a,b);}
void yes(){cout << "Yes" << endl;}
void no (){cout << "No" << endl;}
void yn (bool t){if(t)yes();else no();}
void Yes(){cout << "YES" << endl;}
void No (){cout << "NO" << endl;}
void YN (bool t){if(t)Yes();else No();}
void dout() {cout << setprecision(20);}
void deb(ll h = INF-1) {cout << (h == INF-1 ? "!?" : to_string(h)) << endl;}
void revs(string &s) {reverse(s.begin(),s.end());}
vector<int> dx = {0,1,0,-1};
vector<int> dy = {1,0,-1,0};
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string num = "0123456789";

ll gcds(ll a, ll b){
    a = abs(a); b = abs(b);
    if (b == 0) return a;
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

ll tentou(vector<ll> ar){
    int n = ar.size();
    set<ll> st;
    rep(i,n) st.insert(ar[i]);
    map<ll,int> mp;
    int ind = 0;
    for (ll x : st){
        mp[x] = ind;
        ind++;
    }
    fenwick_tree<ll> fw(ind);
    ll ans = 0;
    rep(i,n){
        int a = mp[ar[i]];
        ans += i - fw.sum(0,a+1);
        fw.add(a,1);
    }
    return ans;
}

struct vs{
    vector<pair<int, long long>> to;
};

struct Graph{
    using pli = pair<long long, int>;
    using pil = pair<int, long long>;
    int n, m;
    vector<vs> ar;
    // n : 頂点数 , m : 辺数 , c = 1 : コストを入力 , dual = 1 : 辺が双方向
    Graph(int _n, int _m, int c = 1, int dual = 1) : n(_n), m(_m), ar(n) {
        for (int i = 0; i < m; i++){
            int u, v; cin >> u >> v;
            long long d = 1;
            if (c == 1) cin >> d;
            ar[u-1].to.emplace_back(pil(v-1,d));
            if (dual == 1) ar[v-1].to.emplace_back(pil(u-1,d));
        }
    }
    Graph(vector<vs> _ar, int _n, int _m = 0) : ar(_ar), n(_n), m(_m){}
    vector<long long> dijkstra(int s){
        priority_queue<pli, vector<pli>, greater<pli>> pque;
        vector<long long> dist(n,1e18);
        dist[s] = 0;
        pque.push(pli(0,s));
        while (!pque.empty()){
            pli p = pque.top(); pque.pop();
            if (dist[p.second] < p.first) continue;
            for (pil x : ar[p.second].to){
                if (dist[x.first] > p.first + x.second){
                    dist[x.first] = p.first + x.second;
                    pque.push(pli(dist[x.first],x.first));
                }
            }
        }
        return dist;
    }
    vector<vector<long long>> washall_floyd(){
        vector<vector<long long>> dist(n,vector<long long>(n,2e18));
        for (int i = 0; i < n; i++) dist[i][i] = 0;
        for (int i = 0; i < n; i++){
            for (pil x : ar[i].to){
                dist[i][x.first] = min(dist[i][x.first], x.second);
            }
        }
        for (int k = 0; k < n; k++){
            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++){
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        return dist;
    }
    
};

/*
alias g++='g++ -I/mnt/c/Users/Owner/Desktop/ac-library'
*/

int main(){
    using pil = pair<int,ll>;
    int h, w; cin >> h >> w;
    vector<ll> cost(4);
    cin >> cost[3] >> cost[1] >> cost[0] >> cost[2];
    rep(i,4) cost[i] *= 2;
    ll ka, p; cin >> ka >> p;
    ka *= 2;
    int a, b, c, d; cin >> a >> b >> c >> d;
    int s = w * (a-1) + b-1;
    int g = w * (c-1) + d-1;
    vector<vector<char>> maze(h,vector<char>(w));
    rep(i,h) rep(j,w) cin >> maze[i][j];
    vector<vs> ar(h*w);
    rep(i,h) rep(j,w){
        if (maze[i][j] == '#') continue;
        int f = i * w + j;
        ll pl = (maze[i][j] == '@' ? p : 0);
        rep(k,4){
            if (rrange(P(0,0),P(h,w),P(i+dx[k],j+dy[k]))){
                if (maze[i+dx[k]][j+dy[k]] == '#') continue;
                int t = (i+dx[k]) * w + j+dy[k];
                ll y = pl;
                if (maze[i+dx[k]][j+dy[k]] == '@') y += p;
                ar[f].to.emplace_back(pil(t,cost[k] + y));
            }
        }
    }
    Graph gr(ar,h*w);
    auto v = gr.dijkstra(s);
    yn(v[g] <= ka);
    //cout << v[g] << endl;
    //priv(v);
    //priv(cost);
}
0