QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59759#1362. Bad Packingabdelrahman001RE 92ms396176kbC++201.2kb2022-11-01 02:04:042022-11-01 02:04:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-01 02:04:05]
  • 评测
  • 测评结果:RE
  • 用时:92ms
  • 内存:396176kb
  • [2022-11-01 02:04:04]
  • 提交

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, a[N], memo[M][N];
int pref[N];
int solve(int i, int rem) {
    if(rem < 0)
        return 0;
    if(rem == 0)
        return 1;
    if(i == n + 1)
        return 0;
    int &ans = memo[rem][i];
    if(ans != -1)
        return ans;
    return ans = max(solve(i + 1, rem - a[i]), solve(i + 1, rem));
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> c;
    for(int i = 1;i <= n;i++)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    for(int i = 1;i <= n;i++)
        pref[i] = pref[i - 1] + a[i];
    memset(memo, -1, sizeof memo);
    for(int i = 1;i <= c;i++) {
        int rem = c - i;
        int j = upper_bound(a + 1, a + n + 1, rem) - a;
        int sum = pref[j - 1];
        if(sum > i)
            continue;
        if(solve(j, i - sum))
            return cout << i, 0;
    }
    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 92ms
memory: 396176kb

input:

4 10
9
6
5
7

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 69ms
memory: 396116kb

input:

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

output:

20

result:

ok single line: '20'

Test #3:

score: -100
Runtime Error

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:


result: