結果
| 問題 | 
                            No.4 おもりと天秤
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-09-07 16:17:19 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 836 bytes | 
| コンパイル時間 | 425 ms | 
| コンパイル使用メモリ | 55,564 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-15 21:04:50 | 
| 合計ジャッジ時間 | 3,618 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 2 WA * 5 RE * 16 | 
コンパイルメッセージ
main.cpp: In function ‘bool run(int*, int, int)’:
main.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
   25 | }
      | ^
            
            ソースコード
#include <iostream>
int sum=0;
bool run(int*mess_list,int mess,int length){
	std::cout<<mess<<std::endl;
	for(int i=0;i< length;i++){
		if(mess+mess_list[i]<sum){
			int*copy=new int[length-1];
			for(int j=0;j<length;j++){
				if(i>j){
					copy[j]=mess_list[j];
				}else if(i<j){
					copy[j-1]=mess_list[j];
				}
			}
			bool result=run(copy,mess+mess_list[i],length-1);
			delete[] copy;
			if(result==true){
				return true;
			}
		}
		if(mess+mess_list[i]==sum){
			return true;
		}
	}
}
int main(){
	int n;
	std::cin>>n;
	int*mess_list=new int[n];
	for(int i=0;i<n;i++){
		std::cin>>mess_list[i];
	}
	for(int i=0;i<n;i++){
		sum+=mess_list[i];
	}
	if(sum%2==1){
		std::cout<<"impossible"<<std::endl;
		return 0;
	}
	sum/=2;
	std::cout<<(run(mess_list,0,n)?"possible":"impossible")<<std::endl;
	delete[] mess_list;
	return 0;
}