結果

問題 No.568 じゃんじゃん 落とす 委員会
ユーザー ojisan_ITojisan_IT
提出日時 2017-09-24 15:25:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 1,000 ms
コード長 1,865 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 88,620 KB
実行使用メモリ 5,380 KB
最終ジャッジ日時 2023-08-20 09:49:29
合計ジャッジ時間 3,454 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
5,380 KB
testcase_01 AC 88 ms
5,296 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 87 ms
4,996 KB
testcase_13 AC 89 ms
5,112 KB
testcase_14 AC 86 ms
4,908 KB
testcase_15 AC 87 ms
4,960 KB
testcase_16 AC 83 ms
4,992 KB
testcase_17 AC 82 ms
5,052 KB
testcase_18 AC 83 ms
4,968 KB
testcase_19 AC 86 ms
4,908 KB
testcase_20 AC 84 ms
5,000 KB
testcase_21 AC 84 ms
5,068 KB
testcase_22 AC 89 ms
5,272 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cmath>
#include<climits>
#include<algorithm>

#include<tuple>

using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))

#define mt make_tuple

typedef tuple<int,int> tii;
vector<int> x(100001);
int main(){
  int n,m; cin >> n >> m;
  vector<tii> a;
  vector<tii> b;
  rep(i,n){
    int xx,aa,bb; cin >> xx >> aa >> bb;
    a.pb(tii{i,aa});
    b.pb(tii{i,bb});
    x[i] = xx+1;
  }
  sort(ALL(a),[](tii a,tii b){return get<1>(a) < get<1>(b);});
  sort(ALL(b),[](tii a,tii b){return get<1>(a) < get<1>(b);});
  int ans = INF;
  int now_a = -2, now_b = 200001;
  int a_index = 0, b_index = n-1;
  int cnt[6] = {};
  rep(i,n){cnt[x[i]]++;}
  
  while(now_a < 200001 && now_b >= -1){
    // SHOW(now_a,now_b);
    // rep(i,6)cerr <<" "<<cnt[i]; cerr<<endl;
    if(cnt[2]+cnt[3]+cnt[4]+cnt[5] >= m){
      ans = min(ans,cnt[3]+cnt[4]+cnt[5]);
      now_a++;
      for(;a_index < n && get<1>(a[a_index]) < now_a; a_index++){
        cnt[x[get<0>(a[a_index])]]--;
        x[get<0>(a[a_index])]--;
        cnt[x[get<0>(a[a_index])]]++;
      }
    }else{
      now_b--;
      for(;b_index >= 0 && get<1>(b[b_index]) > now_b; b_index--){
        cnt[x[get<0>(b[b_index])]]--;
        x[get<0>(b[b_index])]++;
        cnt[x[get<0>(b[b_index])]]++;
      }
    }
  }
  
  cout << ans << endl;
}
0