結果
| 問題 |
No.472 平均順位
|
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2016-12-21 12:40:31 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 881 ms / 2,000 ms |
| コード長 | 3,952 bytes |
| コンパイル時間 | 2,250 ms |
| コンパイル使用メモリ | 81,964 KB |
| 実行使用メモリ | 54,156 KB |
| 最終ジャッジ日時 | 2024-12-17 14:02:53 |
| 合計ジャッジ時間 | 8,780 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
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) {}}
}
ぴろず