結果

問題 No.472 平均順位
ユーザー maesoramaesora
提出日時 2017-04-02 16:23:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,810 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 84,960 KB
実行使用メモリ 15,444 KB
最終ジャッジ日時 2023-09-22 07:40:24
合計ジャッジ時間 6,055 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 17 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 66 ms
4,376 KB
testcase_08 AC 1,091 ms
5,208 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

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