結果
問題 | No.335 門松宝くじ |
ユーザー | Grenache |
提出日時 | 2016-07-28 21:21:23 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,607 bytes |
コンパイル時間 | 5,228 ms |
コンパイル使用メモリ | 79,300 KB |
実行使用メモリ | 57,676 KB |
最終ジャッジ日時 | 2024-04-24 10:36:47 |
合計ジャッジ時間 | 7,431 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
37,468 KB |
testcase_01 | AC | 59 ms
37,580 KB |
testcase_02 | AC | 57 ms
37,680 KB |
testcase_03 | AC | 54 ms
37,740 KB |
testcase_04 | WA | - |
testcase_05 | AC | 120 ms
44,212 KB |
testcase_06 | AC | 158 ms
46,220 KB |
testcase_07 | AC | 206 ms
55,580 KB |
testcase_08 | AC | 166 ms
54,124 KB |
testcase_09 | AC | 236 ms
57,240 KB |
testcase_10 | AC | 290 ms
57,676 KB |
testcase_11 | AC | 354 ms
56,780 KB |
testcase_12 | AC | 260 ms
56,168 KB |
testcase_13 | AC | 237 ms
57,452 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder335 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int m = sc.nextInt(); int maxe = 0; int maxei = 0; for (int mm = 0; mm < m; mm++) { int[] e = new int[n]; for (int i = 0; i < n; i++) { e[i] = sc.nextInt(); } int[][] max = new int[n][n]; for (int i = 0; i < n; i++) { max[i][i] = e[i]; for (int j = i + 1; j < n; j++) { max[i][j] = Math.max(max[i][j - 1], e[j]); } } int[][] maxi = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (e[j] < e[i]) { maxi[i][j] = Math.max(maxi[i][j - 1], e[j]); } } } int[][] maxj = new int[n][n]; for (int i = n - 1; i >= 0; i--) { for (int j = i - 1; j >= 0; j--) { if (e[j] < e[i]) { maxj[i][j] = Math.max(maxj[i][j + 1], e[j]); } } } int sum = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int tmp = 0; if (e[j] > e[i]) { if (i > 0 && max[0][i - 1] > e[i]) { tmp = Math.max(tmp, max[0][i - 1]); } if (j > i + 1 && max[i + 1][j - 1] > e[j]) { tmp = Math.max(tmp, max[i + 1][j - 1]); } if (j > i + 1) { tmp = Math.max(tmp, maxi[i][j]); } if (j < n - 1) { tmp = Math.max(tmp, maxi[j][n - 1]); } } else { if (i > 0) { tmp = Math.max(tmp, maxj[0][i]); } if (j > i + 1 && max[i + 1][j - 1] > e[i]) { tmp = Math.max(tmp, max[i + 1][j - 1]); } if (j > i + 1) { tmp = Math.max(tmp, maxj[i][j]); } if (j < n - 1 && max[j + 1][n - 1] > e[j]) { tmp = Math.max(tmp, max[j + 1][n - 1]); } } if (tmp > 0) { sum += e[i] + e[j] + tmp; } } } if (sum > maxe) { maxe = sum; maxei = mm; } } pr.println(maxei); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }