Submission #68766218


Source Code Expand

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef pair<ll,ll> pl;
typedef pair<ll,pl> ppl;
typedef pair<ll,ppl> pppl;
typedef pair<ll,pppl> pppppl;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) begin(a),end(a)
#define sz(a) (int)(a).size()
#define F first
#define S second
#define bs(A,x) binary_search(all(A),x)
#define lb(A,x) (ll)(lower_bound(all(A),x)-A.begin())
#define ub(A,x) (ll)(upper_bound(all(A),x)-A.begin())
#define cou(A,x) (ll)(upper_bound(all(A),x)-lower_bound(all(A),x))
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
/*
using mint=modint998244353;
const ll mod=998244353;
//*/
/*
using mint=modint1000000007;
const ll mod=1000000007;
//*/
using mint=modint;
//*
typedef vector<mint> vm;
typedef vector<vm> vvm;
typedef vector<vvm> vvvm;
typedef vector<vvvm> vvvvm;
ostream&operator<<(ostream&os,mint a){os<<a.val();return os;}
istream&operator>>(istream&is,mint&a){int x;is>>x;a=mint(x);return is;}
//*/
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>p){os<<p.F<<" "<<p.S;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.F>>p.S;return is;}
template<typename T>ostream&operator<<(ostream&os,vector<T>v){rep(i,0,sz(v))os<<v[i]<<(i+1!=sz(v)?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
int main(){
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  ll h,w;cin>>h>>w;
  vector<string>S(h);cin>>S;
  vvvl D(2,vvl(h,vl(w,1e18)));
  queue<ppl>Q;
  rep(i,0,h)rep(j,0,w)if(S[i][j]=='S'){
    Q.emplace(ppl(0,pl(i,j)));
    D[0][i][j]=0;
  }
  vl dx={1,-1,0,0},dy={0,0,-1,1};
  while(sz(Q)){
    auto[s,p]=Q.front();Q.pop();
    auto[x,y]=p;
    ll d=D[s][x][y];
    rep(_,0,4){
      ll nx=x+dx[_],ny=y+dy[_];
      if(nx<0||ny<0||nx>=h||ny>=w)continue;
      if(S[nx][ny]=='#')continue;
      if(s==0&&S[nx][ny]=='x')continue;
      if(s==1&&S[nx][ny]=='o')continue;
      ll ns=s;
      if(S[nx][ny]=='?')ns=!ns;
      if(chmin(D[ns][nx][ny],d+1)){
        Q.emplace(ppl(ns,pl(nx,ny)));
      }
    }
  }
  rep(i,0,h)rep(j,0,w)if(S[i][j]=='G'){
    ll ans=min(D[0][i][j],D[1][i][j]);
    if(ans>1e17)ans=-1;
    cout<<ans<<endl;
  }
  return 0;
}

Submission Info

Submission Time
Task D - Toggle Maze
User TKTYI
Language C++ 20 (gcc 12.2)
Score 400
Code Size 2870 Byte
Status AC
Exec Time 28 ms
Memory 9568 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 67
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 02_random_32.txt, 02_random_33.txt, 02_random_34.txt, 02_random_35.txt, 02_random_36.txt, 02_random_37.txt, 02_random_38.txt, 02_random_39.txt, 02_random_40.txt, 02_random_41.txt, 02_random_42.txt, 02_random_43.txt, 02_random_44.txt, 02_random_45.txt, 02_random_46.txt, 02_random_47.txt, 02_random_48.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3484 KiB
00_sample_01.txt AC 1 ms 3484 KiB
00_sample_02.txt AC 1 ms 3412 KiB
01_handmade_00.txt AC 11 ms 9436 KiB
01_handmade_01.txt AC 13 ms 9432 KiB
01_handmade_02.txt AC 11 ms 9428 KiB
01_handmade_03.txt AC 12 ms 9568 KiB
01_handmade_04.txt AC 1 ms 3520 KiB
01_handmade_05.txt AC 1 ms 3476 KiB
01_handmade_06.txt AC 1 ms 3612 KiB
01_handmade_07.txt AC 1 ms 3556 KiB
01_handmade_08.txt AC 1 ms 3624 KiB
01_handmade_09.txt AC 8 ms 9204 KiB
01_handmade_10.txt AC 8 ms 9176 KiB
01_handmade_11.txt AC 16 ms 9468 KiB
01_handmade_12.txt AC 15 ms 9564 KiB
01_handmade_13.txt AC 8 ms 9468 KiB
01_handmade_14.txt AC 9 ms 9432 KiB
02_random_00.txt AC 1 ms 3588 KiB
02_random_01.txt AC 13 ms 7616 KiB
02_random_02.txt AC 1 ms 3816 KiB
02_random_03.txt AC 15 ms 8448 KiB
02_random_04.txt AC 1 ms 4064 KiB
02_random_05.txt AC 17 ms 9428 KiB
02_random_06.txt AC 14 ms 8480 KiB
02_random_07.txt AC 17 ms 9432 KiB
02_random_08.txt AC 2 ms 4576 KiB
02_random_09.txt AC 17 ms 9464 KiB
02_random_10.txt AC 4 ms 9400 KiB
02_random_11.txt AC 17 ms 9472 KiB
02_random_12.txt AC 4 ms 9468 KiB
02_random_13.txt AC 4 ms 4516 KiB
02_random_14.txt AC 15 ms 8156 KiB
02_random_15.txt AC 1 ms 3688 KiB
02_random_16.txt AC 17 ms 9496 KiB
02_random_17.txt AC 1 ms 3772 KiB
02_random_18.txt AC 18 ms 9472 KiB
02_random_19.txt AC 2 ms 3904 KiB
02_random_20.txt AC 18 ms 9472 KiB
02_random_21.txt AC 1 ms 3528 KiB
02_random_22.txt AC 18 ms 9480 KiB
02_random_23.txt AC 1 ms 3704 KiB
02_random_24.txt AC 6 ms 7344 KiB
02_random_25.txt AC 2 ms 5272 KiB
02_random_26.txt AC 6 ms 5516 KiB
02_random_27.txt AC 3 ms 4188 KiB
02_random_28.txt AC 9 ms 9204 KiB
02_random_29.txt AC 4 ms 4944 KiB
02_random_30.txt AC 14 ms 9236 KiB
02_random_31.txt AC 4 ms 8152 KiB
02_random_32.txt AC 6 ms 9268 KiB
02_random_33.txt AC 4 ms 6300 KiB
02_random_34.txt AC 10 ms 9300 KiB
02_random_35.txt AC 4 ms 4148 KiB
02_random_36.txt AC 16 ms 6568 KiB
02_random_37.txt AC 10 ms 5252 KiB
02_random_38.txt AC 28 ms 9496 KiB
02_random_39.txt AC 22 ms 8372 KiB
02_random_40.txt AC 28 ms 9476 KiB
02_random_41.txt AC 1 ms 3520 KiB
02_random_42.txt AC 1 ms 3644 KiB
02_random_43.txt AC 1 ms 3620 KiB
02_random_44.txt AC 1 ms 3724 KiB
02_random_45.txt AC 1 ms 3660 KiB
02_random_46.txt AC 1 ms 3484 KiB
02_random_47.txt AC 1 ms 3644 KiB
02_random_48.txt AC 1 ms 3584 KiB