結果
問題 |
No.1443 Andd
|
ユーザー |
![]() |
提出日時 | 2021-04-13 16:08:27 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,883 bytes |
コンパイル時間 | 2,166 ms |
コンパイル使用メモリ | 78,504 KB |
実行使用メモリ | 67,320 KB |
最終ジャッジ日時 | 2024-06-29 21:07:48 |
合計ジャッジ時間 | 7,752 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 1 TLE * 1 -- * 18 |
ソースコード
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(); } }