結果

問題 No.54 Happy Hallowe'en
ユーザー pekempeypekempey
提出日時 2016-04-01 20:19:00
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,935 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 174,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 16:43:43
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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; }
	Bitset split(int l, int r) {
		Bitset result(n);
		while (l < r && l % 64 != 0) result.set(l, get(l)), l++;
		while (l < r && r % 64 != 0) r--, result.set(r, get(r));
		while (l < r) result.dat[l / 64] = dat[l / 64], l += 64;
		return result;
	}
	Bitset &operator<<=(int k) {
		int l = max(k / 64, 1), d = k / 64, e = k % 64;
		for (int i = m - 1; i >= l; i--) dat[i] = (dat[i - d] << e) | (dat[i - d - 1] >> 63 - e >> 1);
		if (d == 0) dat[0] <<= e;
		for (int i = 0; i < d; i++) dat[i] = 0;
		return *this;
	}
	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, bool v) { if (v) dat[k / 64] |= 1ull << (k % 64); else dat[k / 64] &= ~(1ull << (k % 64)); }
	Bitset operator&(const Bitset &rhs) const { return Bitset(*this) &= rhs; }
	Bitset operator|(const Bitset &rhs) const { return Bitset(*this) |= rhs; }
	Bitset operator<<(int k) { return Bitset(*this) <<= k; }
	Bitset &operator&=(const Bitset &rhs) { for (int i = 0; i < m; i++) dat[i] &= rhs.dat[i]; return *this; }
	Bitset &operator|=(const Bitset &rhs) { for (int i = 0; i < m; i++) dat[i] |= rhs.dat[i]; return *this; }
	bool operator[](int k) { return get(k); }
};

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, 1);

	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[i]) ans = i;
	cout << ans << endl;

	return 0;
}
0