結果

問題 No.472 平均順位
ユーザー penguinshunyapenguinshunya
提出日時 2019-03-20 23:33:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 1,971 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 112,440 KB
実行使用メモリ 125,660 KB
最終ジャッジ日時 2023-10-19 04:38:14
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,420 KB
testcase_08 AC 6 ms
6,268 KB
testcase_09 AC 21 ms
13,144 KB
testcase_10 AC 30 ms
15,944 KB
testcase_11 AC 72 ms
32,220 KB
testcase_12 AC 66 ms
29,568 KB
testcase_13 AC 578 ms
125,660 KB
testcase_14 AC 291 ms
110,608 KB
testcase_15 AC 583 ms
125,660 KB
testcase_16 AC 112 ms
56,060 KB
testcase_17 AC 28 ms
24,424 KB
testcase_18 AC 9 ms
8,936 KB
testcase_19 AC 348 ms
77,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = long long;
using u32 = unsigned long long;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vstr = vector<string>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int n, p;
class Rank {
public:
  int a, b, c;
};
vector<Rank> abc;

i64 memo[5010][15010];

i64 rec(int i, int j) {
  if (memo[i][j]) return memo[i][j];
  if (j < 0 || j > (n - i) * 3) return 1e9;
  if (i == n - 1) {
    switch (j) {
      case 0: return abc[i].a;
      case 1: return abc[i].b;
      case 2: return abc[i].c;
      case 3: return 1;
    }
  }
  i64 ret = 1 + rec(i + 1, j - 3);
  amin(ret, abc[i].a + rec(i + 1, j));
  amin(ret, abc[i].b + rec(i + 1, j - 1));
  amin(ret, abc[i].c + rec(i + 1, j - 2));
  return memo[i][j] = ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cin >> n >> p;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c;
    abc.push_back({a, b, c});
  }
  cout << rec(0, p) / (f64) n << endl;
  return 0;
}
0