結果

問題 No.472 平均順位
ユーザー kyawashellkyawashell
提出日時 2018-03-28 12:16:25
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 1,296 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 144,436 KB
実行使用メモリ 619,260 KB
最終ジャッジ日時 2023-09-07 19:22:03
合計ジャッジ時間 13,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,500 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 5 ms
16,452 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
7,928 KB
testcase_07 AC 5 ms
16,388 KB
testcase_08 AC 22 ms
54,760 KB
testcase_09 AC 77 ms
125,776 KB
testcase_10 AC 73 ms
153,216 KB
testcase_11 AC 231 ms
237,032 KB
testcase_12 AC 174 ms
221,020 KB
testcase_13 MLE -
testcase_14 TLE -
testcase_15 MLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 118 ms
152,080 KB
testcase_19 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
#define INF (1e9)

int N,P;
int a[4][5000];
bool done[5001][15001];
double memo[5001][15001];

double solve(int i,int j) {
	if(done[i][j]) {
		return memo[i][j];
	}
	if(i == N - 1) {
		double ret;
		if(j < 4) {
			ret = a[j][i];
		}
		else 
			ret = INF;
		done[i][j] = true;
		return memo[i][j] = ret;
	}

	double x = INF,y = INF,z = INF,w = INF;

	x = (solve(i + 1,j) * (N - i - 1) + a[0][i]) / (N - i);

	if(j > 0) {
		y = (solve(i + 1,j - 1) * (N - i - 1) + a[1][i]) / (N - i);
	} 
	if(j > 1) {
		z = (solve(i + 1,j - 2) * (N - i - 1) + a[2][i]) / (N - i);
	}
	if(j > 2) {
		w = (solve(i + 1,j - 3) * (N - i - 1) + a[3][i]) / (N - i);
	}
	done[i][j] = true;
	return memo[i][j] = min(min(x,y),min(z,w));
}


int main(){
	scanf("%d%d",&N,&P);
	REP(i,N) {
		scanf("%d%d%d",a[0]+i,a[1]+i,a[2]+i);
		a[3][i] = 1;
	}

	
	printf("%0.10f\n",solve(0,P));
	return 0;
}
0