結果

問題 No.50 おもちゃ箱
ユーザー h_nosonh_noson
提出日時 2016-03-17 13:49:08
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,152 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 54,968 KB
最終ジャッジ日時 2023-09-08 03:52:07
合計ジャッジ時間 803 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:16: error: ‘pow’ was not declared in this scope
         rep (j,pow(2,n)) {
                ^~~
main.cpp:8:36: note: in definition of macro ‘REP’
 #define REP(i,s,e) for (i = s; i < e; i++)
                                    ^
main.cpp:25:9: note: in expansion of macro ‘rep’
         rep (j,pow(2,n)) {
         ^~~
main.cpp:25:16: note: suggested alternative: ‘putw’
         rep (j,pow(2,n)) {
                ^~~
main.cpp:8:36: note: in definition of macro ‘REP’
 #define REP(i,s,e) for (i = s; i < e; i++)
                                    ^
main.cpp:25:9: note: in expansion of macro ‘rep’
         rep (j,pow(2,n)) {
         ^~~
main.cpp:42:24: error: ‘pow’ was not declared in this scope
         if (dp[i][(int)pow(2,n)-1]) {
                        ^~~
main.cpp:42:24: note: suggested alternative: ‘putw’
         if (dp[i][(int)pow(2,n)-1]) {
                        ^~~
                        putw

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

typedef long long ll;

int main() {
    int i, j, k, l, n, m;
    bool dp[11][1024] {};
    int a[10], b[10];
    cin >> n;
    rep (i,n) cin >> a[i];
    cin >> m;
    rep (i,m) cin >> b[i];
    sort(b,b+m,greater<int>{});
    dp[0][0] = true;
    REP (i,1,11) {
        rep (j,pow(2,n)) {
            if (dp[i-1][j]) {
                rep (k,pow(2,n)) {
                    if ((~j & k) == k) {
                        int sum = 0;
                        rep (l,n) {
                            if (k & (1<<l))
                                sum += a[l];
                        }
                        if (b[i-1] >= sum)
                            dp[i][j|k] = true;
                    }
                }
            }
        }
    }
    rep (i,11) {
        if (dp[i][(int)pow(2,n)-1]) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}
0