#include <iostream>
using namespace std;
vector< vector< int >> hillSum( vector< vector< int >> & v, int k) {
int n = v.size ( ) ;
if ( ! n) return 0 ;
int m = v[ 0 ] .size ( ) ;
if ( ! m) return 0 ;
vector< vector< int >> ans;
for ( int i= 0 ; i< n+ k; i++ ) {
ans.push_back ( vector< int > ( m+ 2 * k,0 ) ) ;
if ( i< n)
for ( int j= 0 ; j< m; j++ )
ans[ i] [ j+ k] = v[ i] [ j] ;
if ( ! i) continue ;
for ( int j= 0 ; j< ans.size ( ) ; j++ ) {
int & ref = ans[ i] [ j] ;
if ( i- 1 < n&& j>= k& j< m+ k) ref + = v[ i- 1 ] [ j] ;
if ( j> 0 ) ref + = ans[ i- 1 ] [ j- 1 ] ;
if ( j+ 1 < m+ 2 * k) ref + = ans[ i- 1 ] [ j+ 1 ] ;
if ( i- 1 > 0 ) ref - = ans[ i- 2 ] [ j] ;
}
}
return ans;
}
vector< vector< int >> diamondSum( vector< vector< int >> & v, int k) {
vector< vector< int >> h = hillSum( v,k) ;
vector< vector< int >> ans = v;
for ( int i= 0 ; i< ans.size ( ) ; i++ ) {
for ( int j= 0 ; j< ans[ i] .size ( ) ; j++ ) {
v[ i] [ j] = h[ i+ k] [ j] ;
if ( ! i) continue ;
if ( i- k> 0 ) v[ i] [ j] + = h[ i- k- 1 ] [ j] ;
if ( j- k- 1 >= 0 ) v[ i] [ j] - = h[ i- 1 ] [ j- k- 1 ] ;
if ( j+ 1 < m+ k) v[ i] [ j] - = h[ i- 1 ] [ j+ k+ 1 ] ;
}
}
return ans;
}
int main( ) {
// your code goes here
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdmVjdG9yPHZlY3RvcjxpbnQ+PiBoaWxsU3VtKHZlY3Rvcjx2ZWN0b3I8aW50Pj4gJnYsIGludCBrKXsKCWludCBuID0gdi5zaXplKCk7CglpZighbikJcmV0dXJuIDA7CglpbnQgbSA9IHZbMF0uc2l6ZSgp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Owp9CgppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCXJldHVybiAwOwp9
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