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