結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-10 07:04:59 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 944 bytes |
| 記録 | |
| コンパイル時間 | 324 ms |
| コンパイル使用メモリ | 51,456 KB |
| 最終ジャッジ日時 | 2024-11-14 19:18:41 |
| 合計ジャッジ時間 | 663 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:10:1: error: ‘vector’ does not name a type
10 | vector<int> m, dp;
| ^~~~~~
main.cpp: In function ‘int sum_of(int)’:
main.cpp:15:30: error: ‘m’ was not declared in this scope
15 | if(mask>>i & 1) { res += m[i]; }
| ^
main.cpp: In function ‘int main()’:
main.cpp:22:3: error: ‘m’ was not declared in this scope; did you mean ‘tm’?
22 | m.resize(n);
| ^
| tm
main.cpp:28:3: error: ‘dp’ was not declared in this scope
28 | dp.resize(1<<n, 0);
| ^~
main.cpp:21:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
const int mod = 1000;
int n;
vector<int> m, dp;
int sum_of(int mask) {
int res = 0;
for(int i : range(n)) {
if(mask>>i & 1) { res += m[i]; }
}
return res;
}
int main(void) {
scanf("%d", &n);
m.resize(n);
int allsum = 0;
for(int i : range(n)) {
scanf("%d", &m[i]);
allsum += m[i];
}
dp.resize(1<<n, 0);
for(int mask : range(1<<n)) {
for(int i : range(n)) {
if(mask>>i & 1) { continue; }
int &tmp = dp[mask|(1<<i)];
int val = dp[mask] + min(m[i], sum_of(mask) % mod);
tmp = max(tmp, val);
}
}
int res = allsum - dp[(1<<n)-1];
printf("%d\n", res);
return 0;
}