結果

問題 No.1443 Andd
ユーザー tentententen
提出日時 2021-04-13 16:08:27
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,883 bytes
コンパイル時間 4,027 ms
コンパイル使用メモリ 75,348 KB
実行使用メモリ 74,340 KB
最終ジャッジ日時 2023-09-12 08:21:36
合計ジャッジ時間 8,837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,652 KB
testcase_01 AC 44 ms
49,164 KB
testcase_02 AC 44 ms
49,340 KB
testcase_03 AC 1,650 ms
68,096 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        boolean[][] exists = new boolean[n + 1][1024];
        exists[0][0] = true;
        HashSet<Integer> prev = new HashSet<>();
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= n; i++) {
            HashSet<Integer> next = new HashSet<>();
            int a = sc.nextInt();
            for (int j = 0; j < 1024; j++) {
                if (exists[i - 1][j]) {
                    exists[i][a & j] = true;
                    if (a + j >= 1024) {
                        next.add(a + j);
                    } else {
                        exists[i][a + j] = true;
                    }
                }
            }
            for (int x : prev) {
                exists[i][x & a] = true;
                next.add(x + a);
            }
            prev = next;
            sb.append(next.size() + getCount(exists[i])).append("\n");
        }
        System.out.print(sb);
    }
    
    static int getCount(boolean[] arr) {
        int count = 0;
        for (boolean b : arr) {
            if (b) {
                count++;
            }
        }
        return count;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0