結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー tansunogontansunogon
提出日時 2017-05-09 07:30:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 4,000 ms
コード長 2,428 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 79,012 KB
実行使用メモリ 9,696 KB
最終ジャッジ日時 2023-08-16 03:09:05
合計ジャッジ時間 2,732 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 52 ms
9,696 KB
testcase_30 AC 41 ms
8,676 KB
testcase_31 AC 40 ms
8,392 KB
testcase_32 AC 32 ms
8,040 KB
testcase_33 AC 40 ms
7,024 KB
testcase_34 AC 35 ms
6,792 KB
testcase_35 AC 51 ms
9,580 KB
testcase_36 AC 52 ms
9,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct iostream_init_struct
{ 
	iostream_init_struct()
	{
		std::cin.tie(0);
		std::ios::sync_with_stdio(false);
	}
} iostream_init;

// index begins with 1
class BIT
{
public:
	vector<long long> data;
	const int msb_n;

	BIT(int n) : data(n + 1), msb_n(1 << log(n)) {}

	void add(int i, int v)
	{
		for (int x = i; x < data.size(); x += x & -x)
		{
			data[x] += v;
		}
	}

	//long long sum(int i)
	//{
	//	int ret = 0;
	//	for (int x = i; x > 0; x -= x & -x)
	//	{
	//		ret += data[x];
	//	}
	//	return ret;
	//}

	int lowerBound(long long v)
	{
		int x = 0;
		for (int k = msb_n; k > 0; k /= 2)
		{
			if (x + k < data.size() && data[x + k] < v)
			{
				v -= data[x + k];
				x += k;
			}
		}
		return x + 1;
	}

	inline static int log(int n)
	{
#ifdef __GNUC__
		return std::__lg(n);
#else
		int ret = 0;
		while (n = n >> 1)
		{
			ret += 1;
		}
		return ret;
#endif
	}
};

int n;
long long h;
int w;

// adding_data[i][]
//        i: place
//    first: time
//   second: b (height)
vector<vector<pair<int, int>>> adding_data;

int main()
{
	cin >> n >> w >> h;
	adding_data = vector<vector<pair<int, int>>>(w + 2);
	for (int i = 1; i <= n; ++i)
	{
		int a, b, x;
		cin >> a >> b >> x;
		adding_data[x].emplace_back(i, b);
		adding_data[x + a].emplace_back(i, -b);
	}

	BIT bit(n);

	int A_score = 0;
	for (int x = 1; x <= w; ++x)
	{
		for (auto data : adding_data[x])
		{
			int time = data.first;
			int add_height = data.second;
			bit.add(time, add_height);
		}
		A_score += bit.lowerBound(h) & 1;
	}

	int B_score = w - A_score;

	if (A_score > B_score)
		cout << "A" << endl;
	else if (A_score < B_score)
		cout << "B" << endl;
	else
		cout << "DRAW" << endl;
}

//char map[10000][10000];
//int bed[10000] = {};
//int main()
//{
//	memset(map, ' ', sizeof map);
//	cin >> n >> w >> h;
//	for (int i = 1; i <= n; ++i)
//	{
//		int a, b, x;
//		cin >> a >> b >> x;
//		for (int j = 0; j < b; ++j)
//		{
//			for (int k = 0; k < a; ++k)
//			{
//				if (i & 1)
//					map[bed[k + x]++][k + x] = 'a' + (char)(i - 1);
//				else
//					map[bed[k + x]++][k + x] = 'A' + (char)(i - 1);
//			}
//		}
//	}
//
//	int height = 0;
//	for (int i = 1; i <= n; ++i)
//	{
//		height = max(height, bed[i]);
//	}
//
//	for (int y = height; y >= 0; --y)
//	{
//		for (int x = 1; x <= w; ++x)
//		{
//			cout << map[y][x];
//		}
//		cout << endl;
//	}
//}
0