Submission #71689779


Source Code Expand

#if !__INCLUDE_LEVEL__
#include __FILE__

void solve() {
  int H,W;
  cin>>H>>W;
  vs grid(H);
  rep(i,H)cin>>grid[i];
  priority_queue<tpi,vector<tpi>,greater<tpi>> pq;
  vvpii warp(26);
  vi warp_vis(26,false);
  rep(i,H)rep(j,W){
    if(grid[i][j]=='#'||grid[i][j]=='.')continue;
    warp[grid[i][j]-'a'].pb({i,j});
  }
  rep(i,0){
    char t='a'+i;
    cout<<t<<el;
    for(auto [x,y]:warp[i])cout<<'('<<x<<spa<<y<<')'<<spa;
    cout<<el;
  }
  vvb vis(H,vb(W,false));
  vvi dp(H,vi(W,1e9));
  dp[0][0]=0;
  pq.push({0,0,0});
  while(!pq.empty()){
    auto [cost,x,y]=pq.top();
    //cout<<x<<spa<<y<<el;
    pq.pop();
    if(vis[x][y])continue;
    vis[x][y]=true;
    if(grid[x][y]!='.'){
      int p=grid[x][y]-'a';
      if(warp_vis[p]==false){
      warp_vis[p]=true;
      for(auto [i,j]:warp[p]){
        if(vis[i][j])continue;
        if(chmin(dp[i][j],cost+1)){
          pq.push({dp[i][j],i,j});
        }
      }
      }
    }
    for(auto [dx,dy]:dir){
        int nx=dx+x,ny=dy+y;
        if(grid_inside(H,W,nx,ny)&&grid[nx][ny]!='#'&&vis[nx][ny]==false&&chmin(dp[nx][ny],cost+1)){
          pq.push({dp[nx][ny],nx,ny});
        }
      }
  }
  if(vis[H-1][W-1]){
    cout<<dp[H-1][W-1]<<el;
  }else cout<<-1<<el;
  
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int T=1;
    //cin>>T;
    while(T--)solve();
}

#else
#include <bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
//using mint=modint998244353;

  
// 関数テンプレート
template<typename T> bool chmax(T &m, const T q) {
    if (m < q) {m = q; return true;} else return false; }

template<typename T> bool chmin(T &m,const T q){
    if(m>q){m=q;return true;}else return false;
}
template<typename T>
bool grid_inside(const T h, const T w, const T &m, const T &n) {
    return (m >= 0 && m < h && n >= 0 && n < w);
}
// ループマクロ
#define rep(i,r) for(int i=0;(r)>i;i++)
#define REP(i,l,r) for(int i=(l);i<(r);i++)
#define rrep(i,N) for(int i=(N)-1;i>=0;i--)
#define RREP(i,r,N) for(int i=(N)-1;i>=r;i--)

// コンテナショートカット
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define el '\n'
#define spa " "
#define pb push_back

// YES/NO 出力
#define Yes cout<<"Yes"<<el
#define No cout<<"No"<<el
#define YES cout<<"YES"<<el
#define NO cout<<"NO"<<el
#define YESNO(bool) if(bool){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(bool) if(bool){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(bool) if(bool){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

// 型エイリアス
using ll=long long;
using ull=unsigned long long;
using pqgi=priority_queue<int, vector<int>, greater<int>>;
using pqgl=priority_queue<long long, vector<long long>, greater<long long>>;
using pqgpl=priority_queue<pair<long long,long long>,vector<pair<long long,long long>>,greater<pair<long long,long long>>>;
using pqgptpl=priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>>;
using pqi=priority_queue<int>;
using pii=pair<int, int>;
using tpi=tuple<int,int,int>;
using tpl=tuple<ll,ll,ll>;
using pll=pair<long long, long long>;
using vs=vector<string>;
using vi=vector<int>;
using vb=vector<bool>;
using vl=vector<long long>;
using vc=vector<char>;
using vvi=vector<vector<int>>;
using vvl=vector<vector<long long>>;
using vvc=vector<vector<char>>;
using vvb=vector<vector<bool>>;
using vvs=vector<vector<string>>;
using vpii=vector<pii>;
using vpll=vector<pll>;
using vvpii=vector<vector<pii>>;
using vvpll=vector<vector<pll>>;
using vtiii=vector<tuple<int, int, int>>;

// 定数
const long long INF=1e18;
const int mod=1e9+7;
//const int mod=998244353;
const int MAX=1e5+10;
const int MIN=-1e9;
const vpii dir={{1,0},{-1,0},{0,1},{0,-1}};
#endif


Submission Info

Submission Time
Task D - Teleport Maze
User yasaikeikaku
Language C++23 (GCC 15.2.0)
Score 400
Code Size 3916 Byte
Status AC
Exec Time 206 ms
Memory 34836 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 4
AC × 51
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3508 KiB
00_sample_01.txt AC 1 ms 3568 KiB
00_sample_02.txt AC 1 ms 3596 KiB
00_sample_03.txt AC 1 ms 3596 KiB
01_random_00.txt AC 1 ms 3592 KiB
01_random_01.txt AC 75 ms 9576 KiB
01_random_02.txt AC 67 ms 8540 KiB
01_random_03.txt AC 206 ms 29104 KiB
01_random_04.txt AC 121 ms 9124 KiB
01_random_05.txt AC 182 ms 16208 KiB
01_random_06.txt AC 149 ms 10404 KiB
01_random_07.txt AC 122 ms 9052 KiB
01_random_08.txt AC 1 ms 3496 KiB
01_random_09.txt AC 35 ms 5276 KiB
01_random_10.txt AC 70 ms 8488 KiB
01_random_11.txt AC 157 ms 27288 KiB
01_random_12.txt AC 122 ms 9436 KiB
01_random_13.txt AC 117 ms 9564 KiB
01_random_14.txt AC 127 ms 10400 KiB
01_random_15.txt AC 109 ms 9052 KiB
01_random_16.txt AC 1 ms 3728 KiB
01_random_17.txt AC 13 ms 4776 KiB
01_random_18.txt AC 8 ms 8492 KiB
01_random_19.txt AC 124 ms 26240 KiB
01_random_20.txt AC 125 ms 17672 KiB
01_random_21.txt AC 126 ms 18032 KiB
01_random_22.txt AC 9 ms 9164 KiB
01_random_23.txt AC 115 ms 13300 KiB
01_random_24.txt AC 1 ms 3496 KiB
01_random_25.txt AC 7 ms 4604 KiB
01_random_26.txt AC 8 ms 8504 KiB
01_random_27.txt AC 79 ms 18200 KiB
01_random_28.txt AC 81 ms 17660 KiB
01_random_29.txt AC 75 ms 13468 KiB
01_random_30.txt AC 80 ms 17672 KiB
01_random_31.txt AC 81 ms 17712 KiB
01_random_32.txt AC 1 ms 3600 KiB
01_random_33.txt AC 11 ms 6436 KiB
01_random_34.txt AC 7 ms 8576 KiB
01_random_35.txt AC 38 ms 13584 KiB
01_random_36.txt AC 7 ms 9048 KiB
01_random_37.txt AC 16 ms 9508 KiB
01_random_38.txt AC 34 ms 11676 KiB
01_random_39.txt AC 32 ms 11708 KiB
02_handmade_00.txt AC 63 ms 8616 KiB
02_handmade_01.txt AC 145 ms 34836 KiB
02_handmade_02.txt AC 4 ms 8572 KiB
02_handmade_03.txt AC 4 ms 8504 KiB
02_handmade_04.txt AC 13 ms 8492 KiB
02_handmade_05.txt AC 55 ms 8572 KiB
02_handmade_06.txt AC 148 ms 18912 KiB