結果
| 問題 | No.771 しおり |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-06-11 11:52:01 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 193 ms / 2,000 ms |
| コード長 | 1,126 bytes |
| 記録 | |
| コンパイル時間 | 6,026 ms |
| コンパイル使用メモリ | 148,864 KB |
| 実行使用メモリ | 22,048 KB |
| 最終ジャッジ日時 | 2026-04-03 08:04:21 |
| 合計ジャッジ時間 | 11,079 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge5_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
コンパイルメッセージ
main.cpp:19:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
19 | int A[N];
| ^
main.cpp:19:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
17 | int N;
| ^
main.cpp:20:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
20 | int B[N];
| ^
main.cpp:20:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
17 | int N;
| ^
main.cpp:27:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
27 | int dp[L][N];
| ^
main.cpp:27:13: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
17 | int N;
| ^
main.cpp:27:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
27 | int dp[L][N];
| ^
main.cpp:27:10: note: read of non-const variable 'L' is not allowed in a constant expression
main.cpp:26:7: note: declared here
26 | int L = 1 << N;
| ^
4 warnings generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N;
cin >> N;
int A[N];
int B[N];
for (int i = 0; i < N; ++i) {
cin >> A[i] >> B[i];
}
int L = 1 << N;
int dp[L][N];
memset(dp, -1, sizeof(dp));
memset(dp[0], 0, sizeof(dp[0]));
for (int mask = 0; mask < L; ++mask) {
for (int i = 0; i < N; ++i) {
if (mask >> i & 1) continue;
int nmask = mask | (1 << i);
for (int j = 0; j < N; ++j) {
if (dp[mask][j] == -1) continue;
int ndist = dp[mask][j];
if (__builtin_popcount(mask) != 0) {
ndist = max(ndist, (B[j] - A[j]) + A[i]);
}
if (dp[nmask][i] == -1) {
dp[nmask][i] = ndist;
} else {
dp[nmask][i] = min(dp[nmask][i], ndist);
}
}
}
}
int ans = INT_MAX;
for (int i = 0; i < N; ++i) {
ans = min(ans, dp[L - 1][i]);
}
cout << ans << endl;
return 0;
}
siman