QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59714#1362. Bad Packingabdelrahman001#WA 81ms396544kbC++201.3kb2022-10-31 21:45:002022-10-31 21:45:01

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 21:45:01]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:396544kb
  • [2022-10-31 21:45:00]
  • 提交

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 && j >= 0;i--, j--) {
		if(a[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: 0
Wrong Answer
time: 81ms
memory: 396544kb

input:

4 10
9
6
5
7

output:

6

result:

wrong answer 1st lines differ - expected: '5', found: '6'