結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
cww
|
| 提出日時 | 2017-06-26 01:51:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 866 bytes |
| コンパイル時間 | 1,802 ms |
| コンパイル使用メモリ | 173,744 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-06-26 10:20:39 |
| 合計ジャッジ時間 | 2,713 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#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>> memo( 100 + 1, vector<int>( 10000 + 1, -1 ) );
int N, total, res;
vector<int> vc;
bool dfs( int i, int x )
{
if( i == 0 )
{
return x == 0;
}
if( x < 0 )
{
return false;
}
int &res = memo[ i ][ x ];
if( res != -1 )
{
return res;
}
return ( res = dfs( i - 1, x ) || dfs( i - 1, x - vc[ i - 1 ] ) );
}
int main()
{
cin >> N;
vc.resize( N );
for( auto &x : vc )
{
cin >> x;
}
total = accumulate( ALL( vc ), 0 );
cout << ( dfs( N - 1, total / 2 ) && total % 2 == 0 ? "possible" : "impossible" ) << endl;
return 0;
}
cww