結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー | btk |
提出日時 | 2017-03-27 20:35:31 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,019 bytes |
コンパイル時間 | 1,993 ms |
コンパイル使用メモリ | 77,424 KB |
実行使用メモリ | 67,560 KB |
最終ジャッジ日時 | 2024-07-06 12:18:48 |
合計ジャッジ時間 | 6,034 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 86 ms
66,004 KB |
testcase_01 | AC | 81 ms
65,496 KB |
testcase_02 | AC | 80 ms
65,500 KB |
testcase_03 | AC | 77 ms
65,692 KB |
testcase_04 | AC | 180 ms
67,276 KB |
testcase_05 | AC | 77 ms
65,004 KB |
testcase_06 | AC | 192 ms
67,080 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 175 ms
67,348 KB |
testcase_10 | AC | 78 ms
65,048 KB |
testcase_11 | AC | 108 ms
67,076 KB |
testcase_12 | AC | 77 ms
65,440 KB |
testcase_13 | AC | 81 ms
65,768 KB |
testcase_14 | AC | 79 ms
65,920 KB |
testcase_15 | AC | 77 ms
65,560 KB |
testcase_16 | AC | 66 ms
65,624 KB |
testcase_17 | AC | 79 ms
65,796 KB |
testcase_18 | AC | 181 ms
67,156 KB |
testcase_19 | AC | 179 ms
66,788 KB |
testcase_20 | AC | 188 ms
67,308 KB |
testcase_21 | AC | 188 ms
67,200 KB |
testcase_22 | AC | 183 ms
67,152 KB |
testcase_23 | AC | 177 ms
67,248 KB |
testcase_24 | AC | 202 ms
67,560 KB |
ソースコード
import java.io.*; import java.util.*; /** * Created by btk on 2017/03/16. */ public class Main { static FastScanner in; static PrintWriter out; static int Gr,Gc; static int K; static int[] R,C,N; static void init(){ Gr = in.nextInt(); Gc = in.nextInt(); K = in.nextInt(); R = new int[5]; C = new int[5]; N = new int[5]; for (int i = 0; i < 5; i++) { N[i] = 0; } for (int i = 0; i < K; i++) { R[i] = in.nextInt(); C[i] = in.nextInt(); N[i] = in.nextInt(); } } final static int mod = (int)1e9+7; final static int M = 1 << 20; static long[] dp; static int[] r,c; static long res = 0; static int pos(int[] num) { int ret=0; for (int i = 4; i >=0; i--) { ret<<=4; ret+=num[i]; } return ret; } static void rec(int now){ if(dp[now]!=-1)return; //out.println(now); int lb = 1; int mask = 15; dp[now] = 0; for (int i = 0; i < 5; i++,mask<<=4,lb<<=4) { if((now&mask)>0) { int nxt = now -lb; rec(nxt); r[now] = r[nxt] + R[i]; c[now] = c[nxt] + C[i]; dp[now] += dp[nxt]; } } dp[now] %= mod; if(r[now] == Gr &&c[now]==Gc) res+=dp[now]; } static void solve(){ dp = new long[M]; r = new int[M]; c = new int[M]; for (int i = 0; i < M; i++) { dp[i] = -1 ; } dp[0] = 1; r[0] = 0; c[0] = 0; rec(pos(N)); out.println(res%mod); } public static void main(String[] args){ in = new FastScanner(); out = new PrintWriter(System.out); init(); solve(); out.close(); } } class FastScanner { private final 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; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }