QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#394752#1362. Bad PackingWisdomCasual#WA 35ms788936kbC++201.1kb2024-04-20 19:08:272024-04-20 19:08:27

Judging History

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

  • [2024-04-20 19:08:27]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:788936kb
  • [2024-04-20 19:08:27]
  • 提交

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'