結果

問題 No.2559 眩しい数直線
ユーザー t98slider
提出日時 2023-12-02 14:35:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 2,014 ms
コンパイル使用メモリ 193,812 KB
最終ジャッジ日時 2025-02-18 03:39:04
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> dp(x);
    for(int i = 0; i < n; i++){
        int y, z;
        cin >> y >> z;
        y--;
        dp[y] = max(dp[y], z);
    }
    for(int i = 0; i + 1 < x; i++){
        dp[i + 1] = max(dp[i + 1], dp[i] - 1);
    }
    for(int i = x - 1; i >= 1; i--){
        dp[i - 1] = max(dp[i - 1], dp[i] - 1);
    }
    cout << dp << '\n';
}
0