add things-dont-add-up

This commit is contained in:
Jacob Magnuson 2017-02-18 02:03:31 +00:00
parent c8ef4db162
commit 17c72df16d
5 changed files with 62 additions and 6 deletions

View file

@ -11,11 +11,11 @@ The first line contains three integers `A B N`. The second line contains a serie
#### Input Constraints
`0 < N < 16`
`0 < N <= 16`
`0 < A < B < 10000000`
`0 < A < B <= 10000000`
`0 < d_i < 10000000`
`0 < d_i <= 10000000`
#### Sample Input

View file

@ -1 +1,18 @@
# TODO
N = input()
if N == 0:
print '8 15 3\n4 9 11'
elif N == 1:
print '50 55 3\n7 24 33'
elif N == 2:
print '123 456 3\n5 7 11'
elif N == 3:
print '1 10000000 16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16'
else:
import random as r
r.seed(N)
lo = r.randint(1, 5000000)
hi = r.randint(lo + 1, 10000000)
N = 16
nugs = [str(r.randint(1, 10000000)) for i in range(16)]
print '%d %d 16\n%s' % (lo, hi, ' '.join(nugs))

View file

@ -0,0 +1,35 @@
import java.util.Scanner;
public class grader {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int A = s.nextInt(), B = s.nextInt(), N = s.nextInt(), count = 0;
int[] nugs = new int[N];
for(int i = 0; i < N; i++)
nugs[i] = s.nextInt();
// 1 10000000 16 788069 788246 419404 186300 847360 357398 969137 457317 770314 238904 904353 340869 513632 232159 549739 279898
boolean[] poss = new boolean[B + 1];
poss[0] = true;
for(int i = 0; i < A; i++)
if(poss[i])
for(int n : nugs)
if(i + n <= B)
poss[i + n] = true;
for(int i = A; i <= B; i++)
if(poss[i]) {
for(int n : nugs)
if(i + n <= B)
poss[i + n] = true;
}
else count++;
System.out.println(count);
}
}

View file

@ -1 +1 @@
# TODO
# done in grader.java

View file

@ -3,4 +3,8 @@ title: Things Don't Add Up
category: Programming
autogen: false
programming: true
value: 280
value: 210
test_cases: 15
time_limit: 1000
memory_limit: 256000