結果

問題 No.2662 Installing Cell Towers
ユーザー GOTKAKOGOTKAKO
提出日時 2024-03-07 22:54:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,060 bytes
コンパイル時間 2,489 ms
コンパイル使用メモリ 208,696 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-03-07 22:54:40
合計ジャッジ時間 4,682 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 45 ms
9,216 KB
testcase_06 AC 23 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 15 ms
6,676 KB
testcase_09 AC 5 ms
6,676 KB
testcase_10 AC 46 ms
9,216 KB
testcase_11 AC 41 ms
8,576 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 22 ms
6,676 KB
testcase_14 AC 47 ms
9,216 KB
testcase_15 AC 42 ms
9,216 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 37 ms
8,200 KB
testcase_18 AC 37 ms
8,200 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M; cin >> N >> M;
    vector<vector<long long>> add(N);
    while(M--){
        int pos,x; cin >> pos >> x; pos--;
        add.at(pos).push_back(x);
    }

    vector<long long> answer(N),minus(N);
    for(int i=0; i<N; i++) for(auto x : add.at(i)) answer.at(i) += x;

    long long now = 0,sum = 0;
    for(int i=0; i<N; i++){
        now -= minus.at(i);
        sum -= now;
        answer.at(i) += sum;
        
        for(auto x : add.at(i)){
            now++; sum += x;
            if(i+x+1 < N) minus.at(i+x+1)++;
        }
    }
    now = 0,sum = 0;
    minus.assign(N,0);
    for(int i=N-1; i>=0; i--){
        now -= minus.at(i);
        sum -= now;
        answer.at(i) += sum;

        for(auto x : add.at(i)){
            now++; sum += x;
            if(i-x-1 >= 0) minus.at(i-x-1)++;
        }
    }
    
    for(int i=0; i<N; i++){
        if(i) cout << " ";
        cout << answer.at(i);
    }
    cout << endl;
}
0