結果

問題 No.165 四角で囲え!
ユーザー koba-e964koba-e964
提出日時 2015-06-11 19:18:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 1,532 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 79,532 KB
実行使用メモリ 4,988 KB
最終ジャッジ日時 2023-08-26 23:44:31
合計ジャッジ時間 2,727 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
4,716 KB
testcase_01 AC 3 ms
4,676 KB
testcase_02 AC 3 ms
4,752 KB
testcase_03 AC 2 ms
4,952 KB
testcase_04 AC 2 ms
4,708 KB
testcase_05 AC 88 ms
4,704 KB
testcase_06 AC 21 ms
4,640 KB
testcase_07 AC 3 ms
4,620 KB
testcase_08 AC 2 ms
4,588 KB
testcase_09 AC 3 ms
4,748 KB
testcase_10 AC 3 ms
4,676 KB
testcase_11 AC 37 ms
4,776 KB
testcase_12 AC 17 ms
4,724 KB
testcase_13 AC 16 ms
4,736 KB
testcase_14 AC 14 ms
4,728 KB
testcase_15 AC 13 ms
4,708 KB
testcase_16 AC 120 ms
4,988 KB
testcase_17 AC 88 ms
4,736 KB
testcase_18 AC 141 ms
4,800 KB
testcase_19 AC 105 ms
4,720 KB
testcase_20 AC 90 ms
4,636 KB
testcase_21 AC 90 ms
4,796 KB
testcase_22 AC 90 ms
4,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;
const int N = 410;
int x[N], y[N], p[N];
int dp[N][N], dp2[N][N];

int main(void){
  int n, b;
  cin >> n >> b;
  REP(i, 0, n) {
    cin >> x[i] >> y[i] >> p[i];
  }
  set<int> ixp;
  REP(i, 0, n) {
    ixp.insert(x[i]);
  }
  set<int> iyp;
  REP(i, 0, n) {
    iyp.insert(y[i]);
  }
  vector<int> ixv(ixp.begin(), ixp.end());
  vector<int> iyv(iyp.begin(), iyp.end());
  REP(i, 0, n) {
    int pp = lower_bound(ixv.begin(), ixv.end(), x[i]) - ixv.begin();
    int qq = lower_bound(iyv.begin(), iyv.end(), y[i]) - iyv.begin();
    dp[pp + 1][qq + 1] += p[i];
    dp2[pp + 1][qq + 1] ++;
  }
  REP(i, 1, N) {
    REP(j, 0, N) {
      dp[i][j] += dp[i - 1][j];
      dp2[i][j] += dp2[i - 1][j];
    }
  }
  int qx = ixv.size() + 1;
  int qy = iyv.size() + 1;
  int ma = 0;
  REP(i, 0, qx) {
    REP(j, i + 1, qx) {
      int mi = 0;
      int tot = 0;
      int tot2 = 0;
      int l = 0;
      REP(k, 0, qy) {
	while (l < qy && tot <= b) {
	  ma = max(ma, tot2);
	  l++;
	  tot += dp[j][l] - dp[i][l];
	  tot2 += dp2[j][l] - dp2[i][l];
	}
	tot -= dp[j][k] - dp[i][k];
	tot2 -= dp2[j][k] - dp2[i][k];
      }
    }
  }
  cout << ma << endl;
}
0