fork(4) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. // freopen("treasures.in","r",stdin);
  28. int T;
  29. scanf(" %d",&T);
  30.  
  31. for(int t =0; t < T; t++) {
  32. int N,M,Tt,x,y;
  33. scanf(" %d %d %d %d %d",&N,&M,&Tt,&x,&y);
  34. x--, y--;
  35. vector< vector<long long> > C(N, vector<long long>(M));
  36. for(int i =0; i < N*M; i++) scanf(" %lld",&C[i/M][i%M]);
  37. long long mod =1000000007;
  38.  
  39. vector< vector< vector<long long> > > A(Tt+1,vector< vector<long long> >(N+M,vector<long long>(N+M,0)));
  40. vector< vector< vector<long long> > > S(Tt+1,vector< vector<long long> >(N+M+1,vector<long long>(N+M+1,0)));
  41. for(int i =0; i < N; i++) for(int j =0; j < M; j++) A[1][i+j][i-j+M] =C[i][j];
  42. for(int ta =2; ta <= Tt; ta++) {
  43. for(int i =0; i < N+M; i++) for(int j =0; j < N+M; j++) {
  44. S[ta-1][i+1][j+1] =S[ta-1][i][j+1]+S[ta-1][i+1][j]-S[ta-1][i][j]+A[ta-1][i][j];
  45. S[ta-1][i+1][j+1] %=mod;
  46. if(S[ta-1][i+1][j+1] < 0) S[ta-1][i+1][j+1] +=mod;}
  47.  
  48. for(int i =0; i < N; i++) for(int j =0; j < M; j++) {
  49. int xa =max(0,i+j-(ta-1)), xb =min(N+M-1,i+j+(ta-1));
  50. int ya =max(0,i-j-(ta-1)+M), yb =min(N+M-1,i-j+(ta-1)+M);
  51. long long Sn =(S[ta-1][xb+1][yb+1]+S[ta-1][xa][ya]-S[ta-1][xa][yb+1]-S[ta-1][xb+1][ya])%mod;
  52. if(Sn < 0) Sn +=mod;
  53. A[ta][i+j][i-j+M] =Sn;}}
  54.  
  55. printf("Case %d: %lld\n",t+1,A[Tt][x+y][x-y+M]);}
  56. return 0;}
  57.  
  58. // look at my code
  59. // my code is amazing
Success #stdin #stdout 0s 3436KB
stdin
1
3 3 2 3 2
1 2 3
4 5 6
7 8 9
stdout
Case 1: 29