結果

問題 No.54 Happy Hallowe'en
ユーザー pekempeypekempey
提出日時 2016-04-01 19:11:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,820 bytes
コンパイル時間 1,744 ms
コンパイル使用メモリ 175,140 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:43:40
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 13 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 18 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 18 ms
5,376 KB
testcase_13 AC 17 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Bitset {
	vector<unsigned long long> dat;
	int n, m;
	Bitset(int n) : n(n), dat((n + 63) / 64 + 1) { m = dat.size() - 1; }
	int count() {
		int result = 0;
		for (int i = 0; i < m; i++) result += __builtin_popcountll(dat[i]);
		return result;
	}
	bool get(int k) {
		return dat[k / 64] >> (k % 64) & 1ull;
	}
	void set(int k) {
		dat[k / 64] |= 1ull << (k % 64);
	}
	void set(int l, int r) {
		while (l < r && l % 64 != 0) set(l), l++;
		while (l < r && r % 64 != 0) r--, set(r);
		while (l < r) dat[l / 64] = ULLONG_MAX, l += 64;
	}
	Bitset split(int l, int r) {
		Bitset result(n);
		while (l < r && l % 64 != 0) {
			if (get(l)) result.set(l);
			l++;
		}
		while (l < r && r % 64 != 0) {
			r--;
			if (get(r)) result.set(r);
		}
		while (l < r) result.dat[l / 64] = dat[l / 64], l += 64;
		return result;
	}
	Bitset operator<<(int k) {
		Bitset result(*this);
		result <<= k;
		return result;
	}
	Bitset &operator|=(const Bitset &rhs) {
		for (int i = 0; i < m; i++) {
			dat[i] |= rhs.dat[i];
		}
		return *this;
	}
	Bitset &operator<<=(int k) {
		int d = k / 64;
		int e = k % 64;
		for (int i = m - 1; i >= d; i--) {
			dat[i] = dat[i - d];
			dat[i + 1] |= (dat[i] >> 63 - e) >> 1;
			dat[i] <<= e;
		}
		for (int i = 0; i < d; i++) dat[i] = 0;
		return *this;
	}
};

int main() {
	int n;
	cin >> n;
	vector<int> v(n), t(n);
	vector<tuple<int, int, int>> vt(n);
	for (int i = 0; i < n; i++) cin >> v[i] >> t[i], vt[i] = make_tuple(v[i] + t[i], v[i], t[i]);
	sort(vt.begin(), vt.end());
	for (int i = 0; i < n; i++) tie(ignore, v[i], t[i]) = vt[i];

	Bitset dp(20202);
	dp.set(0);

	for (int i = 0; i < n; i++) {
		dp |= dp.split(0, t[i]) << v[i];
	}

	int ans = 0;
	for (int i = 0; i < 20202; i++) if (dp.get(i)) ans = i;
	cout << ans << endl;

	return 0;
}
0