結果

問題 No.3044 April Sum of Odd
ユーザー kusagame12kusagame12
提出日時 2023-11-07 18:25:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 595 ms / 2,000 ms
コード長 925 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 84,392 KB
実行使用メモリ 63,032 KB
最終ジャッジ日時 2023-11-07 18:25:16
合計ジャッジ時間 6,759 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
57,128 KB
testcase_01 AC 129 ms
57,816 KB
testcase_02 AC 119 ms
56,240 KB
testcase_03 AC 242 ms
60,828 KB
testcase_04 AC 263 ms
60,820 KB
testcase_05 AC 316 ms
62,196 KB
testcase_06 AC 300 ms
62,316 KB
testcase_07 AC 213 ms
59,744 KB
testcase_08 AC 229 ms
61,120 KB
testcase_09 AC 318 ms
61,832 KB
testcase_10 AC 595 ms
63,032 KB
testcase_11 AC 471 ms
61,792 KB
testcase_12 AC 131 ms
57,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0 ; i < n ; i++){
            as[i] = sc.nextInt();
        } 
        
        List<Long> ansList = new ArrayList<>();
        for (int i = 0 ; i < n ; i++){
            int a = as[i];
            if(a % 2 == 1){
                int cnt = 1;
                long sum = a;
                while(i < n - 1 && as[i+1] % 2 == 1){
                    sum += as[i+1];
                    cnt++;
                    i++;
                }
                if(cnt >= m){
                    ansList.add(sum);
                }
            }
        } 
        
        for (long i : ansList){
            System.out.println(i);
        }
        
    }
}
0