Submission #1304097


Source Code Expand

import java.util.*;

public class Main {
 
	private static long[] dp;
	private static int[][] pos;
	private static int W;
	private static int H;
	private static Map<String, Integer> comp = new HashMap<>();
	private static int cmpIdx = 0;
 
	private static long dfs(int w1, int h1, int w2, int h2) {
		if (w1 > w2 || h1 > h2 || w1 < 0 || w2 >= W || h1 < 0 || h2 >= H) {
			return 0;
		}
		
		int q = h(w1, h1, w2, h2);
		if (dp[q] > 0) {
			return dp[q];
		}
 
		long v = (w2 - w1 + 1) + (h2 - h1 + 1) - 1;
	
		long ret = 0;
		for (int[] p : pos) {
			if (w1 <= p[0] && p[0] <= w2 && h1 <= p[1] && p[1] <= h2) {
				long now = v;
				now += dfs(p[0] + 1, p[1] + 1, w2, h2);
				now += dfs(p[0] + 1, h1, w2, p[1] - 1);
				now += dfs(w1, p[1] + 1, p[0] - 1, h2);
				now += dfs(w1, h1, p[0] - 1, p[1] - 1);
				
				ret = Math.max(now, ret);
			}
		}
		dp[q] = ret;
		//System.out.printf("w1:%d, h1:%d, w2:%d, h2:%d, x=%d\n", w1, h1, w2, h2, ret);
		return ret;
	}
 
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		W = sc.nextInt();
		H = sc.nextInt();
		int N = sc.nextInt();
 
		pos = new int[N][2];
 
		for (int i = 0; i < N; i ++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;
			pos[i][0] = x;
			pos[i][1] = y;
		}
		
		dp = new long[100000];
		long ret = dfs(0, 0, W - 1, H - 1);
		System.out.println(ret);
	}
 
	private static int h(int w1, int h1, int w2, int h2) {
		String s = String.format("%d,%d,%d,%d", w1, h1, w2, h2);
		if (!comp.containsKey(s)) {
			comp.put(s, cmpIdx ++);
		}
		return comp.get(s);
	}
}

Submission Info

Submission Time
Task D - 金塊ゲーム
User suesue
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1641 Byte
Status CE

Compile Error

./Main.java:4: error: illegal character: '\u00a0'
 
^
./Main.java:11: error: illegal character: '\u00a0'
 
^
./Main.java:21: error: illegal character: '\u00a0'
 
^
./Main.java:40: error: illegal character: '\u00a0'
 
^
./Main.java:46: error: illegal character: '\u00a0'
 
^
./Main.java:48: error: illegal character: '\u00a0'
 
^
./Main.java:60: error: illegal character: '\u00a0'
 
^
7 errors