結果

問題 No.107 モンスター
ユーザー itezpaceitezpace
提出日時 2016-11-21 07:22:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,475 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 70,876 KB
実行使用メモリ 7,608 KB
最終ジャッジ日時 2023-08-18 06:08:16
合計ジャッジ時間 8,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N;cin>>N;
  int D;
  vector<int> vg1,vb1;
  for(int i=0;i<N;++i){
    cin>>D;
    if(D>0) vg1.push_back(D);
    else if(D<0) vb1.push_back(D*-1);
  }
  int L=100,LM=100,LP=100;
  sort(vg1.begin(),vg1.end());
  sort(vb1.begin(),vb1.end(),greater<int>());
  while(1){
    vector<int> vbp1;
    for(int i=0;i<vb1.size();++i){
      int a=vb1[i];
      if(L>a){
        L-=a;
        vbp1.push_back(i);
      }
    }
    if(L==LP && vb1.size()!=0 && vg1.size()==0){
      L=0;
      break;
    }
    int cnt_b=0;
    for(int i=0;i<vbp1.size();++i){
      int b=vbp1[i];
      vb1.erase(vb1.begin()+b-cnt_b);
      LM+=100;
      cnt_b+=1;
    }
    LP=L;
    vector<int> vgp1;
    for(int i=0;i<vg1.size();++i){
      int c=vg1[i];
      if(LM>=L+c){
        L+=c;
        vgp1.push_back(i);
      }
    }
    if(L==LP && vb1.size()!=0 && vg1.size()!=0){
      for(int i=0;i<vg1.size();++i){
        int c=vg1[i];
        if(LM>L){
          L=min(LM,L+c);
          vgp1.push_back(i);
        }
      }
    }
    if(L==LP && vb1.size()==0 && vg1.size()!=0){
      for(int i=0;i<vg1.size();++i){
        int e=vg1[i];
        L=max(LM,L+e);
      }
      break;
    }
    int cnt_g=0;
    for(int i=0;i<vgp1.size();++i){
      int d=vgp1[i];
      vg1.erase(vg1.begin()+d-cnt_g);
      cnt_g+=1;
    }
    LP=L;
    if(vb1.size()==0 && vg1.size()==0) break;
  }
  cout<<L<<endl;
}
0