結果
問題 | No.1460 Max of Min |
ユーザー | cyclerecycle9 |
提出日時 | 2022-05-04 02:57:51 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 950 ms / 2,000 ms |
コード長 | 5,104 bytes |
コンパイル時間 | 2,550 ms |
コンパイル使用メモリ | 79,180 KB |
実行使用メモリ | 470,644 KB |
最終ジャッジ日時 | 2024-07-03 03:06:16 |
合計ジャッジ時間 | 34,683 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
36,808 KB |
testcase_01 | AC | 51 ms
36,924 KB |
testcase_02 | AC | 52 ms
36,724 KB |
testcase_03 | AC | 950 ms
466,272 KB |
testcase_04 | AC | 924 ms
460,900 KB |
testcase_05 | AC | 53 ms
36,664 KB |
testcase_06 | AC | 933 ms
458,752 KB |
testcase_07 | AC | 934 ms
460,908 KB |
testcase_08 | AC | 53 ms
36,552 KB |
testcase_09 | AC | 52 ms
36,908 KB |
testcase_10 | AC | 841 ms
465,276 KB |
testcase_11 | AC | 823 ms
460,532 KB |
testcase_12 | AC | 252 ms
76,532 KB |
testcase_13 | AC | 484 ms
228,988 KB |
testcase_14 | AC | 303 ms
102,636 KB |
testcase_15 | AC | 184 ms
65,772 KB |
testcase_16 | AC | 415 ms
181,424 KB |
testcase_17 | AC | 291 ms
102,580 KB |
testcase_18 | AC | 96 ms
40,376 KB |
testcase_19 | AC | 331 ms
122,756 KB |
testcase_20 | AC | 104 ms
41,420 KB |
testcase_21 | AC | 139 ms
50,004 KB |
testcase_22 | AC | 356 ms
122,952 KB |
testcase_23 | AC | 90 ms
39,768 KB |
testcase_24 | AC | 283 ms
122,224 KB |
testcase_25 | AC | 86 ms
39,056 KB |
testcase_26 | AC | 489 ms
226,856 KB |
testcase_27 | AC | 169 ms
65,904 KB |
testcase_28 | AC | 131 ms
50,444 KB |
testcase_29 | AC | 328 ms
122,920 KB |
testcase_30 | AC | 389 ms
180,960 KB |
testcase_31 | AC | 326 ms
122,884 KB |
testcase_32 | AC | 219 ms
66,612 KB |
testcase_33 | AC | 71 ms
38,232 KB |
testcase_34 | AC | 212 ms
52,484 KB |
testcase_35 | AC | 112 ms
41,724 KB |
testcase_36 | AC | 53 ms
36,676 KB |
testcase_37 | AC | 145 ms
50,668 KB |
testcase_38 | AC | 92 ms
39,916 KB |
testcase_39 | AC | 207 ms
52,216 KB |
testcase_40 | AC | 129 ms
45,988 KB |
testcase_41 | AC | 131 ms
46,236 KB |
testcase_42 | AC | 100 ms
40,300 KB |
testcase_43 | AC | 279 ms
76,700 KB |
testcase_44 | AC | 287 ms
102,468 KB |
testcase_45 | AC | 89 ms
39,272 KB |
testcase_46 | AC | 203 ms
67,048 KB |
testcase_47 | AC | 252 ms
67,760 KB |
testcase_48 | AC | 342 ms
123,412 KB |
testcase_49 | AC | 198 ms
85,676 KB |
testcase_50 | AC | 95 ms
39,916 KB |
testcase_51 | AC | 260 ms
76,916 KB |
testcase_52 | AC | 136 ms
50,424 KB |
testcase_53 | AC | 135 ms
46,096 KB |
testcase_54 | AC | 147 ms
50,888 KB |
testcase_55 | AC | 260 ms
120,832 KB |
testcase_56 | AC | 110 ms
45,656 KB |
testcase_57 | AC | 290 ms
103,364 KB |
testcase_58 | AC | 934 ms
465,984 KB |
testcase_59 | AC | 207 ms
78,372 KB |
testcase_60 | AC | 213 ms
100,812 KB |
testcase_61 | AC | 161 ms
50,488 KB |
testcase_62 | AC | 162 ms
50,496 KB |
testcase_63 | AC | 59 ms
36,700 KB |
testcase_64 | AC | 58 ms
36,592 KB |
testcase_65 | AC | 337 ms
123,828 KB |
testcase_66 | AC | 166 ms
50,600 KB |
testcase_67 | AC | 63 ms
37,348 KB |
testcase_68 | AC | 294 ms
102,328 KB |
testcase_69 | AC | 286 ms
77,012 KB |
testcase_70 | AC | 257 ms
67,688 KB |
testcase_71 | AC | 342 ms
123,872 KB |
testcase_72 | AC | 134 ms
50,296 KB |
testcase_73 | AC | 143 ms
50,636 KB |
testcase_74 | AC | 118 ms
50,252 KB |
testcase_75 | AC | 115 ms
45,808 KB |
testcase_76 | AC | 110 ms
45,792 KB |
testcase_77 | AC | 117 ms
45,972 KB |
testcase_78 | AC | 69 ms
37,832 KB |
testcase_79 | AC | 126 ms
45,868 KB |
testcase_80 | AC | 110 ms
41,288 KB |
testcase_81 | AC | 69 ms
37,804 KB |
testcase_82 | AC | 112 ms
45,980 KB |
testcase_83 | AC | 90 ms
39,500 KB |
testcase_84 | AC | 851 ms
470,644 KB |
testcase_85 | AC | 844 ms
466,212 KB |
testcase_86 | AC | 810 ms
465,688 KB |
testcase_87 | AC | 845 ms
461,816 KB |
testcase_88 | AC | 828 ms
459,852 KB |
testcase_89 | AC | 853 ms
459,760 KB |
testcase_90 | AC | 839 ms
464,312 KB |
testcase_91 | AC | 856 ms
458,984 KB |
testcase_92 | AC | 843 ms
466,052 KB |
testcase_93 | AC | 828 ms
463,460 KB |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; public class Main { static final long MOD=1000000007; static final long MOD1=998244353; static int size = 0; static long MAX = 1000000000000000000l; public static void main(String[] args){ PrintWriter out = new PrintWriter(System.out); InputReader sc=new InputReader(System.in); int k = sc.nextInt(); long n = sc.nextLong(); long[] init = sc.nextLongArray(k); long[] a = sc.nextLongArray(k); kitamasa KITA = new kitamasa(k, a); System.out.println(KITA.calc(init, n)); } //きたまさ法, k項間線形漸化式の第n項をO(k^2logn)で求める //注) aもinitも小さい順に入れていく、a_k = c_k-1*a_k-1 + .... + c_0*a_0 なら添え字の通りにいれる //0index-dで0~k-1項を初項として計算する //コンストラクタに漸化式の係数を与えて初期化。calcで初項を与えて計算する。 static class kitamasa{ int k; long[] a; public kitamasa(int k, long[] a) { this.k = k; this.a = new long[k]; for (int i = 0; i < a.length; i++) { this.a[i] = a[i]; } } long[] dfs(long n){ if(n == k) return a; long[] res = new long[k]; Arrays.fill(res, Long.MIN_VALUE); if((n & 1) == 1 || n < k * 2){ long[] x = dfs(n - 1); oneplus(res, x); } else{ long[][] x = new long[k][k]; for (int i = 0; i < x.length; i++) { Arrays.fill(x[i], Long.MIN_VALUE); } x[0] = dfs(n >> 1); for(int i = 0; i + 1 < k; i++){ oneplus(x[i+1], x[i]); } for(int i = 0; i < k; i++){ for(int j = 0; j < k; j++){ res[j] = Math.max(res[j], Math.min(x[0][i] , x[i][j])); } } } return res; } void oneplus(long[] res, long[] x) { for(int i = 0; i < k; i++) res[i] = Math.min(a[i] , x[k - 1]); for(int i = 0; i + 1 < k; i++) res[i + 1] = Math.max(res[i + 1] , x[i]); } long calc(long[] init, long n) { if(n<k) return init[(int)n]; long[] x = dfs(n);//a_nの係数 long res = Long.MIN_VALUE; for (int i = 0; i < k; i++) { res = Math.max(res, Math.min(init[i] , x[i])); } return res; } } static class InputReader { private InputStream in; private byte[] buffer = new byte[1024]; private int curbuf; private int lenbuf; public InputReader(InputStream in) { this.in = in; this.curbuf = this.lenbuf = 0; } public boolean hasNextByte() { if (curbuf >= lenbuf) { curbuf = 0; try { lenbuf = in.read(buffer); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return false; } return true; } private int readByte() { if (hasNextByte()) return buffer[curbuf++]; else return -1; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private void skip() { while (hasNextByte() && isSpaceChar(buffer[curbuf])) curbuf++; } public boolean hasNext() { skip(); return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); int c = readByte(); while (isSpaceChar(c)) c = readByte(); boolean minus = false; if (c == '-') { minus = true; c = readByte(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res = res * 10 + c - '0'; c = readByte(); } while (!isSpaceChar(c)); return (minus) ? -res : res; } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public double[] nextDoubleArray(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextDouble(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public char[][] nextCharMap(int n, int m) { char[][] map = new char[n][m]; for (int i = 0; i < n; i++) map[i] = next().toCharArray(); return map; } } }