Submission #3773988


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
int dp(int x,int y,int cnt);
#define INF 1000000000
int dx[]={0,1,1,1,0,-1};
int dy[]={-1,-1,0,1,1,0};
int h,w,sx,sy;
char mp[109][109];
int memo[109][109][10009];

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>h>>w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>mp[i][j];
      if(mp[i][j]=='s'){
	sx=j;
	sy=i;
	mp[i][j]='0';
      }
    }
  } 
  cout<<dp(0,0,0)<<endl;
  return(0);
}

int dp(int x,int y,int cnt){
  int rec=INF;
  if(memo[x][y][cnt]!=-1)return memo[x][y][cnt];
  if(mp[y][x]=='t')return 0;
  if(cnt>h*w)return INF;
  for(int i=0;i<6;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(0<=nx&&nx<w&&0<=ny&&ny<h){
      rec=min(rec,dp(nx,ny,cnt+1)+mp[y][x]-'0');
    }
  }
  return memo[x][y][cnt]=rec;
}

Submission Info

Submission Time
Task B - Office Ninja
User r1705
Language C++14 (GCC 5.4.1)
Score 0
Code Size 829 Byte
Status TLE
Exec Time 2105 ms
Memory 465536 KB

Judge Result

Set Name All
Score / Max Score 0 / 100
Status
TLE × 8
MLE × 20
Set Name Test Cases
All 001-sample-01.txt, 002-sample-02.txt, 003-minimum-01.txt, 004-random-01.txt, 005-random-02.txt, 006-random-03.txt, 007-random-04.txt, 008-random-05.txt, 009-random-06.txt, 010-random-07.txt, 011-random-08.txt, 012-random-09.txt, 013-random-10.txt, 014-random-11.txt, 015-random-12.txt, 016-random-13.txt, 017-random-14.txt, 018-random-15.txt, 019-random-16.txt, 020-random-17.txt, 021-random-18.txt, 022-random-19.txt, 023-random-20.txt, 024-maximum-01.txt, 025-maximum-02.txt, 026-maximum-03.txt, 027-maximum-04.txt, 999-handmade-01.txt
Case Name Status Exec Time Memory
001-sample-01.txt MLE 134 ms 464768 KB
002-sample-02.txt MLE 133 ms 464768 KB
003-minimum-01.txt MLE 133 ms 464768 KB
004-random-01.txt MLE 586 ms 465024 KB
005-random-02.txt MLE 216 ms 464896 KB
006-random-03.txt MLE 232 ms 464896 KB
007-random-04.txt MLE 135 ms 464768 KB
008-random-05.txt TLE 2105 ms 465280 KB
009-random-06.txt MLE 144 ms 464768 KB
010-random-07.txt MLE 188 ms 464896 KB
011-random-08.txt MLE 136 ms 464768 KB
012-random-09.txt MLE 288 ms 464896 KB
013-random-10.txt MLE 143 ms 464768 KB
014-random-11.txt MLE 750 ms 465024 KB
015-random-12.txt MLE 135 ms 464768 KB
016-random-13.txt MLE 156 ms 464768 KB
017-random-14.txt MLE 1253 ms 465152 KB
018-random-15.txt MLE 135 ms 464768 KB
019-random-16.txt TLE 2105 ms 465280 KB
020-random-17.txt MLE 136 ms 464768 KB
021-random-18.txt MLE 825 ms 465024 KB
022-random-19.txt TLE 2105 ms 465280 KB
023-random-20.txt MLE 142 ms 464768 KB
024-maximum-01.txt TLE 2105 ms 465536 KB
025-maximum-02.txt TLE 2105 ms 465536 KB
026-maximum-03.txt TLE 2105 ms 465536 KB
027-maximum-04.txt TLE 2105 ms 465536 KB
999-handmade-01.txt TLE 2105 ms 465536 KB