結果

問題 No.1522 Unfairness
ユーザー kiyoshi0205kiyoshi0205
提出日時 2021-05-28 22:47:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 4,567 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 210,508 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 07:29:13
合計ジャッジ時間 3,684 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 6 ms
4,376 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 10 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 11 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 19 ms
4,376 KB
testcase_16 AC 19 ms
4,380 KB
testcase_17 AC 19 ms
4,380 KB
testcase_18 AC 18 ms
4,376 KB
testcase_19 AC 18 ms
4,380 KB
testcase_20 AC 19 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
  char num[40000];
  constexpr Pre() : num() {
    for (int i = 0; i < 10000; i++) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
        num[i * 4 + j] = n % 10 + '0';
        n /= 10;
      }
    }
  }
} constexpr pre;

__attribute__((target("avx2"), optimize("O3"))) inline void load() {
  memcpy(ibuf, ibuf + pil, pir - pil);
  pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
  pil = 0;
}

__attribute__((target("avx2"), optimize("O3"))) inline void flush() {
  fwrite(obuf, 1, por, stdout);
  por = 0;
}

inline void rd(char& c) { c = ibuf[pil++]; }

template <typename T>
__attribute__((target("avx2"), optimize("O3"))) inline void rd(T& x) {
  if (pil + 32 > pir) load();
  char c;
  do
    rd(c);
  while (c < '-');
  bool minus = 0;
  if constexpr (is_signed<T>::value) {
    if (c == '-') {
      minus = 1;
      rd(c);
    }
  }
  x = 0;
  while (c >= '0') {
    x = x * 10 + (c & 15);
    rd(c);
  }
  if constexpr (is_signed<T>::value) {
    if (minus) x = -x;
  }
}

inline void wt(char c) { obuf[por++] = c; }
template <typename T>
__attribute__((target("avx2"), optimize("O3"))) inline void wt(T x) {
  if (por + 32 > SZ) flush();
  if (!x) {
    wt('0');
    return;
  }
  if constexpr (is_signed<T>::value) {
    if (x < 0) {
      wt('-');
      x = -x;
    }
  }
  if (x >= 10000000000000000) {
    uint32_t r1 = x % 100000000;
    uint64_t q1 = x / 100000000;
    if (x >= 1000000000000000000) {
      uint32_t n1 = r1 % 10000;
      uint32_t n2 = r1 / 10000;
      uint32_t n3 = q1 % 10000;
      uint32_t r2 = q1 / 10000;
      uint32_t n4 = r2 % 10000;
      uint32_t q2 = r2 / 10000;
      memcpy(obuf + por + 15, pre.num + (n1 << 2), 4);
      memcpy(obuf + por + 11, pre.num + (n2 << 2), 4);
      memcpy(obuf + por + 7, pre.num + (n3 << 2), 4);
      memcpy(obuf + por + 3, pre.num + (n4 << 2), 4);
      memcpy(obuf + por, pre.num + (q2 << 2) + 1, 3);
      por += 19;
    } else if (x >= 100000000000000000) {
      uint32_t n1 = r1 % 10000;
      uint32_t n2 = r1 / 10000;
      uint32_t n3 = q1 % 10000;
      uint32_t r2 = q1 / 10000;
      uint32_t n4 = r2 % 10000;
      uint32_t q2 = r2 / 10000;
      uint32_t q3 = (q2 * 205) >> 11;
      uint32_t r3 = q2 - q3 * 10;
      memcpy(obuf + por + 14, pre.num + (n1 << 2), 4);
      memcpy(obuf + por + 10, pre.num + (n2 << 2), 4);
      memcpy(obuf + por + 6, pre.num + (n3 << 2), 4);
      memcpy(obuf + por + 2, pre.num + (n4 << 2), 4);
      obuf[por + 1] = '0' + r3;
      obuf[por + 0] = '0' + q3;
      por += 18;
    } else {
      uint32_t n1 = r1 % 10000;
      uint32_t n2 = r1 / 10000;
      uint32_t n3 = static_cast<uint32_t>(q1) % 10000;
      uint32_t r2 = static_cast<uint32_t>(q1) / 10000;
      uint32_t n4 = r2 % 10000;
      uint32_t q2 = r2 / 10000;
      memcpy(obuf + por + 13, pre.num + (n1 << 2), 4);
      memcpy(obuf + por + 9, pre.num + (n2 << 2), 4);
      memcpy(obuf + por + 5, pre.num + (n3 << 2), 4);
      memcpy(obuf + por + 1, pre.num + (n4 << 2), 4);
      obuf[por + 0] = '0' + q2;
      por += 17;
    }
  } else {
    int i = 8;
    char buf[12];
    while (x >= 10000) {
      memcpy(buf + i, pre.num + (x % 10000) * 4, 4);
      x /= 10000;
      i -= 4;
    }
    if (x < 100) {
      if (x < 10) {
        wt(char('0' + x));
      } else {
        obuf[por + 0] = '0' + x / 10;
        obuf[por + 1] = '0' + x % 10;
        por += 2;
      }
    } else {
      if (x < 1000) {
        memcpy(obuf + por, pre.num + (x << 2) + 1, 3);
        por += 3;
      } else {
        memcpy(obuf + por, pre.num + (x << 2), 4);
        por += 4;
      }
    }
    memcpy(obuf + por, buf + i + 4, 8 - i);
    por += 8 - i;
  }
}

struct Dummy {
  Dummy() { atexit(flush); }
} dummy;

}  // namespace fastio
using fastio::rd;
using fastio::wt;


unsigned int N,M,dp[2][3001],nx[2][3001],a[3000];
__attribute__((target("avx2"), optimize("O3"))) int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  rd(N);
  rd(M);
  for(unsigned int i=0;i<N;++i)rd(a[i]);
  sort(a,a+N,greater<unsigned int>());
  for(unsigned int i=0;i<N-1;++i){
    unsigned int x=a[i]-a[i+1];
    for(unsigned int j=0;j<=M;++j){
      nx[0][j]=max(dp[0][j],dp[1][j]);
      if(j+x<=M)nx[1][j+x]=dp[0][j]+a[i];
    }
    swap(dp,nx);
  }
  unsigned int ans=0;
  for(int i=0;i<2;++i)for(unsigned int j=0;j<=M;++j)if(ans<dp[i][j])ans=dp[i][j];
  wt(ans);
  wt('\n');
}
0