雑記・まとめ

個人的な備忘録

typical90d

パッと見た瞬間に累積和

初めて解説に頼らずAC

まぁ☆2だしね

 

#include<bits/stdc++.h>
using namespace std;

int h, w;
int a[2009][2009], b[2009][2009], c[2009][2009];

int main(){

    cin >> h >> w;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin >> a[i][j];

    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            b[i][j] += b[i][j-1] + a[i][j];

    for(int j=1;j<=w;j++)
        for(int i=1;i<=h;i++)
            c[i][j] += c[i-1][j] + a[i][j];

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cout << b[i][w] + c[h][j] - a[i][j];
            if(j != w) cout << " ";
        }
        cout << endl;
    }
}