結果

問題 No.1638 Robot Maze
ユーザー LayCurseLayCurse
提出日時 2021-08-06 21:26:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 9,987 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 222,784 KB
実行使用メモリ 16,052 KB
最終ジャッジ日時 2024-09-17 01:17:35
合計ジャッジ時間 4,061 ms
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,672 KB
testcase_01 AC 4 ms
11,720 KB
testcase_02 AC 4 ms
11,724 KB
testcase_03 WA -
testcase_04 AC 4 ms
11,724 KB
testcase_05 AC 4 ms
11,724 KB
testcase_06 AC 3 ms
9,676 KB
testcase_07 AC 3 ms
9,932 KB
testcase_08 AC 3 ms
9,676 KB
testcase_09 AC 4 ms
11,720 KB
testcase_10 AC 4 ms
11,720 KB
testcase_11 AC 4 ms
11,716 KB
testcase_12 AC 4 ms
9,804 KB
testcase_13 AC 3 ms
9,552 KB
testcase_14 AC 4 ms
9,812 KB
testcase_15 WA -
testcase_16 AC 4 ms
13,852 KB
testcase_17 WA -
testcase_18 AC 3 ms
9,680 KB
testcase_19 AC 5 ms
11,732 KB
testcase_20 AC 4 ms
13,772 KB
testcase_21 AC 4 ms
11,864 KB
testcase_22 AC 4 ms
9,936 KB
testcase_23 WA -
testcase_24 AC 5 ms
11,988 KB
testcase_25 AC 4 ms
11,864 KB
testcase_26 WA -
testcase_27 AC 4 ms
11,892 KB
testcase_28 AC 4 ms
11,860 KB
testcase_29 WA -
testcase_30 AC 3 ms
9,676 KB
testcase_31 WA -
testcase_32 AC 5 ms
13,900 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 5 ms
12,092 KB
testcase_36 AC 5 ms
14,044 KB
testcase_37 AC 5 ms
13,992 KB
testcase_38 AC 3 ms
9,812 KB
testcase_39 WA -
testcase_40 AC 4 ms
9,812 KB
testcase_41 WA -
testcase_42 AC 4 ms
9,812 KB
testcase_43 AC 5 ms
12,108 KB
testcase_44 AC 5 ms
16,052 KB
testcase_45 AC 4 ms
11,860 KB
testcase_46 AC 5 ms
13,924 KB
testcase_47 AC 5 ms
11,972 KB
testcase_48 AC 4 ms
12,000 KB
testcase_49 AC 4 ms
9,816 KB
testcase_50 AC 5 ms
13,900 KB
testcase_51 AC 5 ms
13,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
  walloc1d(arr, x2-x1, mem);
  (*arr) -= x1;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S> inline void arrInsert(const int k, int &sz, S a[], const S aval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  a[k] = aval;
}
template<class S, class T> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  a[k] = aval;
  b[k] = bval;
}
template<class S, class T, class U> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
}
template<class S, class T, class U, class V> inline void arrInsert(const int k, int &sz, S a[], const S aval, T b[], const T bval, U c[], const U cval, V d[], const V dval){
  int i;
  sz++;
  for(i=sz-1;i>k;i--){
    a[i] = a[i-1];
  }
  for(i=sz-1;i>k;i--){
    b[i] = b[i-1];
  }
  for(i=sz-1;i>k;i--){
    c[i] = c[i-1];
  }
  for(i=sz-1;i>k;i--){
    d[i] = d[i-1];
  }
  a[k] = aval;
  b[k] = bval;
  c[k] = cval;
  d[k] = dval;
}
template <class T> struct DijkstraHeap{
  int*hp;
  int*place;
  int size;
  char*visited;
  T*val;
  void malloc(int N){
    hp = (int*)std::malloc(N*sizeof(int));
    place = (int*)std::malloc(N*sizeof(int));
    visited = (char*)std::malloc(N*sizeof(char));
    val = (T*)std::malloc(N*sizeof(T));
  }
  void free(){
    std::free(hp);
    std::free(place);
    std::free(visited);
    std::free(val);
  }
  void walloc(int N, void **mem=&wmem){
    walloc1d(&hp, N, mem);
    walloc1d(&place, N, mem);
    walloc1d(&visited, N, mem);
    walloc1d(&val, N, mem);
  }
  void malloc(int N, int init_fg){
    malloc(N);
    if(init_fg){
      init(N);
    }
  }
  void walloc(int N, int init_fg, void **mem=&wmem){
    walloc(N,mem);
    if(init_fg){
      init(N);
    }
  }
  void init(int N){
    int i;
    size = 0;
    for(i=(0);i<(N);i++){
      place[i]=-1;
    }
    for(i=(0);i<(N);i++){
      visited[i]=0;
    }
  }
  void up(int n){
    int m;
    while(n){
      m=(n-1)/2;
      if(val[hp[m]]<=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void down(int n){
    int m;
    for(;;){
      m=2*n+1;
      if(m>=size){
        break;
      }
      if(m+1<size&&val[hp[m]]>val[hp[m+1]]){
        m++;
      }
      if(val[hp[m]]>=val[hp[n]]){
        break;
      }
      swap(hp[m],hp[n]);
      swap(place[hp[m]],place[hp[n]]);
      n=m;
    }
  }
  void change(int n, T v){
    if(visited[n]||(place[n]>=0&&val[n]<=v)){
      return;
    }
    val[n]=v;
    if(place[n]==-1){
      place[n]=size;
      hp[size++]=n;
      up(place[n]);
    }
    else{
      up(place[n]);
    }
  }
  int pop(void){
    int res=hp[0];
    place[res]=-1;
    size--;
    if(size){
      hp[0]=hp[size];
      place[hp[0]]=0;
      down(0);
    }
    visited[res]=1;
    return res;
  }
}
;
struct graph{
  int N;
  int*es;
  int**edge;
  void setDirectEdge(int N__, int M, int A[], int B[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    walloc1d(&edge[0], M, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
    }
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      edge[A[i]][es[A[i]]++] = B[i];
    }
  }
}
;
template<class T> struct wgraph{
  int N;
  int*es;
  int**edge;
  T**cost;
  graph g;
  void setDirectEdge(int N__, int M, int A[], int B[], T C[], void **mem = &wmem){
    int i;
    N = N__;
    walloc1d(&es, N, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
    }
    walloc1d(&edge, N, mem);
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    walloc1d(&cost, N, mem);
    for(i=(0);i<(N);i++){
      walloc1d(&cost[i], es[i], mem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      edge[A[i]][es[A[i]]] = B[i];
      cost[A[i]][es[A[i]]++] = C[i];
    }
    g.N = N;
    g.es = es;
    g.edge = edge;
  }
  template<class S> S getDistT(int a, int b, S unreachable = -1, void *mem = wmem){
    int i;
    int j;
    DijkstraHeap<S> hp;
    hp.walloc(N, &mem);
    hp.init(N);
    hp.change(a,0);
    while(hp.size){
      i = hp.pop();
      if(i==b){
        return hp.val[i];
      }
      for(j=(0);j<(es[i]);j++){
        hp.change(edge[i][j], hp.val[i]+cost[i][j]);
      }
    }
    return unreachable;
  }
}
;
struct dimcomp2{
  int B;
  dimcomp2(){
  }
  dimcomp2(int b){
    B = b;
  }
  dimcomp2(int a, int b){
    B = b;
  }
  inline void set(int b){
    B = b;
  }
  inline void set(int a, int b){
    B = b;
  }
  inline int mask(int a, int b){
    return a * B + b;
  }
  inline int operator()(int a, int b){
    return a * B + b;
  }
  inline void para(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
  inline void operator()(int mask, int &a, int &b){
    a = mask / B;
    b = mask % B;
  }
}
;
int X;
int Y;
int SX;
int SY;
int TX;
int TY;
long long C[4];
long long K;
long long P;
char S[100][102];
wgraph<long long> g;
int node;
int mm;
int aa[1000000];
int bb[1000000];
long long cc[1000000];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main(){
  int i;
  wmem = memarr;
  int ni;
  int nj;
  long long c;
  long long dd;
  rd(X);
  rd(Y);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(4);Lj4PdHRW++){
      rd(C[Lj4PdHRW]);
    }
  }
  rd(K);
  rd(P);
  rd(SX);SX += (-1);
  rd(SY);SY += (-1);
  rd(TX);TX += (-1);
  rd(TY);TY += (-1);
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(X);e98WHCEY++){
      rd(S[e98WHCEY]);
    }
  }
  dimcomp2 dm(X,Y);
  node = X*Y;
  for(i=(0);i<(X);i++){
    int j;
    for(j=(0);j<(Y);j++){
      int d;
      for(d=(0);d<(4);d++){
        ni = i + dx[d];
        nj = j + dy[d];
        if(ni < 0 || nj < 0 || ni >= X || nj >= Y || S[ni][nj]=='#'){
          continue;
        }
        if(S[ni][nj]=='@'){
          c = C[d] +K;
        }
        else{
          c = C[d] +0;
        }
        arrInsert(mm, mm, aa, dm(i,j), bb, dm(ni,nj), cc, c);
      }
    }
  }
  g.setDirectEdge(node, mm, aa, bb, cc);
  dd = g.getDistT<long long>(dm(SX,SY), dm(TX,TY));
  if(dd==-1 || dd > K){
    wt_L("No");
    wt_L('\n');
  }
  else{
    wt_L("Yes");
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210717-1 [beta]

// --- original code ---
// int X, Y, SX, SY, TX, TY;
// ll C[4], K, P;
// char S[100][102];
// wgraph<ll> g;
// int node, mm, aa[1d6], bb[]; ll cc[];
// int dx[4] = {-1, 1, 0, 0};
// int dy[4] = {0, 0, 1, -1};
// {
//   int ni, nj; ll c, dd;
//   rd(X,Y,C(4),K,P,SX--,SY--,TX--,TY--,S(X));
//   dimcomp2 dm(X,Y);
//   node = X*Y;
//   rep(i,X) rep(j,Y) rep(d,4){
//     ni = i + dx[d];
//     nj = j + dy[d];
//     if(ni < 0 || nj < 0 || ni >= X || nj >= Y || S[ni][nj]=='#') continue;
//     c = C[d] + if[S[ni][nj]=='@', K, 0];
//     arrInsert(mm, mm, aa, dm(i,j), bb, dm(ni,nj), cc, c);
//   }
//   g.setDirectEdge(node, mm, aa, bb, cc);
//   dd = g.getDistT<ll>(dm(SX,SY), dm(TX,TY));
//   wt(if[dd==-1 || dd > K, "No", "Yes"]);
// }
0