結果

問題 No.472 平均順位
ユーザー maesoramaesora
提出日時 2017-04-02 16:26:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,891 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 84,344 KB
実行使用メモリ 296,600 KB
最終ジャッジ日時 2023-09-22 07:40:31
合計ジャッジ時間 2,764 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
5,148 KB
testcase_09 AC 11 ms
11,500 KB
testcase_10 AC 9 ms
8,372 KB
testcase_11 AC 29 ms
28,264 KB
testcase_12 AC 21 ms
21,060 KB
testcase_13 AC 70 ms
68,852 KB
testcase_14 AC 262 ms
244,028 KB
testcase_15 AC 71 ms
68,852 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 20 ms
20,776 KB
testcase_19 AC 36 ms
34,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#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;

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 dp[N][p + 1];
  REP(i, N) REP(j, p + 1) dp[i][j] = 0;

  dp[0][0] = A[0];
  dp[0][1] = B[0];
  dp[0][2] = C[0];
  dp[0][3] = 1;

  // // dbg
  // cerr << "\t";
  // REP(i, p + 1) {
  //   cerr << i << "\t";
  // }
  // cerr << "\n--------\n";
  // cerr << 0 << "\t";
  // REP(j, p + 1) {
  //   cerr << dp[0][j] << "\t";
  // }
  // cerr << "\n";

  for(int i = 1;i < N;i++) {
    for(int j = 0;j <= P;j++) {
      dp[i][j] = dp[i-1][j] + A[i];
      if (j >= 1 && dp[i-1][j-1] > 0){
	dp[i][j] = min(dp[i][j], dp[i-1][j-1] + B[i]);
      }
      if (j >= 2 && dp[i-1][j-2] > 0){
	dp[i][j] = min(dp[i][j], dp[i-1][j-2] + C[i]);
      }
      if (j >= 3 && dp[i-1][j-3] > 0){
	dp[i][j] = min(dp[i][j], dp[i-1][j-3] + 1);
      }
    }

    // // dbg
    // cerr << i << "\t";
    // REP(j, p + 1) {
    //   cerr << dp[i][j] << "\t";
    // }
    // cerr << "\n";
  }

  return (double)dp[N-1][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;
}
0