提出 #43142095


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define loop(i,l,n) for(int i=l;i<n;i++)
long long int dp[501][501];
bool ans(int i,int j,int n,int m,string arr[],vector<vector<bool>>&visited,map<char,char>&hash,char back){
  
   // cout<<"hello "<<i<<" "<<j<<"\n";
  if((i>n) || (i>m) || (i<0) || (j<0))return false;
  if(visited[i][j])return false;
 
  if((arr[i][j])!=hash[back])return false;
  visited[i][j]=true;
  
  if((i==n) &&(j==m))return true;
 if(dp[i][j]!=-1)return dp[i][j];
  bool ans1=ans(i+1,j,n,m,arr,visited,hash,arr[i][j]);
  bool ans2=ans(i-1,j,n,m,arr,visited,hash,arr[i][j]);
  bool ans3=ans(i,j+1,n,m,arr,visited,hash,arr[i][j]);
  bool ans4=ans(i,j-1,n,m,arr,visited,hash,arr[i][j]);
  return dp[i][j]=(ans1||ans2||ans3||ans4);
}
void solve_tc(){
 ll n,m;
 for(int i=0;i<501;i++){
  for(int j=0;j<501;j++)dp[i][j]=-1;
 }
 cin>>n>>m;
 string arr[n];
 loop(i,0,n)cin>>arr[i];
 map<char,char>hash;
 hash['s']='n';
 hash['n']='u';
 hash['u']='k';
 hash['k']='e';
 hash['e']='s';
 // int m=arr[0].length();
 vector<vector<bool>>visited(n,vector<bool>(m,false));
 bool anss=ans(0,0,n-1,m-1,arr,visited,hash,'e');
 if(anss)cout<<"Yes\n";
 else cout<<"No\n";
 
}

int main() {
ios_base::sync_with_stdio(false);
      cin.tie(NULL);
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
 freopen("outpu.txt", "w", stdout);
  #endif
ll test_case=1;
// cin>>test_case;

for(int i=1;i<=test_case;i++){
 
  // cout<<"Case #"<<i<<": ";
  solve_tc();
}
 


  return 0; 

}
  

 
  

 


 
  

提出情報

提出日時
問題 D - Snuke Maze
ユーザ rishi_22
言語 C++ (GCC 9.2.1)
得点 0
コード長 1621 Byte
結果 WA
実行時間 48 ms
メモリ 44860 KiB

コンパイルエラー

./Main.cpp: In function ‘bool ans(int, int, int, int, std::string*, std::vector<std::vector<bool> >&, std::map<char, char>&, char)’:
./Main.cpp:22:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   22 |   return dp[i][j]=(ans1||ans2||ans3||ans4);
      |          ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 400
結果
AC × 3
AC × 32
WA × 4
セット名 テストケース
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_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, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 02_random2_08.txt, 02_random2_09.txt, 02_random2_10.txt, 02_random2_11.txt, 02_random2_12.txt, 02_random2_13.txt, 02_random2_14.txt, 02_random2_15.txt, 02_random2_16.txt, 02_random2_17.txt, 02_random2_18.txt, 02_random2_19.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 9 ms 5500 KiB
00_sample_01.txt AC 4 ms 5516 KiB
00_sample_02.txt AC 4 ms 5384 KiB
01_random_00.txt AC 5 ms 5448 KiB
01_random_01.txt AC 2 ms 5604 KiB
01_random_02.txt AC 5 ms 5748 KiB
01_random_03.txt AC 7 ms 5512 KiB
01_random_04.txt AC 5 ms 5648 KiB
01_random_05.txt AC 3 ms 5448 KiB
01_random_06.txt AC 3 ms 5568 KiB
01_random_07.txt AC 3 ms 5452 KiB
02_random2_00.txt WA 31 ms 12892 KiB
02_random2_01.txt AC 28 ms 12268 KiB
02_random2_02.txt AC 23 ms 12004 KiB
02_random2_03.txt AC 27 ms 11732 KiB
02_random2_04.txt AC 23 ms 12728 KiB
02_random2_05.txt AC 5 ms 5908 KiB
02_random2_06.txt WA 26 ms 11456 KiB
02_random2_07.txt AC 29 ms 11664 KiB
02_random2_08.txt WA 25 ms 10420 KiB
02_random2_09.txt AC 5 ms 5876 KiB
02_random2_10.txt WA 28 ms 11360 KiB
02_random2_11.txt AC 5 ms 5892 KiB
02_random2_12.txt AC 31 ms 10028 KiB
02_random2_13.txt AC 22 ms 9588 KiB
02_random2_14.txt AC 7 ms 5816 KiB
02_random2_15.txt AC 28 ms 9276 KiB
02_random2_16.txt AC 6 ms 5844 KiB
02_random2_17.txt AC 7 ms 5840 KiB
02_random2_18.txt AC 24 ms 8856 KiB
02_random2_19.txt AC 26 ms 8976 KiB
03_handmade_00.txt AC 4 ms 5548 KiB
03_handmade_01.txt AC 21 ms 6032 KiB
03_handmade_02.txt AC 18 ms 6048 KiB
03_handmade_03.txt AC 48 ms 44748 KiB
03_handmade_04.txt AC 40 ms 44860 KiB