Submission #1204037


Source Code Expand

import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	int f(int x) {
		x = Math.abs(x);
		return Math.max(x - 1, 0);
	}
	
	void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[2 * n - 1];
		for (int i = 0; i < 2 * n - 1; i++) {
			a[i] = nextInt();
		}
		Arrays.sort(a);
		int[][] dp = {{}, {1} };
		for (int i = 1; i < n; i++) {
			int addL = a[n - i] != a[n - 1 - i] ? 1 : 0;
			int addR = a[n - 1 + i] != a[n - 2 + i] ? 1 : 0;
			
			int[][] nxt = new int[2 * i + 2][2 * i + 2];
			for (int cnt = 1; cnt <= 2 * i - 1; cnt++) {
				for (int place = 0; place < cnt; place++) {
					
					int realCnt = cnt + addL + addR;
					int realPlace = place + addL;
					
					for (int toPlace = 0; toPlace < realCnt; toPlace++) {
						int newCnt = realCnt - f(toPlace - realPlace);
						int newPlace = toPlace <= realPlace ? toPlace : realPlace + 1;
						
						nxt[newCnt][newPlace] += dp[cnt][place];
						if (nxt[newCnt][newPlace] >= P) {
							nxt[newCnt][newPlace] -= P;
						}
					}
					
				}
			}
			dp = nxt;
		}
		
		long ret = 0;
		for (int[] row : dp) {
			for (int val : row) {
				ret += val;
			}
		}
		
		out.println(ret % P);
	}
	
	static final int P = 1_000_000_007;

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Submission Info

Submission Time
Task F - Prefix Median
User mmaxio
Language Java8 (OpenJDK 1.8.0)
Score 2000
Code Size 2220 Byte
Status AC
Exec Time 128 ms
Memory 23620 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2000 / 2000
Status
AC × 3
AC × 54
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 70 ms 19156 KB
00_example_02.txt AC 68 ms 21204 KB
00_example_03.txt AC 72 ms 21204 KB
01.txt AC 127 ms 22412 KB
02.txt AC 117 ms 22412 KB
03.txt AC 104 ms 21900 KB
04.txt AC 90 ms 21716 KB
05.txt AC 88 ms 20052 KB
06.txt AC 104 ms 22476 KB
07.txt AC 128 ms 22476 KB
08.txt AC 92 ms 19668 KB
09.txt AC 126 ms 22732 KB
10.txt AC 68 ms 21204 KB
11.txt AC 72 ms 21076 KB
12.txt AC 74 ms 21204 KB
13.txt AC 104 ms 22412 KB
14.txt AC 113 ms 19332 KB
15.txt AC 69 ms 18516 KB
16.txt AC 117 ms 19588 KB
17.txt AC 71 ms 19536 KB
18.txt AC 70 ms 20948 KB
19.txt AC 68 ms 18516 KB
20.txt AC 73 ms 17876 KB
21.txt AC 72 ms 17492 KB
22.txt AC 71 ms 20564 KB
23.txt AC 100 ms 23620 KB
24.txt AC 87 ms 22996 KB
25.txt AC 96 ms 20296 KB
26.txt AC 104 ms 21932 KB
27.txt AC 73 ms 19924 KB
28.txt AC 113 ms 22552 KB
29.txt AC 79 ms 19028 KB
30.txt AC 101 ms 20620 KB
31.txt AC 73 ms 18132 KB
32.txt AC 99 ms 22284 KB
33.txt AC 70 ms 20948 KB
34.txt AC 95 ms 17876 KB
35.txt AC 109 ms 20484 KB
36.txt AC 68 ms 18900 KB
37.txt AC 110 ms 22424 KB
38.txt AC 99 ms 21304 KB
39.txt AC 93 ms 19796 KB
40.txt AC 78 ms 20692 KB
41.txt AC 117 ms 20208 KB
42.txt AC 117 ms 22532 KB
43.txt AC 77 ms 19668 KB
44.txt AC 118 ms 18820 KB
45.txt AC 70 ms 21076 KB
46.txt AC 72 ms 20052 KB
47.txt AC 73 ms 21332 KB
48.txt AC 101 ms 22352 KB
49.txt AC 122 ms 22088 KB
50.txt AC 74 ms 19156 KB
51.txt AC 115 ms 22712 KB