結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  777yuuki12323 | 
| 提出日時 | 2017-06-28 12:54:18 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 1,140 bytes | 
| コンパイル時間 | 718 ms | 
| コンパイル使用メモリ | 74,280 KB | 
| 実行使用メモリ | 5,632 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:20:53 | 
| 合計ジャッジ時間 | 1,484 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |                 scanf("%d", w+i);
      |                 ~~~~~^~~~~~~~~~~
            
            ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>
typedef long long ll;
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789
using namespace std;
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////
////////////////////////////////////////////////
////////////////////////////////////////////////
int N;
int idx;
int top;
int wa = 0;
int w[112];
int dp[112][5123];
int main(){
	
	int i;
	int j;
	int flag = 0;
	
	cin>>N;
	
	fill( dp[0], dp[N], 0 );
	
	for( i = 0; i < N; i++ ){
		scanf("%d", w+i);
		wa += w[i];
	}
	
	sort( w, w+N );
	
	
	dp[0][0] = 1;
	
	if( wa % 2 == 0 ){
		wa /= 2;
		
		for( i = 1; i <= N; i++ ){
			top = wa-w[i-1];
			for( j = 0; j <= top; j++ ){
				if( dp[i-1][j] ){
					dp[i][j] = dp[i-1][j];
					idx = j+w[i];
					dp[i][idx] = 1;
					if( idx == wa ){
						flag = 1;
						i = mod;
						j = mod;
					}
				}
			}
		}
		
	}
	
	
	if( flag ) puts("possible");
	else{	   puts("impossible");}
	
	return 0;
}
            
            
            
        