Submission #1444885
Source Code Expand
import java.util.Scanner; import java.util.stream.IntStream; public class Main { static int[][] memo; static int[][] D; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); D = new int[N][N]; for (int i : IntStream.range(0, N).toArray()) { for (int j : IntStream.range(0, N).toArray()) { D[i][j] = scan.nextInt(); } } memo = new int[N][N]; for (int i : IntStream.range(0, N).toArray()) { for (int j : IntStream.range(0, N).toArray()) { int x = N - 1 - i; int y = N - 1 -j; if (x == N -1 && y == N - 1) { memo[x][y] = D[x][y]; } else if (x == N - 1) { memo[x][y] = memo[x][y + 1] + D[x][y]; } else if (y == N -1) { memo[x][y] = memo[x + 1][y] + D[x][y]; } else { memo[x][y] = memo[x][y + 1] + memo[x + 1][y] - memo[x + 1][y + 1] + D[x][y]; } } } int NN = N * N; int[] score = new int[NN+1]; for (int i : IntStream.range(1, NN).toArray()) { for (int j : IntStream.range(1, NN).toArray()) { int S = i * j; if (S > NN) { break; } score[S] = Math.max(score[S], max(i, j, N)); } } int tmpScore = 0; for (int i :IntStream.range(0, NN + 1).toArray()){ if (tmpScore > score[i]) { score[i] = tmpScore; } else { tmpScore = score[i]; } } int Q = scan.nextInt(); for (int i :IntStream.range(0, Q).toArray()){ int p = scan.nextInt(); System.out.println(score[p]); } } static int max(int x, int y, int N) { if (x > N || y > N) { return 0; } int max = 0; for (int i : IntStream.range(0, N - x + 1).toArray()) { for (int j : IntStream.range(0, N - y + 1).toArray()) { if (i + x == N && j + y == N) { max = Math.max(max, memo[i][j]); } else if (i + x == N) { max = Math.max(max, memo[i][j] - memo[i][j + y]); } else if(j + y == N) { max = Math.max(max, memo[i][j] - memo[i + x][j]); } else { max = Math.max(max, memo[i][j] - memo[i][j + y] - memo[i + x][j] + memo[i + x][ j +y]); } } } return max; } }
Submission Info
Submission Time | |
---|---|
Task | D - おいしいたこ焼きの焼き方 |
User | pytran |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 2789 Byte |
Status | WA |
Exec Time | 421 ms |
Memory | 45324 KB |
Judge Result
Set Name | Subtask1 | Subtask2 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 50 | 0 / 50 | ||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Subtask1 | sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt |
Subtask2 | rand0.txt, rand1.txt, rand2.txt, rand3.txt, rand4.txt, rand_max0.txt, rand_max1.txt, rand_max2.txt, rand_max3.txt, rand_max4.txt, s1.txt, s2.txt, sub0.txt, sub1.txt, sub2.txt, sub_rand_max0.txt, sub_rand_max1.txt, sub_rand_max2.txt, sub_rand_max3.txt, sub_rand_min0.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
rand0.txt | AC | 371 ms | 42848 KB |
rand1.txt | AC | 318 ms | 39372 KB |
rand2.txt | AC | 370 ms | 42664 KB |
rand3.txt | AC | 265 ms | 29684 KB |
rand4.txt | AC | 207 ms | 26560 KB |
rand_max0.txt | AC | 393 ms | 44380 KB |
rand_max1.txt | AC | 411 ms | 44624 KB |
rand_max2.txt | AC | 421 ms | 45324 KB |
rand_max3.txt | AC | 408 ms | 45284 KB |
rand_max4.txt | AC | 385 ms | 43432 KB |
s1.txt | AC | 164 ms | 24532 KB |
s2.txt | AC | 172 ms | 24780 KB |
sub0.txt | AC | 180 ms | 26836 KB |
sub1.txt | AC | 189 ms | 24656 KB |
sub2.txt | AC | 194 ms | 26444 KB |
sub_rand_max0.txt | AC | 169 ms | 24272 KB |
sub_rand_max1.txt | AC | 173 ms | 22992 KB |
sub_rand_max2.txt | AC | 178 ms | 26452 KB |
sub_rand_max3.txt | AC | 183 ms | 27092 KB |
sub_rand_min0.txt | WA | 173 ms | 26580 KB |