結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
Twizz
|
| 提出日時 | 2017-05-19 09:39:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 151 ms / 2,000 ms |
| コード長 | 754 bytes |
| 記録 | |
| コンパイル時間 | 1,907 ms |
| コンパイル使用メモリ | 158,052 KB |
| 実行使用メモリ | 259,472 KB |
| 最終ジャッジ日時 | 2024-09-18 22:43:35 |
| 合計ジャッジ時間 | 9,489 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int rec(int, int)’:
main.cpp:17:19: warning: overflow in conversion from ‘ll’ {aka ‘long long int’} to ‘int’ changes value from ‘10000000000’ to ‘1410065408’ [-Woverflow]
17 | int res = mod;
| ^~~
ソースコード
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;
int n;
int m[16];
int dp[65537][1000];//これまで取ったものの集合と合計値段のmodでこれからいくらかかるかの最小値
int rec(int s,int p) {
if (dp[s][p] > 0)return dp[s][p];
if (s == (1 << n) - 1)return dp[s][p] = 0;
int res = mod;
REP(u, n) {
if (!(s >> u & 1)) {
res = min(res, rec(s | 1 << u, (p + m[u]) % 1000) + max(0, m[u] - p % 1000));
}
}
return dp[s][p] = res;
}
int main() {
cin >> n;
REP(i, n)cin >> m[i];
memset(dp, -1, sizeof(dp));
print(rec(0,0));
return 0;
}
Twizz