結果

問題 No.59 鉄道の旅
ユーザー sune232002sune232002
提出日時 2014-11-06 23:48:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,228 ms / 5,000 ms
コード長 719 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 147,880 KB
実行使用メモリ 12,220 KB
最終ジャッジ日時 2023-08-26 05:22:42
合計ジャッジ時間 6,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,512 KB
testcase_01 AC 3 ms
7,572 KB
testcase_02 AC 2 ms
7,528 KB
testcase_03 AC 3 ms
7,532 KB
testcase_04 AC 878 ms
10,000 KB
testcase_05 AC 2 ms
7,516 KB
testcase_06 AC 2 ms
7,584 KB
testcase_07 AC 2 ms
7,636 KB
testcase_08 AC 25 ms
7,592 KB
testcase_09 AC 10 ms
7,640 KB
testcase_10 AC 12 ms
7,760 KB
testcase_11 AC 3 ms
7,572 KB
testcase_12 AC 11 ms
11,992 KB
testcase_13 AC 1,233 ms
12,220 KB
testcase_14 AC 2,228 ms
12,008 KB
testcase_15 AC 2 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int w[1000000];
int a[1000000];
int c[1000000];

int main() {
  int n,k;
  while(scanf("%d%d",&n,&k) == 2) {
    REP(i,n) {
      c[i] = 0;
      scanf("%d", w+i);
      a[i] = abs(w[i]);
    }
    sort(a,a+n);
    int m = unique(a,a+n) - a;
    REP(i,n) {
      if (w[i]>0) {
        int id = lower_bound(a,a+m,w[i]) - a;
        int sm = 0;
        for (int j=id; j<m; ++j) sm += c[j];
        if (sm < k) c[id]++;
      } else {
        int id = lower_bound(a,a+m,-w[i]) - a;
        if (c[id]) c[id]--;
      }
    }
    int ans = 0;
    REP(i,n) ans+=c[i];
    cout << ans << endl;
  }
}
0