結果

問題 No.59 鉄道の旅
ユーザー h_nosonh_noson
提出日時 2016-04-06 19:57:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 1,100 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 65,012 KB
実行使用メモリ 11,172 KB
最終ジャッジ日時 2023-08-26 06:55:37
合計ジャッジ時間 1,382 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,400 KB
testcase_01 AC 2 ms
5,704 KB
testcase_02 AC 1 ms
5,460 KB
testcase_03 AC 1 ms
5,596 KB
testcase_04 AC 39 ms
11,172 KB
testcase_05 AC 1 ms
5,612 KB
testcase_06 AC 2 ms
5,596 KB
testcase_07 AC 1 ms
5,508 KB
testcase_08 AC 12 ms
11,160 KB
testcase_09 AC 12 ms
10,704 KB
testcase_10 AC 9 ms
10,308 KB
testcase_11 AC 4 ms
7,516 KB
testcase_12 AC 14 ms
7,480 KB
testcase_13 AC 30 ms
5,728 KB
testcase_14 AC 31 ms
5,840 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 100000000
#define MAX 1048576

typedef long long ll;

int bit[MAX+1];
int item[1000001];

int main() {
    int i, n, k;
    cin >> n >> k;
    rep (i,n) {
        int w;
        cin >> w;
        if (w > 0) {
            int x = w-1;
            int sum = bit[MAX];
            while (x > 0) {
                sum -= bit[x];
                x -= x & -x;
            }
            if (sum < k) {
                item[w]++;
                while (w <= MAX) {
                    bit[w]++;
                    w += w & -w;
                }
            }
        }
        else {
            w = -w;
            if (item[w] > 0) {
                item[w]--;
                while (w <= MAX) {
                    bit[w]--;
                    w += w & -w;
                }
            }
        }
    }
    cout << bit[MAX] << endl;
    return 0;
}
0