結果

問題 No.59 鉄道の旅
ユーザー koyoprokoyopro
提出日時 2015-09-30 15:22:44
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 987 bytes
コンパイル時間 1,165 ms
コンパイル使用メモリ 144,784 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-26 06:43:21
合計ジャッジ時間 3,426 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 MAX1 (int)1e5+100
#define MAX2 (int)1e5/500+100
int count1[MAX1];
int count2[MAX2];

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

int count(int n) {
    int j = jforn(n);
    int ret = 0;
    RREP(i,MAX2) {
        if (i <= j) break;
        ret += count2[i];
    }
    RREP(i,500) {
        int k = j * 500 + 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