fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<bits/stdc++.h>
  3.  
  4. using namespace std;
  5. //
  6. //Written by : bkrtoni
  7. //ACMer , aabu - IT
  8. //<3 <3 <3
  9. //
  10.  
  11. // <Header>
  12. #define null NULL
  13. #define f(i,start,end) for(int i=(int)start;i<(int)end;i++)
  14. #define all(v) v.begin(),v.end()
  15. #define x first
  16. #define y second
  17. #define pb push_back
  18. #define del erase
  19. #define pf printf
  20. #define sc scanf
  21. #define test int t;cin>>t;while(t--)
  22. #define see(x) getline(cin,x)
  23. #define read(s) freopen(s,"r",stdin)
  24. #define out(s) freopen(s,"w",stdout)
  25. #define mp make_pair
  26. #define skip continue
  27. #define stop break;
  28. #define ios ios_base::sync_with_stdio(0)
  29. #define i1(x) sc("%d",&x)
  30. #define i2(x,y) sc("%d%d",&x,&y);
  31. #define i3(x,y,z) sc("%d%d%d",&x,&y,&z)
  32. #define toUpper(x) std::transform(x.begin(), x.end(), x.begin(), std::toupper);
  33. #define toLower(x) std::transform(x.begin(), x.end(), x.begin(), std::tolower);
  34.  
  35. typedef long long ll;
  36. typedef vector<int> vInt;
  37. typedef vector<string> vStr;
  38. typedef vector<ll> vLong;
  39. typedef vector<char> vChar;
  40. typedef vector<bool> vBool;
  41. typedef unsigned long long ull;
  42. typedef long double ldb;
  43. typedef map<string, string> dic;
  44. typedef pair<int, int> point;
  45.  
  46. FILE *stm;
  47. const double PI = 22.0 / 7.0;
  48. const ll MXN = 1e5 + 1;
  49. const ll MNN = 1e3 + 1;
  50. const ll MOD = 1e9 + 7;
  51. const ll INF = 1e18;
  52. // </Header>
  53. // <Function>
  54. bool srt(string a, string b){ return a.size() > b.size(); } //sort string by size
  55. int gcd(int a, int b){ if (b == 0)return a; else gcd(b, a % b); } //GCD
  56. int lcm(int a, int b){ return (b / gcd(a, b))*a; } //LCM
  57. // </Function>
  58. //int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
  59. //int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
  60. //int dim1 = 8;
  61. //int dim2 = 4;
  62. //int dx[] = { -1, 1, 0, 0 };
  63. //int dy[] = { 0, 0, 1, -1 };
  64.  
  65. int n;
  66. int M[11][11][11];
  67. bool vis[11][11][11];
  68. int res(int ff,int y,int x){
  69. if(ff<1 or x>10 or y>10 or vis[ff][y][x])return 0;
  70. vis[ff][y][x]=1;
  71. //pf("%d %d %d\n",ff,y,x);
  72. return M[ff][y][x]+
  73. res(ff-1,y,x)+
  74. res(ff,y+1,x)+
  75. res(ff,y,x+1);
  76. }
  77.  
  78.  
  79. int main(){
  80. #ifndef ONLINE_JUDGE
  81. read("Text.txt");
  82. out("output.txt");
  83. #define __builtin_popcount __popcnt
  84. #endif
  85. //read("jumping.in");
  86. ios;
  87.  
  88. test{
  89. memset(M,0,sizeof M);
  90. memset(vis,0,sizeof vis);
  91. cin>>n;
  92. int ff,x,y,h;
  93. f(i,0,n){
  94. cin>>ff>>y>>x>>h;
  95. M[ff][y][x]=h;
  96. }
  97. cout<<res(10,1,1)<<endl;
  98. }
  99.  
  100. return 0;
  101. }
Success #stdin #stdout 0s 3468KB
stdin
2
3
10 5 5 1
10 5 9 5
10 9 5 9
3
1 5 5 1
5 5 9 5
5 9 5 8
stdout
15
14