QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422484#8005. Crossing the BorderzhaohaikunTL 935ms339404kbC++202.5kb2024-05-27 14:59:362024-05-27 14:59:36

Judging History

你现在查看的是最新测评结果

  • [2024-05-27 14:59:36]
  • 评测
  • 测评结果:TL
  • 用时:935ms
  • 内存:339404kb
  • [2024-05-27 14:59:36]
  • 提交

answer

// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "\033[32m[" << __LINE__ << "]\033[0m "
#define SZ(x) ((int) x.size() - 1)
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> T& chkmax(T& x, T y) {return x = max(x, y);}
template <typename T> T& chkmin(T& x, T y) {return x = min(x, y);}
template <typename T> T& read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x *= f;
}
const int N = (1 << 22) | (1 << 10), MOD = 998244353;
const ll INF = 1e18;
int n, w, s[N];
pair <int, int> a[25];
pair <ll, int> f[N];
// int lg(int x) {return 31 ^ __builtin_clz(x);}
pair <ll, int> operator * (pair <ll, int> x, pair <ll, int> y) {
	return make_pair(x.first + y.first, (ll) x.second * y.second % MOD);
}
pair <ll, int> operator + (pair <ll, int> x, pair <ll, int> y) {
	if (x.first ^ y.first) return min(x, y);
	return make_pair(x.first, (x.second + y.second) % MOD);
}
pair <ll, int>& operator += (pair <ll, int>& x, pair <ll, int> y) {
	return x = x + y;
}
vector <int> g[N];
signed main() {
	read(n), read(w);
	F(i, 1, n) read(a[i].second), read(a[i].first);
	sort(a + 1, a + n + 1, greater ());
	f[0] = make_pair(0, 1);
	int full = (1 << n) - 1;
	F(i, 1, full) {
		int t = __builtin_ctz(i);
		// debug << i << " " << t << " " << a[t + 1].first << endl;
		s[i] = min(w + 1, s[i ^ (1 << t)] + a[t + 1].second);
		f[i] = make_pair(INF, 0);
		if (s[i] <= w) {
			// debug << i << endl;
			for (int j = i; ; j = (j + 1) | i) {
				if (__builtin_ctz(j) == t) {
					// debug << j << " " << i << endl;
					g[j].push_back(i);
				}
				if (j == full) break;
			}
		}
	}
	F(i, 1, full) {
		int t = __builtin_ctz(i);
		for (int l: g[i]) {
			// if ((i ^ b) == 3) {
			// 	debug << "! " << s[i ^ b] << " " << w << endl;
			// }
			// if (s[i ^ b] <= w) {
				// debug << (i ^ a) << endl;
				f[i] += make_pair(::a[t + 1].first + f[i ^ l].first, f[i ^ l].second);
				// if (a[t + 1].first + f[a].first < f[i].first) {
				// 	f[i].first = 
				// }
			// }
			// if (!b) break;
		}
		// debug << f[i].first << " " << f[i].second << " " << s[i] << endl;
	}
	cout << f[full].first << ' ' << f[full].second;
	return 0;
}
/* why?
*/

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 7740kb

input:

5 5
3 5
1 4
2 3
2 2
2 1

output:

9 4

result:

ok 2 number(s): "9 4"

Test #2:

score: 0
Accepted
time: 935ms
memory: 339404kb

input:

18 10000000
956231 904623
1692946 1796774
1081323 1170319
3218792 2542661
3183376 3037270
1869132 1442561
35436 35018
1564635 1939950
1847344 2006043
755870 899310
1671882 2057413
1369264 1338951
3132483 3504034
2056224 1825640
1840949 1562071
1514040 1405352
2300821 2421801
2466540 3004920

output:

9391997 70

result:

ok 2 number(s): "9391997 70"

Test #3:

score: -100
Time Limit Exceeded

input:

20 10000000
1289384 1416015
1692778 1966748
1747794 1708650
2885387 2925290
2516650 2410838
2202363 2092667
368691 407497
1897764 1902790
180541 224758
1089173 1075924
2005212 1743637
702568 566295
465783 369143
2722863 2902398
174068 150211
513930 519657
1634023 1313239
1133070 1040937
961394 11066...

output:


result: