結果
| 問題 |
No.472 平均順位
|
| コンテスト | |
| ユーザー |
maesora
|
| 提出日時 | 2017-04-02 18:13:08 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 430 ms / 2,000 ms |
| コード長 | 2,147 bytes |
| コンパイル時間 | 781 ms |
| コンパイル使用メモリ | 87,948 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 00:11:29 |
| 合計ジャッジ時間 | 3,355 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <cstdio>
#include <utility>
#include <cmath>
#include <cstring>
// #include <ctime>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>
#define REP(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;
const int MAX_N = 5000;
double solve(int N, int P, int *A, int *B, int *C) {
// dp(i, q): i回目まででq問ちょうど解いた場合の最小合計順位(i: 0~N-1)
// return: (double)dp(N-1, P) / N
// i問目を解いた数は0, 1, 2, 3問のどれかなので、
// dp(i, q) = min(
// dp(i-1, q) + A[i],
// dp(i-1, q-1) + B[i],
// dp(i-1, q-2) + C[i],
// dp(i-1, q-3) + 1
// )
int p = max(3, P);
int tr[p + 1], prev_tr[p + 1];
REP(i, p + 1) {
tr[i] = 0;
prev_tr[i] = 0;
}
tr[0] = A[0];
tr[1] = B[0];
tr[2] = C[0];
tr[3] = 1;
// // dbg
// cerr << "|j\t";
// REP(i, p + 1) {
// cerr << i << "\t";
// }
// cerr << "\n--------\n";
// cerr << 0 << "\t";
// REP(j, p + 1) {
// cerr << tr[j] << "\t";
// }
// cerr << "\n";
for(int i = 1;i < N;i++) {
// swap
REP(j, p + 1) {
swap(tr[j], prev_tr[j]);
}
// // dbg
// cerr << " p\t";
// REP(j, p + 1) {
// cerr << prev_tr[j] << "\t";
// }
// cerr << "\n";
for(int j = 0;j <= P;j++) {
tr[j] = prev_tr[j] + A[i];
if (j >= 1 && prev_tr[j-1] >= 0) {
tr[j] = min(tr[j], prev_tr[j-1] + B[i]);
}
if (j >= 2 && prev_tr[j-2] >= 0) {
tr[j] = min(tr[j], prev_tr[j-2] + C[i]);
}
if (j >= 3 && prev_tr[j-3] >= 0) {
tr[j] = min(tr[j], prev_tr[j-3] + 1);
}
}
// // dbg
// cerr << i << "\t";
// REP(j, p + 1) {
// cerr << tr[j] << "\t";
// }
// cerr << "\n";
}
return (double)tr[P] / N;
}
int main(void)
{
cin.tie(0);
ios::sync_with_stdio(false);
int N, P;
cin >> N >> P;
int A[N], B[N], C[N];
REP(i, N) cin >> A[i] >> B[i] >> C[i];
cout << solve(N, P, A, B, C) << "\n";
return 0;
}
maesora