結果
| 問題 | No.733 分身並列コーディング |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2022-07-01 17:53:40 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 1,500 ms |
| コード長 | 1,044 bytes |
| 記録 | |
| コンパイル時間 | 7,418 ms |
| コンパイル使用メモリ | 150,784 KB |
| 実行使用メモリ | 13,312 KB |
| 最終ジャッジ日時 | 2026-05-20 12:09:03 |
| 合計ジャッジ時間 | 9,545 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 46 |
コンパイルメッセージ
main.cpp:28:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
28 | int dp[L][N + 2];
| ^~~~~
main.cpp:28:13: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
19 | int N;
| ^
main.cpp:28:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
28 | int dp[L][N + 2];
| ^
main.cpp:28:10: note: read of non-const variable 'L' is not allowed in a constant expression
main.cpp:27:7: note: declared here
27 | int L = 1 << N;
| ^
2 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int T;
cin >> T;
int N;
cin >> N;
vector<int> times(N);
for (int i = 0; i < N; ++i) {
cin >> times[i];
}
int L = 1 << N;
int dp[L][N + 2];
memset(dp, 0, sizeof(dp));
for (int mask = 1; mask < L; ++mask) {
for (int i = 0; i <= N; ++i) {
dp[mask][i] = T * N + 1;
}
}
for (int mask = 1; mask < L; ++mask) {
for (int i = 0; i < N; ++i) {
if (mask >> i & 1) {
for (int j = 0; j <= N; ++j) {
int nmask = mask ^ (1 << i);
dp[mask][j] = min(dp[mask][j], dp[nmask][j] + times[i]);
if (dp[mask][j] <= T) {
dp[mask][j + 1] = 0;
}
}
}
}
}
for (int i = 0; i <= N; ++i) {
if (!dp[L - 1][i]) {
cout << i << endl;
break;
}
}
return 0;
}
siman