提出 #66765991


ソースコード 拡げる

#include <bits/stdc++.h>
#define fs first
#define se second
using namespace std;
#define For(s,e) \
  for(int i=s;i<=e;++i)
#define ForR(s,e) \ 
  for(int i=s;i>=e;--i)
#define FOR(n) \
  for(int i=0;i<n;++i)
#define FORR(n) \ 
  for(int i=n-1;i>=0;--i)
#define IN(a,n) \
  FOR(n){\
    cin>>a[i];\
  }

int d[3003][3003][2];
int main(int /* argc */, char** /* argv */) {
  int n,h,m;
  cin>>n>>h>>m;
  int a[n],b[n];
  for(int i=0;i<n;++i){
    cin>>a[i]>>b[i];
  }
  int l=0,r=n;
  while(l<r){
    int mid=(l+r)>>1;
    memset(d,0,sizeof(d));
    d[0][0][0]=1;
    d[0][0][1]=0;
    bool ok = 0;
    for(int i=1;i<=mid+1;++i){
      for(int j=a[i-1];j<=h;++j){
        if(d[i-1][j-a[i-1]][0]==1){
          d[i][j][0]=1;
          d[i][j][1]=d[i-1][j-a[i-1]][1];
          if(i==mid+1){
            ok=true;
          }
        }
      }
      for(int j=0;j<=h;++j){
        if(d[i-1][j][0]==1&&d[i-1][j][1]+b[i-1]<=m){
          if(d[i][j][0]==1){
            d[i][j][1]=min(d[i-1][j][1]+b[i-1],d[i][j][1]);
          }else{
            d[i][j][1] = d[i-1][j][1]+b[i-1];
          }
          d[i][j][0]=1;
          if(i==mid+1){
            ok=true;
          }
        }
      }
    }
    if(ok){
      l=mid+1;
    } else {
      r=mid;
    }
  }
  cout<<l<<endl;
  return 0;
}

提出情報

提出日時
問題 E - Battles in a Row
ユーザ zz050201010
言語 C++ 23 (Clang 16.0.6)
得点 450
コード長 1348 Byte
結果 AC
実行時間 279 ms
メモリ 74172 KiB

コンパイルエラー

./Main.cpp:7:20: warning: backslash and newline separated by space [-Wbackslash-newline-escape]
#define ForR(s,e) \ 
                   ^
./Main.cpp:11:18: warning: backslash and newline separated by space [-Wbackslash-newline-escape]
#define FORR(n) \ 
                 ^
2 warnings generated.

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 40
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 115 ms 74028 KiB
random_02.txt AC 150 ms 73980 KiB
random_03.txt AC 153 ms 74048 KiB
random_04.txt AC 102 ms 74016 KiB
random_05.txt AC 130 ms 74092 KiB
random_06.txt AC 117 ms 73952 KiB
random_07.txt AC 145 ms 74044 KiB
random_08.txt AC 177 ms 74020 KiB
random_09.txt AC 176 ms 74000 KiB
random_10.txt AC 113 ms 74020 KiB
random_11.txt AC 146 ms 73968 KiB
random_12.txt AC 167 ms 73988 KiB
random_13.txt AC 90 ms 73952 KiB
random_14.txt AC 111 ms 74012 KiB
random_15.txt AC 189 ms 74024 KiB
random_16.txt AC 108 ms 74024 KiB
random_17.txt AC 120 ms 73948 KiB
random_18.txt AC 117 ms 73952 KiB
random_19.txt AC 112 ms 73968 KiB
random_20.txt AC 127 ms 74004 KiB
random_21.txt AC 157 ms 73992 KiB
random_22.txt AC 113 ms 73972 KiB
random_23.txt AC 121 ms 73992 KiB
random_24.txt AC 141 ms 74172 KiB
random_25.txt AC 63 ms 73984 KiB
random_26.txt AC 67 ms 73996 KiB
random_27.txt AC 72 ms 74152 KiB
random_28.txt AC 31 ms 74012 KiB
random_29.txt AC 32 ms 73952 KiB
random_30.txt AC 39 ms 74028 KiB
random_31.txt AC 210 ms 73968 KiB
random_32.txt AC 180 ms 74004 KiB
random_33.txt AC 254 ms 74032 KiB
random_34.txt AC 278 ms 74092 KiB
random_35.txt AC 275 ms 74032 KiB
random_36.txt AC 256 ms 74008 KiB
random_37.txt AC 279 ms 74028 KiB
sample_01.txt AC 40 ms 73944 KiB
sample_02.txt AC 39 ms 74008 KiB
sample_03.txt AC 47 ms 73920 KiB