結果

問題 No.2559 眩しい数直線
ユーザー Keitaro NaruseKeitaro Naruse
提出日時 2023-12-02 15:17:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 78,740 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 15:17:05
合計ジャッジ時間 1,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 3 ms
6,676 KB
testcase_08 AC 3 ms
6,676 KB
testcase_09 AC 3 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 3 ms
6,676 KB
testcase_15 AC 3 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 3 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * @file 2559.cpp
 * @brief yukicoder 眩しい数直線
 * @author Keitaro Naruse
 * @date 2023-12-02
 * @copyright MIT License
 * @details https://yukicoder.me/problems/no/2559
 * */

// # Solution

#include <iostream>
#include <vector>
#include <algorithm>

template < class T >
std::ostream& operator<<( std::ostream& os, const std::vector< T >& v ) {
    for( auto it = v.begin( ); it != v.end( ); it++ ) {
        os << *it << ( it == --v.end( ) ? "" : " " );
    }
    return os;
}

int main( ) {
    //  Read N = [ 1, 10^3 ], X = [ 1, 10^3 ]
    int N, X;
    std::cin >> N >> X;
    //  Read Ai = [ 1, X ], Bi = [ 1, 10^3 ]
    std::vector< int > A( N ), B( N );
    for( int i = 0; i < N; i++ ) {
        std::cin >> A.at( i ) >> B.at( i );
    }

    //  Main::Preprocess
    for( int i = 0; i < N; i++ ) {
        A.at( i )--;
    }

    //  Main::Find a solution
    std::vector< int > L( X, 0 );
    for( int i = 0; i < N; i++ ) {
        for( int j = 0; j < B.at( i ); j++ ) {
            if( j == 0 ) {
                L.at( A.at( i ) ) = std::max( L.at( A.at( i ) ), B.at( i ) );
            } else {
                if( A.at( i ) - j >= 0 ) {
                    L.at( A.at( i ) - j ) = std::max( L.at( A.at( i ) - j ), B.at( i ) - j );
                }
                if( A.at( i ) + j < X ) {
                    L.at( A.at( i ) + j ) = std::max( L.at( A.at( i ) + j ), B.at( i ) - j );
                }
            }
        }
    }
    //  Main::Output a solution
    std::cout << L << std::endl;

    //  Finalize
    return 0;
}
0