結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー | btk |
提出日時 | 2017-03-27 20:37:06 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 177 ms / 2,000 ms |
コード長 | 4,050 bytes |
コンパイル時間 | 1,931 ms |
コンパイル使用メモリ | 77,372 KB |
実行使用メモリ | 56,300 KB |
最終ジャッジ日時 | 2024-07-06 12:19:47 |
合計ジャッジ時間 | 5,847 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
54,800 KB |
testcase_01 | AC | 74 ms
54,428 KB |
testcase_02 | AC | 74 ms
54,908 KB |
testcase_03 | AC | 72 ms
54,272 KB |
testcase_04 | AC | 158 ms
55,848 KB |
testcase_05 | AC | 75 ms
54,388 KB |
testcase_06 | AC | 164 ms
56,228 KB |
testcase_07 | AC | 159 ms
55,940 KB |
testcase_08 | AC | 167 ms
56,072 KB |
testcase_09 | AC | 159 ms
55,928 KB |
testcase_10 | AC | 75 ms
54,452 KB |
testcase_11 | AC | 88 ms
56,104 KB |
testcase_12 | AC | 74 ms
54,056 KB |
testcase_13 | AC | 80 ms
54,404 KB |
testcase_14 | AC | 73 ms
54,196 KB |
testcase_15 | AC | 76 ms
54,952 KB |
testcase_16 | AC | 76 ms
54,776 KB |
testcase_17 | AC | 75 ms
54,728 KB |
testcase_18 | AC | 166 ms
56,096 KB |
testcase_19 | AC | 159 ms
56,012 KB |
testcase_20 | AC | 171 ms
56,048 KB |
testcase_21 | AC | 174 ms
56,300 KB |
testcase_22 | AC | 165 ms
56,008 KB |
testcase_23 | AC | 177 ms
56,028 KB |
testcase_24 | AC | 168 ms
56,092 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; if(Gr==0&&Gc==0)res++; 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());} }