結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  opqopq_ | 
| 提出日時 | 2015-04-29 23:31:24 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 2 ms / 5,000 ms | 
| コード長 | 547 bytes | 
| コンパイル時間 | 179 ms | 
| コンパイル使用メモリ | 22,528 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 09:11:19 | 
| 合計ジャッジ時間 | 950 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:13:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         for (int i = 0; i < N; i++) scanf("%d", W + i);
      |                                     ~~~~~^~~~~~~~~~~~~
            
            ソースコード
#include <cstdio>
using namespace std;
#define MAX_N 100
#define MAX_W 100
int N;
int W[MAX_N];
bool dp[MAX_N * MAX_W + 1];
int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", W + i);
	
	int sum = 0;
	for (int i = 0; i < N; i++) sum += W[i];
	
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		for (int w = MAX_N * MAX_W; W[i] <= w; w--) {
			dp[w] = dp[w] | dp[w - W[i]];
		}
	}
	
	bool ispossible = 0;
	if (sum % 2 == 0 && dp[sum / 2]) ispossible = 1;
	
	printf("%s\n", ispossible ? "possible" : "impossible");
	
	return 0;
}
            
            
            
        