結果
| 問題 |
No.949 飲酒プログラミングコンテスト
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-12-14 23:11:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 92 ms / 2,500 ms |
| コード長 | 1,397 bytes |
| コンパイル時間 | 732 ms |
| コンパイル使用メモリ | 86,492 KB |
| 実行使用メモリ | 12,532 KB |
| 最終ジャッジ日時 | 2024-06-28 03:27:05 |
| 合計ジャッジ時間 | 2,760 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:63:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | for (int i = 0; i <= n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:64:37: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
64 | for (int i = 0; i <= n; i++) scanf("%d", bs + i);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:65:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | for (int i = 0; i < n; i++) scanf("%d", ds + i);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 949.cc: No.949 飲酒プログラミングコンテスト - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 3000;
/* typedef */
/* global variables */
int as[MAX_N + 1], bs[MAX_N + 1], ds[MAX_N];
bool dp[MAX_N + 1][MAX_N + 1];
/* subroutines */
bool check(int k) {
memset(dp, false, sizeof(dp));
dp[0][0] = true;
for (int i = 0; i < k; i++)
for (int j = 0; i + j < k; j++)
if (dp[i][j]) {
int dij = ds[k - 1 - (i + j)];
if (as[i + 1] + bs[j] >= dij) dp[i + 1][j] = true;
if (as[i] + bs[j + 1] >= dij) dp[i][j + 1] = true;
}
for (int i = 0; i <= k; i++)
if (dp[i][k - i]) return true;
return false;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i <= n; i++) scanf("%d", as + i);
for (int i = 0; i <= n; i++) scanf("%d", bs + i);
for (int i = 0; i < n; i++) scanf("%d", ds + i);
sort(ds, ds + n);
int k0 = 0, k1 = n + 1;
while (k0 + 1 < k1) {
int k = (k0 + k1) / 2;
if (check(k)) k0 = k;
else k1 = k;
}
printf("%d\n", k0);
return 0;
}
tnakao0123