結果
問題 | No.1111 コード進行 |
ユーザー | CuriousFairy315 |
提出日時 | 2020-07-10 21:41:44 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 344 ms / 2,000 ms |
コード長 | 7,156 bytes |
コンパイル時間 | 2,738 ms |
コンパイル使用メモリ | 86,388 KB |
実行使用メモリ | 180,392 KB |
最終ジャッジ日時 | 2024-10-11 08:32:01 |
合計ジャッジ時間 | 8,799 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
36,756 KB |
testcase_01 | AC | 54 ms
36,948 KB |
testcase_02 | AC | 54 ms
36,308 KB |
testcase_03 | AC | 55 ms
36,688 KB |
testcase_04 | AC | 54 ms
36,752 KB |
testcase_05 | AC | 54 ms
38,468 KB |
testcase_06 | AC | 76 ms
39,776 KB |
testcase_07 | AC | 65 ms
39,248 KB |
testcase_08 | AC | 59 ms
37,456 KB |
testcase_09 | AC | 61 ms
38,352 KB |
testcase_10 | AC | 61 ms
40,460 KB |
testcase_11 | AC | 57 ms
37,556 KB |
testcase_12 | AC | 82 ms
40,188 KB |
testcase_13 | AC | 59 ms
38,236 KB |
testcase_14 | AC | 97 ms
45,556 KB |
testcase_15 | AC | 57 ms
36,828 KB |
testcase_16 | AC | 83 ms
40,040 KB |
testcase_17 | AC | 57 ms
40,144 KB |
testcase_18 | AC | 55 ms
37,524 KB |
testcase_19 | AC | 55 ms
37,204 KB |
testcase_20 | AC | 57 ms
38,036 KB |
testcase_21 | AC | 55 ms
36,852 KB |
testcase_22 | AC | 63 ms
44,396 KB |
testcase_23 | AC | 60 ms
38,504 KB |
testcase_24 | AC | 58 ms
38,968 KB |
testcase_25 | AC | 95 ms
45,740 KB |
testcase_26 | AC | 79 ms
39,500 KB |
testcase_27 | AC | 56 ms
37,508 KB |
testcase_28 | AC | 124 ms
101,864 KB |
testcase_29 | AC | 105 ms
65,916 KB |
testcase_30 | AC | 131 ms
74,968 KB |
testcase_31 | AC | 68 ms
43,852 KB |
testcase_32 | AC | 144 ms
75,472 KB |
testcase_33 | AC | 134 ms
65,540 KB |
testcase_34 | AC | 119 ms
77,740 KB |
testcase_35 | AC | 132 ms
101,960 KB |
testcase_36 | AC | 215 ms
100,752 KB |
testcase_37 | AC | 117 ms
54,536 KB |
testcase_38 | AC | 102 ms
50,324 KB |
testcase_39 | AC | 166 ms
74,716 KB |
testcase_40 | AC | 190 ms
100,684 KB |
testcase_41 | AC | 135 ms
101,548 KB |
testcase_42 | AC | 134 ms
66,228 KB |
testcase_43 | AC | 137 ms
66,152 KB |
testcase_44 | AC | 103 ms
54,212 KB |
testcase_45 | AC | 137 ms
75,228 KB |
testcase_46 | AC | 67 ms
39,952 KB |
testcase_47 | AC | 344 ms
180,392 KB |
testcase_48 | AC | 69 ms
39,768 KB |
testcase_49 | AC | 66 ms
39,676 KB |
ソースコード
public class Main { public static void main(String[] args) { new Main(); } public Main() { FastScanner fs = new FastScanner(); java.io.PrintWriter out = new java.io.PrintWriter(System.out); solve(fs, out); out.flush(); } public void solve(FastScanner fs, java.io.PrintWriter out) { int N = fs.nextInt(), M = fs.nextInt(), K = fs.nextInt(); Connect[] connect = new Connect[M]; for (int i = 0;i < M;++ i) { connect[i] = new Connect(fs.nextInt() - 1, fs.nextInt() - 1, fs.nextInt()); } final int MOD = 1_000_000_007; // dp[i][j][k]: i個繋げて現在のコードがjになり、複雑度合計がkになるようなものの個数 int[][][] dp = new int[N + 1][300][K + 1]; for (int i = 0;i < 300;++ i) dp[1][i][0] = 1; for (int i = 1;i < N;++ i) { for (int j = 0;j <= K;++ j) { for (Connect k : connect) { if (j + k.c > K) continue; dp[i + 1][k.q][j + k.c] = (dp[i + 1][k.q][j + k.c] + dp[i][k.p][j]) % MOD; } } } int ans = 0; for (int i = 0;i < 300;++ i) ans = (ans + dp[N][i][K]) % MOD; out.println(ans); } class Connect { int p, q, c; Connect(int P, int Q, int C) { p = P; q = Q; c = C; } } static class FastScanner { private final java.io.InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) return true; ptr = 0; try { buflen = in.read(buffer); } catch (java.io.IOException e) { e.printStackTrace(); } return buflen > 0; } private byte readByte() { return hasNextByte() ? buffer[ptr++ ] : -1; } private static boolean isPrintableChar(byte c) { return 32 < c || c < 0; } private static boolean isNumber(int c) { return '0' <= c && c <= '9'; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++ ; return hasNextByte(); } public String next() { if (!hasNext()) throw new java.util.NoSuchElementException(); StringBuilder sb = new StringBuilder(); byte b; while (isPrintableChar(b = readByte())) sb.appendCodePoint(b); return sb.toString(); } public final long nextLong() { if (!hasNext()) throw new java.util.NoSuchElementException(); long n = 0; try { byte b = readByte(); if (b == '-') { while(isNumber(b = readByte())) n = n * 10 + '0' - b; return n; } else if (!isNumber(b)) throw new NumberFormatException(); do n = n * 10 + b - '0'; while (isNumber(b = readByte())); } catch (java.util.NoSuchElementException e) { } return n; } public final int nextInt() { if (!hasNext()) throw new java.util.NoSuchElementException(); int n = 0; try { byte b = readByte(); if (b == '-') { while(isNumber(b = readByte())) n = n * 10 + '0' - b; return n; } else if (!isNumber(b)) throw new NumberFormatException(); do n = n * 10 + b - '0'; while (isNumber(b = readByte())); } catch (java.util.NoSuchElementException e) { } return n; } public double nextDouble() { return Double.parseDouble(next()); } } public static class Arrays { public static void sort(final int[] array) { int l, min = 0xFFFFFFFF, max = 0; for (l = 0;l < array.length;++ l) { int i = array[l]; min &= i; max |= i; if ((i & 0x80000000) == 0) break; } for (int r = l + 1;r < array.length;++ r) { int i = array[r]; min &= i; max |= i; if ((i & 0x80000000) != 0) { array[r] = array[l]; array[l ++] = i; } } int use = min ^ max, bit = Integer.highestOneBit(use & 0x7FFFFFFF); if (bit == 0) return; sort(array, 0, l, use, bit); sort(array, l, array.length, use, bit); } private static void sort(final int[] array, final int left, final int right, final int use, int digit) { if (right - left <= 96) { for (int i = left + 1;i < right;++ i) { int tmp = array[i], tmp2, j; for (j = i;j > left && (tmp2 = array[j - 1]) > tmp;-- j) array[j] = tmp2; array[j] = tmp; } return; } int l = left; while(l < right && (array[l] & digit) == 0) ++ l; for (int r = l + 1;r < right;++ r) { int i = array[r]; if ((i & digit) == 0) { array[r] = array[l]; array[l ++] = i; } } if ((digit = Integer.highestOneBit(use & digit - 1)) == 0) return; sort(array, left, l, use, digit); sort(array, l, right, use, digit); } public static void sort(final long[] array) { int l; long min = 0xFFFFFFFFFFFFFFFFL, max = 0; for (l = 0;l < array.length;++ l) { long i = array[l]; min &= i; max |= i; if ((i & 0x8000000000000000L) == 0) break; } for (int r = l + 1;r < array.length;++ r) { long i = array[r]; min &= i; max |= i; if ((i & 0x8000000000000000L) != 0) { array[r] = array[l]; array[l ++] = i; } } long use = min ^ max, bit = Long.highestOneBit(use & 0x7FFFFFFFFFFFFFFFL); if (bit == 0) return; sort(array, 0, l, use, bit); sort(array, l, array.length, use, bit); } private static void sort(final long[] array, final int left, final int right, final long use, long digit) { if (right - left <= 96) { for (int i = left + 1, j;i < right;++ i) { long tmp = array[i], tmp2; for (j = i;j > left && (tmp2 = array[j - 1]) > tmp;-- j) array[j] = tmp2; array[j] = tmp; } return; } int l = left; while(l < right && (array[l] & digit) == 0) ++ l; for (int r = l + 1;r < right;++ r) { long i = array[r]; if ((i & digit) == 0) { array[r] = array[l]; array[l ++] = i; } } if ((digit = Long.highestOneBit(use & digit - 1)) == 0) return; sort(array, left, l, use, digit); sort(array, l, right, use, digit); } } public static class IntMath { public static int gcd(int a, int b) { while (a != 0) if ((b %= a) != 0) a %= b; else return a; return b; } public static int gcd(int... array) { int ret = array[0]; for (int i = 1;i < array.length;++ i) ret = gcd(ret, array[i]); return ret; } public static long gcd(long a, long b) { while (a != 0) if ((b %= a) != 0) a %= b; else return a; return b; } public static long gcd(long... array) { long ret = array[0]; for (int i = 1;i < array.length;++ i) ret = gcd(ret, array[i]); return ret; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } public static int pow(int a, int b) { int ans = 1; for (int mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul; return ans; } public static long powLong(long a, long b) { long ans = 1; for (long mul = a;b > 0;b >>= 1, mul *= mul) if ((b & 1) != 0) ans *= mul; return ans; } public static int pow(int a, int b, int mod) { if (b < 0) b = b % (mod - 1) + mod - 1; long ans = 1; for (long mul = a;b > 0;b >>= 1, mul = mul * mul % mod) if ((b & 1) != 0) ans = ans * mul % mod; return (int)ans; } public static int floorsqrt(long n) { return (int)Math.sqrt(n + 0.1); } public static int ceilsqrt(long n) { return n <= 1 ? (int)n : (int)Math.sqrt(n - 0.1) + 1; } } }