結果

問題 No.59 鉄道の旅
ユーザー motimoti
提出日時 2020-03-08 15:02:30
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 5,000 ms
コード長 656 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 134,840 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 14:13:22
合計ジャッジ時間 3,467 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 77 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 6 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 19 ms
4,376 KB
testcase_13 AC 143 ms
4,376 KB
testcase_14 AC 447 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(c) (c).begin(), (c).end()
int main() 
{
  
  int N, K; cin >> N >> K;
  vector<int> vec;
  rep(i, N) {
    int W; cin >> W;
    if(W > 0) {
      auto iter = lower_bound(ALL(vec), W);
      int size = (int)vec.size() - (iter-vec.begin());
      if(size >= K) { continue; }
      vec.insert(iter, W);
    }
    else {
      auto iter = lower_bound(ALL(vec), -W);
      if(iter == vec.end()) { continue; }
      if(*iter != -W) { continue; }
      vec.erase(iter);
    }
  }
  
  cout << vec.size() << endl;
  
  return 0;
}
0