fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. vector<vector<int>> hillSum(vector<vector<int>> &v, int k){
  5. int n = v.size();
  6. if(!n) return 0;
  7. int m = v[0].size();
  8. if(!m) return 0;
  9. vector<vector<int>> ans;
  10. for(int i=0; i<n+k; i++){
  11. ans.push_back(vector<int>(m+2*k,0));
  12. if(i<n)
  13. for(int j=0; j<m; j++)
  14. ans[i][j+k] = v[i][j];
  15. if(!i) continue;
  16. for(int j=0; j<ans.size(); j++){
  17. int& ref = ans[i][j];
  18. if(i-1<n&&j>=k&j<m+k) ref += v[i-1][j];
  19. if(j>0) ref += ans[i-1][j-1];
  20. if(j+1<m+2*k) ref += ans[i-1][j+1];
  21. if(i-1>0) ref -= ans[i-2][j];
  22. }
  23. }
  24. return ans;
  25. }
  26.  
  27. vector<vector<int>> diamondSum(vector<vector<int>> &v, int k){
  28. vector<vector<int>> h = hillSum(v,k);
  29. vector<vector<int>> ans = v;
  30. for(int i=0; i<ans.size(); i++){
  31. for(int j=0; j<ans[i].size(); j++){
  32. v[i][j] = h[i+k][j];
  33. if(!i) continue;
  34. if(i-k>0) v[i][j] += h[i-k-1][j];
  35. if(j-k-1>=0) v[i][j] -= h[i-1][j-k-1];
  36. if(j+1<m+k) v[i][j] -= h[i-1][j+k+1];
  37. }
  38. }
  39. return ans;
  40. }
  41.  
  42. int main() {
  43. // your code goes here
  44. return 0;
  45. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:1: error: ‘vector’ does not name a type; did you mean ‘perror’?
 vector<vector<int>> hillSum(vector<vector<int>> &v, int k){
 ^~~~~~
 perror
prog.cpp:27:1: error: ‘vector’ does not name a type; did you mean ‘perror’?
 vector<vector<int>> diamondSum(vector<vector<int>> &v, int k){
 ^~~~~~
 perror
stdout
Standard output is empty