結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  assy1028 | 
| 提出日時 | 2015-03-20 18:58:37 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 989 bytes | 
| コンパイル時間 | 701 ms | 
| コンパイル使用メモリ | 79,108 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:09:23 | 
| 合計ジャッジ時間 | 1,508 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
コンパイルメッセージ
main.cpp: In function ‘bool solve(int)’:
main.cpp:31:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |         scanf("%d", &v);
      |         ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:51:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
            
            ソースコード
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <complex>
#include <string.h>
using namespace std;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
const int inf = 1000000009;
bool solve(int n) {
    int w[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
	int v;
	scanf("%d", &v);
	sum += v;
	w[i] = v;
    }
    if (sum % 2 == 1) return false;
    bool can[sum+1];
    memset(can, false, sizeof(can));
    can[0] = true;
    for (int i = 0; i < n; i++) {
	for (int j = sum; j >= 0; j--) {
	    if (can[j])
		can[j+w[i]] = true;
	}
    }
    return can[sum/2];
}
int main() {
    int n;
    scanf("%d", &n);
    printf("%s\n", solve(n) ? "possible" : "impossible");
}
            
            
            
        