結果

問題 No.370 道路の掃除
ユーザー uafr_csuafr_cs
提出日時 2016-05-13 22:47:44
言語 Java19
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,817 bytes
コンパイル時間 3,041 ms
コンパイル使用メモリ 75,296 KB
実行使用メモリ 51,368 KB
最終ジャッジ日時 2023-07-28 07:22:43
合計ジャッジ時間 5,350 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,232 KB
testcase_01 AC 42 ms
49,368 KB
testcase_02 AC 42 ms
49,364 KB
testcase_03 AC 42 ms
49,352 KB
testcase_04 AC 42 ms
49,368 KB
testcase_05 AC 41 ms
49,200 KB
testcase_06 AC 42 ms
49,124 KB
testcase_07 AC 41 ms
49,128 KB
testcase_08 AC 42 ms
49,652 KB
testcase_09 AC 43 ms
49,344 KB
testcase_10 AC 43 ms
49,256 KB
testcase_11 AC 43 ms
49,196 KB
testcase_12 AC 42 ms
49,284 KB
testcase_13 AC 43 ms
49,400 KB
testcase_14 AC 42 ms
49,184 KB
testcase_15 AC 43 ms
49,204 KB
testcase_16 AC 43 ms
49,396 KB
testcase_17 AC 43 ms
49,376 KB
testcase_18 AC 45 ms
49,352 KB
testcase_19 AC 43 ms
49,664 KB
testcase_20 AC 53 ms
50,276 KB
testcase_21 AC 52 ms
49,968 KB
testcase_22 AC 50 ms
51,084 KB
testcase_23 AC 51 ms
50,244 KB
testcase_24 AC 46 ms
49,328 KB
testcase_25 AC 49 ms
49,444 KB
testcase_26 AC 54 ms
50,156 KB
testcase_27 AC 46 ms
49,216 KB
testcase_28 AC 47 ms
49,452 KB
testcase_29 AC 54 ms
50,424 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		int[] pos = new int[M];
		for(int i = 0; i < M; i++){
			pos[i] = sc.nextInt();
		}
		
		int answer = Integer.MAX_VALUE;
		for(int fst = 0; fst <= M - N; fst++){
			final int snd = fst + N - 1;
			
			answer = Math.min(answer, (Integer.signum(pos[fst]) == Integer.signum(pos[snd])) ? 
					Math.max(Math.abs(pos[fst]), Math.abs(pos[snd])) : 
						(Math.min(Math.abs(2 * pos[fst]) + Math.abs(pos[snd]), Math.abs(pos[fst]) + 2 * Math.abs(pos[snd]))));
			
		}
	
		System.out.println(answer);
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}
0