結果

問題 No.2559 眩しい数直線
ユーザー Maeda
提出日時 2025-09-09 17:21:21
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,060 bytes
コンパイル時間 3,333 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 51,620 KB
最終ジャッジ日時 2025-09-09 17:21:32
合計ジャッジ時間 9,559 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int x = scan.nextInt();
    	int[] list = new int[x];
    	for(int i = 0 ; i < n ; i++){
    		int a = scan.nextInt()-1;
    		int b = scan.nextInt();
    		list[a] = b;
    	}
    	int count = 1;
    	while(count > 0){
    		count = 0;
	    	for(int i = 1 ; i < x-1 ; i++){
	    		if(list[i-1] < list[i] -1 || list[i-1] -1 > list[i] ){
	    			count++;
	    			if( list[i-1] < list[i] -1 ){
	    			list[i-1] = list[i] - 1;
	    		}else if( list[i-1] -1 > list[i] ){
	    			list[i] = list[i-1] -1;
	    		}
	    		}
				if(list[i+1] < list[i] -1 || list[i+1] -1 > list[i] ){
					count++;
						    		if( list[i+1] < list[i] -1 ){
	    			list[i+1] = list[i] - 1;
	    		}else if( list[i+1] -1 > list[i] ){
	    			list[i] = list[i+1] -1;
	    		}
				}
	    	}
    	}
    	for(int i = 0 ; i < x ; i++){
    		System.out.print(list[i] + " ");
    	}
    	System.out.println("");
    }
}
0