結果

問題 No.2708 Jewel holder
ユーザー BBhorseBBhorse
提出日時 2024-03-31 15:25:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 970 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 175,852 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:25:32
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using ll=long long;
#define rep(i,s,n) for (ll i = (s); i < (n); i++)
using namespace std;
using Graph = vector<vector<ll>>;
ll MOD=1e9+7;
const ll INF=1e18;

int main(){
  ll h,w;
  cin>>h>>w;
  ll x0,y0,x1,y1;
  x0=0;y0=0;x1=h-1;y1=w-1;
  
  vector<char> G(h*w);

  rep(i,0,h){
    rep(j,0,w){
      cin>>G[i*w+j];
    }
  }

  queue<pair<ll,ll>> q;
  q.push({x0*w+y0,0});
  vector<ll> dx={1,0}; 
  vector<ll> dy={0,1};
  ll ans=0;

  while(!q.empty()){
    ll v=q.front().first;
    ll j=q.front().second;
    q.pop();
    if(v==h*w-1){
      ans++;
    }
    //cout<<v<<" ";
    ll vx=v/w;
    ll vy=v%w;
    if(G[v]=='o'){
      j++;
    }
    else if(G[v]=='x'){
      j--;
    }
    else{
      continue;
    }

    rep(i,0,2){
      ll nx=vx+dx[i];
      ll ny=vy+dy[i];
      ll nv=nx*w+ny;
      if(nx>=0 && nx<h && ny>=0 && ny<w && !(G[nv]=='x' && j<1) && !(G[nv]=='#')){
        q.push({nv,j});
      }
    }
  }
  cout<<ans<<endl;
}
0