結果

問題 No.59 鉄道の旅
ユーザー koyoprokoyopro
提出日時 2015-09-30 15:25:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 174 ms / 5,000 ms
コード長 1,004 bytes
コンパイル時間 1,132 ms
コンパイル使用メモリ 144,868 KB
実行使用メモリ 7,336 KB
最終ジャッジ日時 2023-08-26 06:43:51
合計ジャッジ時間 2,510 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 85 ms
7,232 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 20 ms
7,336 KB
testcase_09 AC 14 ms
6,884 KB
testcase_10 AC 17 ms
6,716 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 174 ms
4,376 KB
testcase_13 AC 75 ms
4,380 KB
testcase_14 AC 116 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)

int N,K,W;
#define DEV 1000
#define MAX1 (int)1e6*2
#define MAX2 (int)1e6*2/DEV+100
int count1[MAX1];
int count2[MAX2];

int jforn(int n) {
    return n / DEV;
}

int count(int n) {
    int j = jforn(n);
    int ret = 0;
    RREP(i,MAX2) {
        if (i <= j) break;
        ret += count2[i];
    }
    RREP(i,DEV) {
        int k = j * DEV + i;
        if (k < n) break;
        ret += count1[k];
    }
    return ret;
}
signed main()
{
    cin>>N>>K;
    REP(i,N) {
        cin >> W;
        int j = abs(W);
        if (W > 0) {
            if (count(j) < K) {
                count1[j]++;
                count2[jforn(j)]++;
            }
        } else {
            // あれば下ろせる
            if (count1[j]) {
                count1[j]--;
                count2[jforn(j)]--;
            }
        }
    }
    cout << count(0) << endl;
    return 0;
}
0