結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  hitoyozake | 
| 提出日時 | 2018-05-20 01:04:21 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 119 ms / 5,000 ms | 
| コード長 | 1,413 bytes | 
| コンパイル時間 | 957 ms | 
| コンパイル使用メモリ | 96,768 KB | 
| 最終ジャッジ日時 | 2025-01-05 10:42:09 | 
| ジャッジサーバーID (参考情報) | judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
int main()
{
    int n = 0;
    std::cin >> n;
    bool found = false;
    std::vector< int > v;
    for( int i = 0; i < n; ++i )
       {
           int tmp;
           std::cin >> tmp;
           v.push_back(tmp);
       }
    //std::sort(v.begin(), v.end());
    
    std::map<int, bool> dps[201];
    int sum = std::accumulate(v.begin(), v.end(), 0);
    int h = sum/2;
    dps[0][0] = true;
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= h; ++j)
        {
//            std::cout << "j:" << j << std::endl;
            //驕ク縺ー縺ェ縺九▲縺溷�エ蜷�
            if(dps[i][j] == true)
            {
                dps[i+1][j] = true;
            }
            //驕ク繧薙□蝣エ蜷�
            if(j>=v[i]&&dps[i][j - v[i]] == true)
            {
                //std::cout << "!!!" << std::endl;
                dps[i+1][j] = true;
            }
        }
    } 
    for(int i = 0; i < n; ++i)
    {
        for( auto it: dps[i])
        {
  //          std::cout << it.first << ":" << it.second << std::endl;
        }
    }
    if( sum%2==0 && dps[n][h]==true )
        found = true;
    
    if( found )
        std::cout << "possible" << std::endl;
    else
        std::cout << "impossible" << std::endl;
}
            
            
            
        