結果

問題 No.1007 コイン集め
ユーザー 37zigen37zigen
提出日時 2020-03-06 23:15:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 698 ms / 1,500 ms
コード長 871 bytes
コンパイル時間 2,983 ms
コンパイル使用メモリ 85,440 KB
実行使用メモリ 60,148 KB
最終ジャッジ日時 2024-04-22 10:28:56
合計ジャッジ時間 11,936 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
54,040 KB
testcase_01 AC 137 ms
54,320 KB
testcase_02 AC 135 ms
54,140 KB
testcase_03 AC 134 ms
54,128 KB
testcase_04 AC 133 ms
54,172 KB
testcase_05 AC 138 ms
54,088 KB
testcase_06 AC 136 ms
54,344 KB
testcase_07 AC 138 ms
54,164 KB
testcase_08 AC 137 ms
54,308 KB
testcase_09 AC 136 ms
54,236 KB
testcase_10 AC 136 ms
54,500 KB
testcase_11 AC 137 ms
54,124 KB
testcase_12 AC 671 ms
59,552 KB
testcase_13 AC 693 ms
59,468 KB
testcase_14 AC 656 ms
59,508 KB
testcase_15 AC 611 ms
59,156 KB
testcase_16 AC 577 ms
59,272 KB
testcase_17 AC 593 ms
58,908 KB
testcase_18 AC 698 ms
59,992 KB
testcase_19 AC 656 ms
59,396 KB
testcase_20 AC 686 ms
59,600 KB
testcase_21 AC 659 ms
60,148 KB
権限があれば一括ダウンロードができます

ソースコード

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]<=1){
			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