結果

問題 No.3044 April Sum of Odd
ユーザー kusagame12kusagame12
提出日時 2023-11-07 18:20:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 998 bytes
コンパイル時間 2,359 ms
コンパイル使用メモリ 84,212 KB
実行使用メモリ 63,296 KB
最終ジャッジ日時 2023-11-07 18:20:58
合計ジャッジ時間 6,752 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
57,236 KB
testcase_01 AC 127 ms
57,212 KB
testcase_02 AC 127 ms
55,776 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 451 ms
61,736 KB
testcase_12 AC 126 ms
57,244 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<Integer> ansList = new ArrayList<>();
        for (int i = 0 ; i < n ; i++){
            int a = as[i];
            if(a % 2 == 1){
                int cnt = 1;
                int sum = a;
                if(i != n - 1){
                    while(i < n - 1 && as[i+1] % 2 == 1){
                        sum += as[i+1];
                        cnt++;
                        i++;
                    }
                }
                if(cnt >= m){
                    ansList.add(sum);
                }
            }
        } 
        
         for (int i : ansList){
            System.out.println(i);
         }
        
    }
}
0