Submission #28031
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import java.util.*; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); int [] a = new int [n]; for ( int i = 0; i < n; ++i) { a[i] = scan.nextInt(); } boolean found = false ; for ( int bag = 0; bag < 1 << n; ++bag) { int total = 0; for ( int i = 0; i < n; ++i) { if ((bag & 1 << i) != 0) { total += a[i]; } } if (k == total) { found = true ; break ; } } System.out.println(found ? "OK" : "NG" ); } } |
ステータス
項目 | データ |
---|---|
問題 | 0064 - 足し算できる? |
ユーザー名 | KirikaYuumura |
投稿日時 | 2017-10-26 23:40:03 |
言語 | Java |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 571 Byte |
最大実行時間 | 126 ms |
最大メモリ使用量 | 16220 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
AddInput1.txt | AC | 95 ms | 15012 KB |
1
|
AddInput2.txt | AC | 76 ms | 14468 KB |
1
|
AddInput3.txt | AC | 77 ms | 15364 KB |
1
|
AddInput4.txt | AC | 126 ms | 16220 KB |
1
|
AddInput5.txt | AC | 69 ms | 14656 KB |
1
|
AddInput6.txt | AC | 65 ms | 14508 KB |
1
|