結果

問題 No.472 平均順位
ユーザー Shivam062004Shivam062004
提出日時 2024-07-10 20:49:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 336 ms / 2,000 ms
コード長 4,001 bytes
コンパイル時間 3,090 ms
コンパイル使用メモリ 196,056 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-10 20:49:29
合計ジャッジ時間 5,735 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 28 ms
5,376 KB
testcase_12 AC 21 ms
5,376 KB
testcase_13 AC 77 ms
5,376 KB
testcase_14 AC 261 ms
5,376 KB
testcase_15 AC 76 ms
5,376 KB
testcase_16 AC 299 ms
5,376 KB
testcase_17 AC 336 ms
5,376 KB
testcase_18 AC 21 ms
5,376 KB
testcase_19 AC 37 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
//find by order-> element at ith idx(starting from 0)//gives iterator to that index//if not present *it gives 0
//order of key-> number of element less than a number
#define int long long int 
// #define ll long long int
#define loop(s, e) for(int i = s; i < e; i++)
#define rloop(e, s) for(int i = e; i>= s; i--)
#define v vector<int>
// #define vll vector<long long int>
#define printyes cout<<"YES\n"
#define printno cout<<"NO\n"
//COMMENT THIS FOR INTERACTIVE PROBLEMS...............
#define endl '\n'
#define mod 1000000007
#define pinf 1e18
#define ninf -1e18
#define printvec(arr) cout<<#arr<<"=> [ ";for(int i = 0; i < arr.size(); i++){cout<<arr[i]<<" ";}cout<<"]"<<endl;
#define dbg(x) cout<<"value of "<<#x<<" is => "<<x<<endl;
#define all(x) x.begin(), x.end()
#define vpii vector<pair<int, int>>
#define pii pair<int,int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define vpll vector<pll>
#define here(i) cout<<"here "<<i<<" "<<endl;
#define rt return;
#define mx max_element
#define mn min_element
#define asum accumulate
int delrow[4] = {-1,0,1,0};
int delcol[4] = {0,1,0,-1};

void printv(v& ans) {
    for(auto it: ans)cout<<it<<" ";
    cout<<endl;
}

int setBit(int n, int bitNo) {
  n = (n|(1LL<<bitNo));
  return n;
}

int currBit(int n, int bitNo) {
  return ((n&(1ll<<bitNo)) == 0)?0:1;
}

int unSetBit(int n, int bitNo) {
  n = (n&(~(1ll<<bitNo)));
  return n;
}
//*************************************************CHECK THE CONSTRAINTS**********************************************************//
int f(int a, int b) {
  if(b == 0)return 1;
  int res = f(a, b/2);
  if(b%2 != 0) {
    return (((res)%mod * (res)%mod)%mod * a)%mod;
  }
  else {
    return ((res)%mod * (res)%mod)%mod;
  }
}

vector<bool> sieve(int n) {
  vector<bool> prime(n+1, 1);
  prime[0] = 0;
  prime[1] = 0;
  for(int i = 2; i*i <= n; i++) {
    if(prime[i] == 1) {
      for(int j = i*i; j <= n; j+=i) {
        prime[j] = 0;
      }
    }
  }
  return prime;
}



void pikachu(int tt, int tc) {
  int n, p;
  cin>>n>>p;
  vector<vector<int>> c(n, vector<int>(3, 0));
  loop(0, n) {
    cin>>c[i][0]>>c[i][1]>>c[i][2];
  }
  vector<vector<int>> dp(2, vector<int>(p+1, INT_MAX));
  
  dp[0][0] = c[0][0];
  if(p >= 1)dp[0][1] = c[0][1];
  if(p >= 2)dp[0][2] = c[0][2];
  if(p >= 3)dp[0][3] = 1;
  for(int i = 1; i < n; i++) {
    for(int ques = 0; ques <= p; ques++) {
      if(ques-3 >= 0 && dp[0][ques-3] != INT_MAX) dp[1][ques] = min(dp[0][ques-3] + 1, dp[1][ques]);
      if(ques-2 >= 0 && dp[0][ques-2] != INT_MAX) dp[1][ques] = min(dp[0][ques-2] + c[i][2], dp[1][ques]);
      if(ques-1 >= 0 && dp[0][ques-1] != INT_MAX) dp[1][ques] = min(dp[0][ques-1] + c[i][1], dp[1][ques]);
      if(dp[0][ques] != INT_MAX) dp[1][ques] = min(dp[0][ques] + c[i][0], dp[1][ques]);
    }
    dp[0] = dp[1];
    for(int i = 0; i < p+1; i++)dp[1][i] = INT_MAX;
  }
//   dbg(dp[0][p])
  double ans = (double)(dp[0][p])/n;
  cout<<ans<<endl;
}


int32_t main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  int gsBall = 1;
  // cin>>gsBall;
  int tt = gsBall;
  int tc = 1;
  while(gsBall--) {
    pikachu(tt, tc);
    tc++;
  }
  return 0;
}
0