結果

問題 No.107 モンスター
ユーザー なおなお
提出日時 2014-12-19 00:31:59
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,537 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 150,744 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 19:02:38
合計ジャッジ時間 2,646 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 1 ms
4,368 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,368 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
const int MOD = 1000000007;

vector<int> P,M;
unsigned int up, um;

inline void bits(unsigned int &p, int n){ p |= (1<<n); }
inline void bitu(unsigned int &p, int n){ p &= ~(1<<n); }
inline bool biti(unsigned int p, int n){ return !!(p & (1<<n)); };
inline int  bitc(unsigned int p){int c=0;for(;p;p&=p-1) c++; return c; }

int D[20];
int main(){
    int N;
    cin >> N;
    REP(i,N) cin >> D[i];
    int pn = 0, mn = 0;

    REP(i,N){
        if(D[i] < 0){
            M.push_back(-D[i]);
        } else {
            P.push_back(D[i]);
        }
    }
    sort(M.begin(), M.end(), greater<int>());
    sort(P.begin(), P.end(), greater<int>());

    int mv = 100, v = 100, cnt = 1000;

    while(cnt--){
        bool f = false;
        REP(i,M.size()){
            if(biti(um,i)) continue;
            if(v <= M[i]) continue;
            bits(um, i);
            v -= M[i], mv += 100;
            f = true; break;
        }
        if(f) continue;
        int lasti = -1;
        REP(i,P.size()){
            if(biti(up,i)) continue;
            lasti = i;
            if(mv-v < P[i]) continue;
            bits(up, i);
            v += P[i];
            f = true; break;
        }
        if(f) continue;
        if(lasti >= 0){
            bits(up, lasti);
            v += P[lasti];
            if(v > mv) v = mv;
        }

    }
    if(um != (1<<M.size())-1) v = 0;

    cout << v << endl;
    return 0;
}
0