AtCoder Regular Contest 070

Submission #1451649

Source codeソースコード

#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, K, A[5000];
bool dp[5001][5000];

bool ok(ll n) {
  REP(i, 0, N + 1) REP(j, 0, K) dp[i][j] = 0;
  dp[0][0] = 1;

  REP(i, 0, N) REP(j, 0, K) if(dp[i][j]) {
    dp[i + 1][j] = 1;
    if(i != n && j + A[i] < K) dp[i + 1][j + A[i]] = 1;
  }

  bool f = 0;
  REP(i, 0, K) if(dp[N][i] && i + A[n] >= K) f = 1;
  return f;
}

int main(void) {
  cin >> N >> K;
  REP(i, 0, N) cin >> A[i];

  sort(A, A + N);

  ll l = -1, h = N;
  while(h - l > 1) {
    ll m = (l + h) / 2;
    if(ok(m)) h = m;
    else l = m;
  }
  cout << h << endl;
}

Submission

Task問題 D - No Need
User nameユーザ名 ShinyaKato
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 600
Source lengthソースコード長 720 Byte
File nameファイル名
Exec time実行時間 514 ms
Memory usageメモリ使用量 24704 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
Subtask 300 / 300 0_000.txt,0_001.txt,0_002.txt,1_003.txt,1_004.txt,1_005.txt,1_006.txt,1_007.txt,1_008.txt,1_009.txt,1_010.txt,1_011.txt,1_012.txt,1_013.txt,1_014.txt,1_015.txt,1_016.txt,1_017.txt,1_018.txt,1_019.txt,1_020.txt,1_021.txt,1_022.txt,1_023.txt,1_024.txt,1_025.txt
All 300 / 300 0_000.txt,0_001.txt,0_002.txt,1_003.txt,1_004.txt,1_005.txt,1_006.txt,1_007.txt,1_008.txt,1_009.txt,1_010.txt,1_011.txt,1_012.txt,1_013.txt,1_014.txt,1_015.txt,1_016.txt,1_017.txt,1_018.txt,1_019.txt,1_020.txt,1_021.txt,1_022.txt,1_023.txt,1_024.txt,1_025.txt,2_026.txt,2_027.txt,2_028.txt,2_029.txt,2_030.txt,2_031.txt,2_032.txt,2_033.txt,2_034.txt,2_035.txt,2_036.txt,2_037.txt,2_038.txt,2_039.txt,2_040.txt,2_041.txt,2_042.txt,2_043.txt,2_044.txt,2_045.txt,2_046.txt,2_047.txt,2_048.txt,2_049.txt,2_050.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_000.txt AC 1 ms 256 KB
0_001.txt AC 1 ms 256 KB
0_002.txt AC 1 ms 256 KB
1_003.txt AC 1 ms 256 KB
1_004.txt AC 1 ms 256 KB
1_005.txt AC 1 ms 256 KB
1_006.txt AC 1 ms 256 KB
1_007.txt AC 1 ms 256 KB
1_008.txt AC 4 ms 2048 KB
1_009.txt AC 4 ms 2048 KB
1_010.txt AC 3 ms 2048 KB
1_011.txt AC 2 ms 1792 KB
1_012.txt AC 3 ms 2048 KB
1_013.txt AC 2 ms 1792 KB
1_014.txt AC 2 ms 1920 KB
1_015.txt AC 4 ms 2048 KB
1_016.txt AC 1 ms 256 KB
1_017.txt AC 1 ms 256 KB
1_018.txt AC 1 ms 256 KB
1_019.txt AC 4 ms 1920 KB
1_020.txt AC 2 ms 1920 KB
1_021.txt AC 3 ms 1920 KB
1_022.txt AC 2 ms 1024 KB
1_023.txt AC 1 ms 768 KB
1_024.txt AC 3 ms 1920 KB
1_025.txt AC 4 ms 1920 KB
2_026.txt AC 1 ms 256 KB
2_027.txt AC 1 ms 384 KB
2_028.txt AC 1 ms 384 KB
2_029.txt AC 411 ms 24704 KB
2_030.txt AC 445 ms 24704 KB
2_031.txt AC 315 ms 24704 KB
2_032.txt AC 9 ms 23936 KB
2_033.txt AC 314 ms 24704 KB
2_034.txt AC 8 ms 23936 KB
2_035.txt AC 8 ms 23936 KB
2_036.txt AC 514 ms 24704 KB
2_037.txt AC 1 ms 256 KB
2_038.txt AC 1 ms 256 KB
2_039.txt AC 1 ms 384 KB
2_040.txt AC 433 ms 24704 KB
2_041.txt AC 272 ms 24704 KB
2_042.txt AC 415 ms 24704 KB
2_043.txt AC 208 ms 16640 KB
2_044.txt AC 263 ms 22784 KB
2_045.txt AC 130 ms 20736 KB
2_046.txt AC 251 ms 24704 KB
2_047.txt AC 345 ms 24704 KB
2_048.txt AC 442 ms 24704 KB
2_049.txt AC 452 ms 24704 KB
2_050.txt AC 459 ms 24704 KB