結果

問題 No.1007 コイン集め
ユーザー 37zigen37zigen
提出日時 2020-03-06 23:09:46
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 871 bytes
コンパイル時間 2,771 ms
コンパイル使用メモリ 78,340 KB
実行使用メモリ 49,460 KB
最終ジャッジ日時 2024-04-22 10:24:44
合計ジャッジ時間 10,910 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
41,300 KB
testcase_01 AC 113 ms
40,920 KB
testcase_02 AC 106 ms
39,964 KB
testcase_03 AC 108 ms
39,984 KB
testcase_04 AC 113 ms
40,948 KB
testcase_05 AC 107 ms
39,712 KB
testcase_06 AC 115 ms
40,976 KB
testcase_07 AC 110 ms
39,972 KB
testcase_08 WA -
testcase_09 AC 121 ms
41,428 KB
testcase_10 AC 117 ms
40,904 KB
testcase_11 AC 118 ms
41,540 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 629 ms
48,612 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		long[] A=new long[N];
		for(int i=0;i<N;++i) A[i]=sc.nextLong();
		--K;
		if(A[K]==0){
			System.out.println(0);
			return;
		}
		int r=K;
		int l=K;
		while(r+1<A.length&&A[r+1]>=1&&(r==K||A[r]==2))++r;
		while(l-1>=0&&A[l-1]>=1&&(l==K||A[l]==2))--l;
		long rc=0,lc=0;
		for(int i=K+1;i<=r;++i)rc+=A[i];
		for(int i=K-1;i>=l;--i)lc+=A[i];
		if(A[K]<=2){
			System.out.println(A[K]+Math.max(rc,lc));
		}else{
			System.out.println(A[K]+rc+lc);
		}
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}
0