Submission #13253


ソースコード

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
class E
{
static int F()
{
return int.Parse(Console.ReadLine());
}
static int[] G()
{
return Console.ReadLine().Split().Select(int.Parse).ToArray();
}
public static void Main()
{
var I = G();
var N = I[0];
var K = I[1];
var M0 = 0;
var M1 = 0;
var a = new int[N];
for (var i = 0; i < N; i++)
{
a[i] = F();
if (a[i] > 0) M1 += a[i];
else M0 += -a[i];
}
if (N == 0) Console.WriteLine(K == 0 ? "OK" : "NG");
else
{
var M = M1 + M0 + 1;
var dp = new bool[M];
dp[M0] = true;
foreach (var x in a)
{
if (x > 0) for (var i = M - 1; i >= x; i--) dp[i] |= dp[i - x];
else for (var i = 0; i - x < M; i++) dp[i] |= dp[i - x];
}
Console.WriteLine(M0 + K >= 0 && M0 + K < M && dp[M0 + K] ? "OK" : "NG");
}
}
}

ステータス

項目 データ
問題 0064 - 足し算できる?
ユーザー名 selpo
投稿日時 2017-02-28 17:31:28
言語 C#
状態 Accepted
得点 5
ソースコード長 1000 Byte
最大実行時間 68 ms
最大メモリ使用量 11248 KB

セット

セット 得点 Cases
1 ALL 5 / 5 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
AddInput1.txt AC 68 ms 7048 KB
1
AddInput2.txt AC 39 ms 9088 KB
1
AddInput3.txt AC 39 ms 9124 KB
1
AddInput4.txt AC 42 ms 9120 KB
1
AddInput5.txt AC 44 ms 11248 KB
1
AddInput6.txt AC 39 ms 9176 KB
1