結果
| 問題 |
No.498 ワープクリスタル (給料日編)
|
| コンテスト | |
| ユーザー |
btk
|
| 提出日時 | 2017-03-27 20:35:31 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 WA * 2 |
ソースコード
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());}
}
btk