結果

問題 No.165 四角で囲え!
ユーザー たこしたこし
提出日時 2015-06-12 15:39:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 2,636 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 97,988 KB
実行使用メモリ 6,172 KB
最終ジャッジ日時 2023-08-26 23:45:06
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
5,456 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 106 ms
5,544 KB
testcase_06 AC 21 ms
4,800 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 87 ms
5,308 KB
testcase_12 AC 111 ms
5,324 KB
testcase_13 AC 116 ms
5,532 KB
testcase_14 AC 117 ms
5,284 KB
testcase_15 AC 111 ms
5,196 KB
testcase_16 AC 152 ms
6,016 KB
testcase_17 AC 109 ms
5,880 KB
testcase_18 AC 157 ms
6,172 KB
testcase_19 AC 128 ms
6,024 KB
testcase_20 AC 109 ms
6,068 KB
testcase_21 AC 110 ms
6,040 KB
testcase_22 AC 109 ms
5,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF_MIN 100000000
#define INF 1145141919
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-10
#define PI acos(-1)
#define LL long long

using namespace std;

#define MAX_N 410

int N, B;
int X[MAX_N], Y[MAX_N], P[MAX_N];

vector<int> Xlist, Ylist;

//ポイントと点の数
int filedP[MAX_N][MAX_N], filedC[MAX_N][MAX_N];

//累積和
int calcFiledP[MAX_N][MAX_N], calcFiledC[MAX_N][MAX_N];

int calcPoint(int sx, int sy, int gx, int gy){

  return calcFiledP[gy][gx] - calcFiledP[gy][sx] - calcFiledP[sy][gx] + calcFiledP[sy][sx];

}

int calcCnt(int sx, int sy, int gx, int gy){

  return calcFiledC[gy][gx] - calcFiledC[gy][sx] - calcFiledC[sy][gx] + calcFiledC[sy][sx];

}

int main(){

  cin >> N >> B;
  for(int i = 0; i < N; i++){
    cin >> X[i] >> Y[i] >> P[i];
    Xlist.push_back(X[i]);
    Ylist.push_back(Y[i]);
  }

  sort(Xlist.begin(), Xlist.end());
  sort(Ylist.begin(), Ylist.end());

  //重複要素の削除
  Xlist.erase(unique(Xlist.begin(), Xlist.end()), Xlist.end());
  Ylist.erase(unique(Ylist.begin(), Ylist.end()), Ylist.end());
  
  //座標圧縮
  for(int i = 0; i < N; i++){
    X[i] = lower_bound(Xlist.begin(), Xlist.end(), X[i]) - Xlist.begin();
    Y[i] = lower_bound(Ylist.begin(), Ylist.end(), Y[i]) - Ylist.begin();
    filedP[Y[i]][X[i]] += P[i];
    filedC[Y[i]][X[i]]++;
  }

  //累積和を前計算
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      calcFiledP[i+1][j+1] = calcFiledP[i+1][j] + calcFiledP[i][j+1] - calcFiledP[i][j] + filedP[i][j];
      calcFiledC[i+1][j+1] = calcFiledC[i+1][j] + calcFiledC[i][j+1] - calcFiledC[i][j] + filedC[i][j];
    }
  }
  
  int ans = 0;

  for(int sx = 0; sx < N; sx++){
    for(int gx = sx+1; gx <= N; gx++){
      
      int sy = 0, gy = 1;

      while(gy <= N){

	int score = calcPoint(sx, sy, gx, gy);
	if(score <= B){
	  int cnt = calcCnt(sx, sy, gx, gy);
	  ans = max(ans, cnt);
	}

	else{
	  while(true){
	    sy++;
	    int score = calcPoint(sx, sy, gx, gy);
	    if(score <= B){
	      int cnt = calcCnt(sx, sy, gx, gy);
	      ans = max(ans, cnt);
	      break;
	    }
	  }
	}

	gy++;
	
      }

    }
  }

  cout << ans << endl;

  return 0;

}
0