QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#394752 | #1362. Bad Packing | WisdomCasual# | WA | 35ms | 788936kb | C++20 | 1.1kb | 2024-04-20 19:08:27 | 2024-04-20 19:08:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ERROR ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); fileIO();
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
void fileIO(){
#ifndef ONLINE_JUDGE
freopen("io\\input.txt", "r", stdin);
freopen("io\\output.txt", "w", stdout);
#endif
}
const ll mod = 1e9 + 7, N = 1e3 + 5, M = 1e5 + 5;
ll n, c;
ll a[N];
bool taken[N];
ll dp[N][M];
ll solve(int idx, ll rem, int mnIdx){
if(idx == n){
return (rem < a[mnIdx]? c - rem : 1e12);
}
ll& ret = dp[idx][rem];
if(~ret)
return ret;
ret = solve(idx + 1, rem, mnIdx);
if(rem >= a[idx]){
ret = min(ret, solve(idx + 1, rem - a[idx], mnIdx + (idx == mnIdx)));
}
return ret;
}
void TestCase(){
memset(dp, -1, sizeof dp);
cin >> n >> c;
for(int i = 0; i < n; i++)
cin >> a[i];
sort(a, a+n);
cout << solve(0, c, 0) << '\n';
}
int main() {
ERROR;
int t = 1;
//cin >> t;
while(t--)
TestCase();
}
详细
Test #1:
score: 100
Accepted
time: 35ms
memory: 788936kb
input:
4 10 9 6 5 7
output:
5
result:
ok single line: '5'
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 788864kb
input:
10 25 1 1 1 2 2 3 3 4 2 1
output:
1000000000000
result:
wrong answer 1st lines differ - expected: '20', found: '1000000000000'