結果

問題 No.4 おもりと天秤
ユーザー cwwcww
提出日時 2017-04-20 17:47:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 785 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 169,776 KB
実行使用メモリ 7,428 KB
最終ジャッジ日時 2023-08-27 00:45:14
合計ジャッジ時間 6,106 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘bool memo(int, int)’ 内:
main.cpp:22:13: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   22 |         memo( i + 1, total );
      |         ~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
vector<vector<int>> visited( 100 + 1, vector<int>( 10000 + 1, 0 ) );
vector<int> w;
int N, total;
bool memo( int i, int total )
{
	if( visited[ i ][ total ] )
	{
		return visited[ i ][ total ];
	}
	if( i == N )
	{
		return 0;
	}
	visited[ i ][ total ] = 1;
	memo( i + 1, total + w[ i ] );
	memo( i + 1, total );
}
int main()
{
	cin >> N;
	w.resize( N );
	for( auto &x : w )
	{
		cin >> x;
	}
	total = accumulate( ALL( w ), 0 );
	memo( 0, 0 );
	cout << ( visited[ N - 1 ][ total / 2 ] && total % 2 == 0 ? "possible" : "impossible" ) << endl;
    return 0;
}
0