fork download
  1. #pragma GCC optimize "trapv"
  2. #include<bits/stdc++.h>
  3. #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
  4. using namespace std;
  5. #define ll long long
  6. #define pb push_back
  7. #define fo(i,a,b) for(int i=a;i<b;i++)
  8. #define foe(i,a,b) for (int i=a;i<=b;i++)
  9. int a[500][500],ans[500][500];
  10. int x,y;
  11.  
  12. int power(int i,int j){
  13. if (ans[i][j]!=INT_MAX) return ans[i][j];
  14. if (i==x-1)
  15. ans[i][j]=power(i,j+1)+a[i][j];
  16. else if (j==y-1)
  17. ans[i][j]=power(i+1,j)+a[i][j];
  18. else
  19. {
  20. ans[i][j]=min(min(power(i+1,j),power(i,j+1)),power(i+1,j+1))+a[i][j];
  21. }
  22. return a[i][j];
  23.  
  24. }
  25. void solve()
  26. {
  27. int m,n;
  28. cin>>m>>n>>x>>y;
  29.  
  30. fo(i,0,m)
  31. fo(j,0,n) cin>>a[i][j];
  32. fo(i,0,500) fo(j,0,500) ans[i][j]=INT_MAX;
  33. ans[x-1][y-1]=a[x-1][y-1];
  34. int p= power(0,0);
  35. p=p-a[0][0];
  36. if (a[0][0]>=p) cout<<"Escape\n";
  37. else
  38. {
  39. cout<<"Died\n";
  40. }
  41.  
  42. }
  43. signed main()
  44. {
  45. faster;
  46. int t;cin>>t;
  47. while(t--)
  48. solve();
  49. }
Time limit exceeded #stdin #stdout 5s 4304KB
stdin
Standard input is empty
stdout
Standard output is empty