結果
問題 | No.472 平均順位 |
ユーザー | ぴろず |
提出日時 | 2016-12-21 12:40:31 |
言語 | Java19 (openjdk 21) |
結果 |
AC
|
実行時間 | 994 ms / 2,000 ms |
コード長 | 3,952 bytes |
コンパイル時間 | 3,277 ms |
コンパイル使用メモリ | 75,304 KB |
実行使用メモリ | 56,332 KB |
最終ジャッジ日時 | 2023-08-22 14:51:36 |
合計ジャッジ時間 | 10,821 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 113 ms
56,056 KB |
testcase_01 | AC | 114 ms
56,216 KB |
testcase_02 | AC | 112 ms
55,988 KB |
testcase_03 | AC | 113 ms
56,332 KB |
testcase_04 | AC | 115 ms
55,444 KB |
testcase_05 | AC | 113 ms
56,176 KB |
testcase_06 | AC | 116 ms
55,848 KB |
testcase_07 | AC | 124 ms
55,652 KB |
testcase_08 | AC | 145 ms
55,484 KB |
testcase_09 | AC | 167 ms
55,540 KB |
testcase_10 | AC | 159 ms
55,840 KB |
testcase_11 | AC | 240 ms
55,704 KB |
testcase_12 | AC | 209 ms
55,656 KB |
testcase_13 | AC | 406 ms
55,912 KB |
testcase_14 | AC | 994 ms
55,712 KB |
testcase_15 | AC | 402 ms
56,052 KB |
testcase_16 | AC | 929 ms
55,940 KB |
testcase_17 | AC | 993 ms
55,572 KB |
testcase_18 | AC | 197 ms
55,620 KB |
testcase_19 | AC | 281 ms
56,176 KB |
ソースコード
package no472; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; import java.util.NoSuchElementException; public class Main { public static int INF = (int) 1e9; public static void main(String[] args) { ValidatingScanner sc = new ValidatingScanner(true); int n = sc.readInt(1, 5000); sc.readSpace(); int p = sc.readInt(0, 3*n); sc.readEoln(); int[][] rank = new int[n][4]; for(int i=0;i<n;i++) { int a = sc.readInt(2, 100000); sc.readSpace(); int b = sc.readInt(2, a-1); sc.readSpace(); int c = sc.readInt(2, b-1); sc.readEoln(); rank[i][0] = a; rank[i][1] = b; rank[i][2] = c; rank[i][3] = 1; } sc.readEof(); int[] dp = new int[p+1]; Arrays.fill(dp, INF); dp[0] = 0; for(int i=0;i<n;i++) { for(int j=p;j>=0;j--) { int next = INF; for(int k=0;k<=3;k++) { if (j - k < 0) { break; } next = Math.min(next, dp[j-k] + rank[i][k]); } dp[j] = next; } // System.out.println(Arrays.toString(dp)); } System.out.println(String.format("%.6f", (double) dp[p] / n)); } } class ValidatingScanner { boolean strictEoln = false; public static final String EOLN = "\n"; private final InputStream in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; public ValidatingScanner(boolean strictEoln) { this(System.in, strictEoln); } public ValidatingScanner(InputStream source, boolean strictEoln) { this.in = source; this.strictEoln = strictEoln; } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } public boolean eof() { return !hasNextByte(); } private int getByte() { if (hasNextByte()) { return buffer[ptr]; }else{ return -1; } } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; }else{ return -1; } } private void advance() { if (hasNextByte()) { ptr++; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public long readLong() { if (eof()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = getByte(); if (b == '-') { advance(); minus = true; b = getByte(); } if (b < '0' || '9' < b) { throw new InputMismatchException(); } while(true){ if ('0' <= b && b <= '9') { try { n = Math.multiplyExact(n, 10); } catch (ArithmeticException e) { throw new InputMismatchException(); } n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new InputMismatchException(); } advance(); b = getByte(); } } public int readInt() { long nl = readLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new InputMismatchException(); } return (int) nl; } public int readInt(int min,int max) { if (min > max) throw new IllegalArgumentException(); int n = readInt(); if (n < min || n > max) throw new InputMismatchException(); return n; } public void readSpace() { int b = readByte(); if (b != ' ') throw new InputMismatchException(); } public void readEoln() { if (strictEoln) { for(int i=0;i<EOLN.length();i++) { int b = readByte(); if (b == -1 || b != EOLN.charAt(i)) { throw new InputMismatchException(); } } }else{ int b1 = getByte(); if (b1 != '\r' && b1 != '\n') { throw new InputMismatchException(); } advance(); int b2 = getByte(); if ((b1 == '\r' || b1 == '\n') && b1 != b2) { advance(); } } } public void readEof() { if (!eof()) { throw new InputMismatchException(); } } public void close() {try {in.close();} catch (IOException e) {}} }