結果

問題 No.472 平均順位
ユーザー maesoramaesora
提出日時 2017-04-02 18:13:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 402 ms / 2,000 ms
コード長 2,147 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 84,660 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 07:41:44
合計ジャッジ時間 3,183 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 13 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 36 ms
4,376 KB
testcase_12 AC 26 ms
4,376 KB
testcase_13 AC 91 ms
4,376 KB
testcase_14 AC 334 ms
4,380 KB
testcase_15 AC 91 ms
4,380 KB
testcase_16 AC 378 ms
4,380 KB
testcase_17 AC 402 ms
4,380 KB
testcase_18 AC 25 ms
4,380 KB
testcase_19 AC 45 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0