QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59737#1362. Bad Packingabdelrahman001#WA 75ms396132kbC++201.3kb2022-10-31 22:28:232022-10-31 22:28:25

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-31 22:28:25]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:396132kb
  • [2022-10-31 22:28:23]
  • 提交

answer

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int N = 1e5 + 5;
const int M = 1e3 + 5;
int n, c, memo[N][M], a[N];
int solve(int i, int rem) {
	if(rem < 0)
		return 0;
	if(rem == 0)
		return 1;
	if(i == n)
		return 0;
	int &ans = memo[rem][i];
	if(~ans)
		return ans;
	return ans = max(solve(i + 1, rem - a[i]), solve(i + 1, rem));
}
vector<int> v;
void print(int i, int rem) {
	if(i == n)
		return;
	if(solve(i + 1, rem - a[i])) {
		v.push_back(i);
		print(i + 1, rem - a[i]);
	} else
		print(i + 1, rem);
}
bool check(int x) {
	if(!solve(0, x))
		return false;
	v.clear();
	print(0, x);
	int sz = v.size();
	for(int i = n - 1, j = sz - 1;i >= 0;i--, j--) {
		if(j >= 0 && i == v[j])
			continue;
		if(a[i] + x <= c)
			return false;
	}
	return true;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> c;
    for(int i = 0;i < n;i++)
		cin >> a[i];
	sort(a, a + n, greater<>());
	memset(memo, -1, sizeof memo);
	for(int i = 1;i <= c;i++) {
		if(check(i))
			return cout << i, 0;
	}
    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 52ms
memory: 396112kb

input:

4 10
9
6
5
7

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 63ms
memory: 396052kb

input:

10 25
1
1
1
2
2
3
3
4
2
1

output:

20

result:

ok single line: '20'

Test #3:

score: -100
Wrong Answer
time: 75ms
memory: 396132kb

input:

77 9383
203
6771
1608
6509
3213
3597
3416
3011
2241
740
5564
3113
360
3229
5819
5589
5210
4519
5270
6067
10
9147
4171
920
8325
263
8097
3400
9214
3927
8804
4805
8388
1211
523
3799
1124
8573
7491
5527
8026
8529
2510
6430
6171
1405
4820
7662
2449
7264
1419
6320
7272
3327
7042
1517
8326
881
2199
4664
9...

output:

9100

result:

wrong answer 1st lines differ - expected: '8240', found: '9100'