結果
| 問題 |
No.2559 眩しい数直線
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-02 15:17:03 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 1,560 bytes |
| コンパイル時間 | 927 ms |
| コンパイル使用メモリ | 76,564 KB |
| 最終ジャッジ日時 | 2025-02-18 04:24:38 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
/**
* @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;
}