結果

問題 No.4 おもりと天秤
ユーザー h_nosonh_noson
提出日時 2016-02-16 23:00:33
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 639 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 57,064 KB
最終ジャッジ日時 2023-09-08 16:34:57
合計ジャッジ時間 820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:15: error: ‘accumulate’ was not declared in this scope
     int sum = accumulate(w.begin(),w.end(),0);
               ^~~~~~~~~~

ソースコード

diff #

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

#define REPR(i,s,e) for (int i = e-1; i >= s; i--)
#define repr(i,n) REPR(i,0,n)
#define REP(i,s,e) for (int i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w[i];

    int sum = accumulate(w.begin(),w.end(),0);
    vector<bool> dp(sum+1);
    dp[0] = true;
    rep(i,n) repr(j,sum+1) {
        if (dp[j])
            dp[j+w[i]] = true;
    }
    if (sum % 2 == 0 && dp[sum/2])
        cout << "possible" << endl;
    else
        cout << "impossible" << endl;

    return 0;
}

0