結果
問題 | No.1457 ツブ消ししとるなHard |
ユーザー | neko_the_shadow |
提出日時 | 2021-04-06 12:01:24 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 147 ms / 2,000 ms |
コード長 | 6,246 bytes |
コンパイル時間 | 2,361 ms |
コンパイル使用メモリ | 83,108 KB |
実行使用メモリ | 85,872 KB |
最終ジャッジ日時 | 2024-06-10 22:38:53 |
合計ジャッジ時間 | 5,214 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
50,712 KB |
testcase_01 | AC | 60 ms
51,200 KB |
testcase_02 | AC | 59 ms
50,572 KB |
testcase_03 | AC | 60 ms
50,888 KB |
testcase_04 | AC | 115 ms
76,268 KB |
testcase_05 | AC | 130 ms
75,548 KB |
testcase_06 | AC | 118 ms
76,696 KB |
testcase_07 | AC | 58 ms
51,192 KB |
testcase_08 | AC | 56 ms
50,576 KB |
testcase_09 | AC | 89 ms
54,992 KB |
testcase_10 | AC | 81 ms
55,108 KB |
testcase_11 | AC | 59 ms
51,088 KB |
testcase_12 | AC | 140 ms
76,796 KB |
testcase_13 | AC | 94 ms
54,768 KB |
testcase_14 | AC | 68 ms
51,556 KB |
testcase_15 | AC | 105 ms
57,520 KB |
testcase_16 | AC | 147 ms
85,872 KB |
testcase_17 | AC | 57 ms
50,776 KB |
testcase_18 | AC | 60 ms
50,628 KB |
testcase_19 | AC | 103 ms
68,396 KB |
testcase_20 | AC | 59 ms
51,108 KB |
ソースコード
package _1457; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.io.UncheckedIOException; import java.lang.reflect.Array; import java.util.Arrays; import java.util.Objects; public class Main { public void exec() { int n = stdin.nextInt(); int m = stdin.nextInt(); int x = stdin.nextInt(); int y = stdin.nextInt(); int z = stdin.nextInt(); int[] a = stdin.nextIntArray(n); if (Arrays.stream(a).filter(v -> v >= x).count() >= m) { stdout.println("Handicapped"); return; } int r = Arrays.stream(a).sum(); long[][][] dp = new long[n+1][m+1][r+1]; dp[0][0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j <= m; j++) { for (int k = 0; k <= r; k++) { if (a[i] <= y) { dp[i+1][j][k] += dp[i][j][k]; } else if (x <= a[i]) { if (j+1<=m && k+a[i]<=r)dp[i+1][j+1][k+a[i]] += dp[i][j][k]; } else { dp[i+1][j][k] += dp[i][j][k]; if (j+1<=m && k+a[i]<=r) dp[i+1][j+1][k+a[i]] += dp[i][j][k]; } } } } long ans = 0; for (int j = 1; j <= m; j++) { for (int k = 0; k <= r; k++) { if (k%j==0 && k/j==z) { ans += dp[n][j][k]; } } } stdout.println(ans); } private static final Stdin stdin = new Stdin(System.in); private static final Stdout stdout = new Stdout(System.out); private static final Stderr stderr = new Stderr(System.err, false); public static void main(String[] args) { try { new Main().exec(); } finally { stdout.flush(); } } // ASCII ONLY public static class Stdin { private InputStream in; private byte[] buf; private int ptr; private int len; public Stdin(InputStream in) { this.in = in; this.buf = new byte[1024]; this.ptr = 0; this.len = 0; } public String nextString() { StringBuilder sb = new StringBuilder(); byte b; while ((b = read()) != -1) { sb.appendCodePoint(b); } return sb.toString(); } public int nextInt() { return (int)nextLong(); } public double nextDouble() { return Double.parseDouble(nextString()); } public long nextLong() { boolean negative = false; int x = 0; byte b = read(); if (b == '-') { negative = true; } else { x += b-'0'; } while ((b=read()) != -1) { x *= 10; x += b-'0'; } return negative ? -x : x; } private byte read() { byte b = readByte(); if (b == '\r') { readByte(); // LFを読み飛ばす return -1; } else if (b == '\n' || b == ' ') { return -1; } else { return b; } } private byte readByte(){ if (len == ptr) { try { ptr = 0; len = in.read(buf); if (len == -1) return -1; } catch (IOException e) { throw new UncheckedIOException(e); } } return buf[ptr++]; } public String[] nextStringArray(int n) { String[] a = new String[n]; for (int i = 0; i < n; i++) a[i] = nextString(); return a; } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nextDoubleArray(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } public static class Stdout { private PrintWriter stdout; public Stdout(PrintStream stdout) { this.stdout = new PrintWriter(stdout, false); } public void println(Object ... objs) { for (int i = 0, len = objs.length; i < len; i++) { stdout.print(objs[i]); if (i != len-1) stdout.print(' '); } stdout.println(); } public void flush() { stdout.flush(); } } public static class Stderr { private PrintWriter stderr; private boolean debug; public Stderr(PrintStream stderr, boolean debug) { this.stderr = new PrintWriter(stderr, false); this.debug = debug; } public void println(Object ... objs) { if (!debug) return ; stderr.print("DEBUG: "); for (int i = 0, len = objs.length; i < len; i++) { stderr.print(deepToString(objs[i])); if (i != len-1) stderr.print(' '); } stderr.println(); stderr.flush(); } private String deepToString(Object o) { if (o == null) { return "null"; } // 配列の場合 if (o.getClass().isArray()) { int len = Array.getLength(o); String[] tokens = new String[len]; for (int i = 0; i < len; i++) { tokens[i] = deepToString(Array.get(o, i)); } return "{" + String.join(", ", tokens) + "}"; } return Objects.toString(o); } } }