結果

問題 No.165 四角で囲え!
ユーザー nmnmnmnmnmnmnmnmnmnmnmnmnmnm
提出日時 2014-12-21 21:00:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 154 ms / 5,000 ms
コード長 1,936 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 103,624 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 23:29:28
合計ジャッジ時間 3,475 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 108 ms
4,376 KB
testcase_06 AC 25 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 59 ms
4,376 KB
testcase_12 AC 28 ms
4,380 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 39 ms
4,376 KB
testcase_15 AC 38 ms
4,380 KB
testcase_16 AC 154 ms
4,376 KB
testcase_17 AC 133 ms
4,376 KB
testcase_18 AC 151 ms
4,380 KB
testcase_19 AC 146 ms
4,380 KB
testcase_20 AC 133 ms
4,380 KB
testcase_21 AC 132 ms
4,380 KB
testcase_22 AC 133 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(long long i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

int main(){
  int n,B;
  cin>>n>>B;
  vector<pair<int,pair<int,int> > > p;
  rep(i,0,n){
    int a,b,c;
    cin>>a>>b>>c;
    p.pb(mp(a*2,mp(b*2,c)));
  }
  sort(all(p));
  set<int> se;
  rep(i,0,p.sz){
    se.insert(p[i].se.fi-1);
  }
  se.insert(2000000001);
  vector<int> d(all(se));
  int mx = 0;
  rep(i,0,d.sz){
    rep(j,i+1,d.sz){
      vector<pair<int,int> > m;
      rep(k,0,p.sz){
        if(d[i]<p[k].se.fi&&d[j]>p[k].se.fi){
          m.pb(mp(p[k].fi, p[k].se.se));
        }
      }
      int index1 = 0;
      int index2 = 0;
      int c = 0;
      int e = 0;
      for(;;){
        if(e<=B){
          for(;;){
            c++;
            e+=m[index1].se;
            index1++;
            if(index1==m.sz)break;
            if(m[index1-1].fi==m[index1].fi)continue;
            break;
          }
        }
        else{
          for(;;){
            c--;
            e-=m[index2].se;
            index2++;
            if(index2==m.sz)break;
            if(m[index2-1].fi==m[index2].fi)continue;
            break;
          }
        }
        if(e<=B){
          mx = max(mx,c);
          if(index1==m.sz)break;
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}

/*
Y軸方向はnC2で全探索してX軸方向はしゃくとり法やるだけな問題です。O(n^3)。
*/
0