結果

問題 No.54 Happy Hallowe'en
ユーザー pekempeypekempey
提出日時 2016-04-01 19:43:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,388 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 175,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 07:10:22
合計ジャッジ時間 2,345 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 7 ms
6,944 KB
testcase_07 AC 9 ms
6,940 KB
testcase_08 AC 10 ms
6,940 KB
testcase_09 AC 13 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 WA -
testcase_12 AC 11 ms
6,944 KB
testcase_13 AC 12 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,944 KB
testcase_17 WA -
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; }
	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 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 shiftSplit(int l, int r, int k) {
		Bitset result(n);
		int d = k / 64, e = k % 64;
		while (l < r && l % 64 != 0) result.set(l + k, get(l)), l++;
		while (l < r && r % 64 != 0) r--, result.set(r + k, get(r));
		for (int i = min(r / 64 - 1, m - l / 64 - 1); i >= l / 64; i--) {
			result.dat[i + l / 64] = dat[i - d];
			result.dat[i + l / 64 + 1] |= (dat[i] >> 63 - e) >> 1;
			result.dat[i + l / 64] <<= e;
		}
		return result;
	}
	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;
	}
	Bitset &operator<<=(int k) {
		int d = k / 64, 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;
	}
	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.shiftSplit(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