結果
問題 | No.59 鉄道の旅 |
ユーザー | hogeover30 |
提出日時 | 2015-03-05 17:53:24 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 18 ms / 5,000 ms |
コード長 | 596 bytes |
コンパイル時間 | 708 ms |
コンパイル使用メモリ | 27,060 KB |
実行使用メモリ | 6,928 KB |
最終ジャッジ日時 | 2023-08-26 05:37:11 |
合計ジャッジ時間 | 1,550 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,868 KB |
testcase_01 | AC | 4 ms
6,864 KB |
testcase_02 | AC | 4 ms
6,916 KB |
testcase_03 | AC | 4 ms
6,920 KB |
testcase_04 | AC | 18 ms
6,884 KB |
testcase_05 | AC | 4 ms
6,864 KB |
testcase_06 | AC | 4 ms
6,912 KB |
testcase_07 | AC | 4 ms
6,808 KB |
testcase_08 | AC | 6 ms
6,864 KB |
testcase_09 | AC | 5 ms
6,928 KB |
testcase_10 | AC | 5 ms
6,928 KB |
testcase_11 | AC | 4 ms
6,808 KB |
testcase_12 | AC | 10 ms
6,856 KB |
testcase_13 | AC | 18 ms
6,916 KB |
testcase_14 | AC | 18 ms
6,912 KB |
testcase_15 | AC | 4 ms
6,912 KB |
ソースコード
#include <cstdio> #include <cstring> const int maxw=1000001; int b[maxw]; void add(int i, int x) { while (i<maxw) { b[i]+=x; i+=i&-i; } } int sum(int i) { int res=0; while (i>0) { res+=b[i]; i-=i&-i; } return res; } int main() { int n, k; while (~scanf("%d%d", &n, &k)) { memset(b, 0, sizeof(b)); while (n--) { int w; scanf("%d", &w); if (w>0 and sum(maxw)-sum(w-1)<k) add(w, 1); else if (w<0 and sum(-w)-sum(-w-1)>0) add(-w, -1); } printf("%d\n", sum(maxw)); } }