提出 #58238890


ソースコード 拡げる

//yukicoder@cpp17

#include <iostream>
#include <iomanip>

#include <algorithm>

#include <cmath>
#include <cctype>
#include <climits>
#include <cassert>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

#include <random>

#include <bitset>

#include <complex>

#include <utility>

#include <numeric>

#include <functional>


using namespace std;
using ll = long long;
using P = pair<ll,ll>;


const ll MOD = 998244353;
const ll MODx = 1000000007;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62LL)-1;
const double EPS = (1e-10);


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }
 
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/

/* comment outed because can cause bugs
__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
*/


struct d{
  long long val;
  long long sig;
  long long cur;
  long long f()const{
    return val + cur * (sig - cur);
  }
  bool operator>(const d &a)const{
    if(f() == a.f()){
      return cur < a.cur;
    }else{
      return f() > a.f();
    }
  }
  bool operator==(const d &a)const{
    return cur == a.cur && val == a.val;
  }
  bool operator<(const d &a)const{
    return !((*this)>a || (*this)==a);
  }
};


d dp[3010][3010];

int main(){
  long long n,w;cin>>n>>w;
  vector<pair<long long, long long>> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i].first>>A[i].second;
  }
  for(int i = 0; n > i; i++){
    for(int j = 0; w >= j; j++){
      if(j >= A[i].first){
         dp[i][j] = max((d){dp[i][j-A[i].first].val, A[i].second, dp[i][j-A[i].first].cur+1}, dp[i][j]);
      }
      if(i){
        d nex = {dp[i-1][j].f(), 0, 0};
        dp[i][j] = max(nex, dp[i][j]);
      }

      if(i && j >= A[i].first){
        d nex = {dp[i-1][j-A[i].first].f(), A[i].second, 1};
        dp[i][j] = max(nex, dp[i][j]);
      }
    }
  }
  //for(int i = 0; n > i; i++){
  //  for(int j = 0; w >= j; j++){
  //    cout << "(" << dp[i][j].val << ", " << dp[i][j].sig << ", " << dp[i][j].cur << ") ";
  //  }
  //  cout << endl;
  //}
  cout << dp[n-1][w].f() << endl;
  return 0;
}

提出情報

提出日時
問題 F - Knapsack with Diminishing Values
ユーザ CleyL
言語 C++ 20 (gcc 12.2)
得点 0
コード長 2815 Byte
結果 WA
実行時間 235 ms
メモリ 215356 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 550
結果
AC × 3
AC × 28
WA × 30
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 2 ms 3536 KiB
00_sample_02.txt AC 1 ms 3540 KiB
00_sample_03.txt AC 1 ms 3532 KiB
01_random_01.txt AC 229 ms 215172 KiB
01_random_02.txt AC 230 ms 215224 KiB
01_random_03.txt AC 229 ms 215220 KiB
01_random_04.txt AC 230 ms 215216 KiB
01_random_05.txt AC 235 ms 215288 KiB
01_random_06.txt WA 10 ms 13344 KiB
01_random_07.txt WA 185 ms 178252 KiB
01_random_08.txt WA 124 ms 115736 KiB
01_random_09.txt WA 227 ms 215152 KiB
01_random_10.txt WA 18 ms 23960 KiB
01_random_11.txt WA 165 ms 161848 KiB
01_random_12.txt WA 77 ms 79264 KiB
01_random_13.txt WA 174 ms 166832 KiB
01_random_14.txt WA 229 ms 215088 KiB
01_random_15.txt WA 151 ms 149824 KiB
01_random_16.txt AC 17 ms 19940 KiB
01_random_17.txt AC 73 ms 77128 KiB
01_random_18.txt AC 4 ms 6072 KiB
01_random_19.txt AC 224 ms 215084 KiB
01_random_20.txt AC 154 ms 151332 KiB
01_random_21.txt WA 16 ms 18408 KiB
01_random_22.txt WA 35 ms 40368 KiB
01_random_23.txt WA 84 ms 78408 KiB
01_random_24.txt WA 226 ms 215156 KiB
01_random_25.txt WA 25 ms 27352 KiB
01_random_26.txt WA 62 ms 63416 KiB
01_random_27.txt WA 78 ms 81484 KiB
01_random_28.txt WA 69 ms 67416 KiB
01_random_29.txt WA 223 ms 215356 KiB
01_random_30.txt WA 51 ms 52676 KiB
01_random_31.txt AC 29 ms 31120 KiB
01_random_32.txt AC 45 ms 49616 KiB
01_random_33.txt AC 44 ms 42996 KiB
01_random_34.txt AC 224 ms 215172 KiB
01_random_35.txt AC 21 ms 24240 KiB
01_random_36.txt WA 44 ms 48780 KiB
01_random_37.txt WA 160 ms 177596 KiB
01_random_38.txt WA 36 ms 39484 KiB
01_random_39.txt WA 199 ms 215244 KiB
01_random_40.txt WA 59 ms 67068 KiB
01_random_41.txt AC 56 ms 62872 KiB
01_random_42.txt AC 31 ms 38524 KiB
01_random_43.txt AC 144 ms 155640 KiB
01_random_44.txt AC 198 ms 215220 KiB
01_random_45.txt WA 17 ms 20860 KiB
01_random_46.txt AC 77 ms 88316 KiB
01_random_47.txt AC 55 ms 64900 KiB
01_random_48.txt AC 9 ms 11564 KiB
01_random_49.txt AC 199 ms 215088 KiB
01_random_50.txt AC 13 ms 18152 KiB
02_handmade_01.txt AC 197 ms 215216 KiB
02_handmade_02.txt WA 106 ms 104976 KiB
02_handmade_03.txt WA 61 ms 61620 KiB
02_handmade_04.txt WA 72 ms 73204 KiB
02_handmade_05.txt WA 20 ms 25456 KiB