QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59695#1362. Bad PackingSa3tElSefr#WA 52ms15064kbC++201.4kb2022-10-31 20:03:372022-10-31 20:03:38

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 20:03:38]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:15064kb
  • [2022-10-31 20:03:37]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

#define ll long long
#define ld  double
using namespace std;

const int N = 1e5 + 5, M = 1005, lg = 19, mod = 998244353;


bool dp[M][N], mark[M][N];

int n, cap, a[M];


bool solve(int idx, int rem) {
    if(idx == n) return rem == 0;
    if(mark[idx][rem]) return dp[idx][rem];
    mark[idx][rem] = 1;

    bool op1 = solve(idx + 1, rem);
    bool op2 = 0;
    if(a[idx] >= rem) op2 = solve(idx + 1, rem - a[idx]);

    return dp[idx][rem] = (op1 | op2);
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    cin >> n >> cap;
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll total = accumulate(a, a + n, 0LL);

    if(total <= cap) {
        cout << total;
        return 0;
    }

    ll mn = total, pref = 0;
    int z = 0;
    for(int i = 0; i < n; i++) {
        if(pref <= cap) {
            int from = a[i] - 1, to = 0;
            from = min(0LL + from, cap - pref);
            for(int j = from; j >= z; j--) {
                if(cap - pref - j < 0) break;
                if(solve(i + 1, cap - pref - j)) {
                    mn = min(mn, 0LL + cap - j);
                    z = j;
                    break;
                }
            }
        }
        pref += a[i];
    }
    cout << mn;






    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5580kb

input:

4 10
9
6
5
7

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3496kb

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: 52ms
memory: 15064kb

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:

7982

result:

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