結果
問題 |
No.59 鉄道の旅
|
ユーザー |
![]() |
提出日時 | 2015-09-30 15:22:44 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 987 bytes |
コンパイル時間 | 1,585 ms |
コンパイル使用メモリ | 158,336 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-12-24 21:55:30 |
合計ジャッジ時間 | 3,719 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 RE * 10 |
ソースコード
#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; }