QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333453#1362. Bad Packingape_packAC ✓75ms394616kbC++232.0kb2024-02-19 22:19:252024-02-19 22:19:25

Judging History

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

  • [2024-02-19 22:19:25]
  • 评测
  • 测评结果:AC
  • 用时:75ms
  • 内存:394616kb
  • [2024-02-19 22:19:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = a; i >= b; i--)
#define F0Rd(i,a) for (int i = a; i >= 0; i--)
#define FORit(it,a) for (auto it = a.begin(); it != a.end(); it++)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define alla(arr, sz) arr, arr + sz

const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4*1e18;
const int inf = 1000000007;

namespace io {
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
    }
}

using namespace io;

#define DEBUG 0

void solve() {
    int n, c; cin >> n >> c;
    vi v(n); trav(x,v) cin >> x;
    sort(all(v));

    int dp[n+1][c+1]; // dp[i][j] = least capacity used considering first i indices and total capacity j
    // dp[0][0] = 0;
    FOR(i,1,n+1) dp[i][0] = 0;
    FOR(j,1,c+1) {
        if (j < v[0]) dp[1][j] = 0; 
        else dp[1][j] = v[0];
    }
    FOR(i,2,n+1) {
        FOR(j,1,c+1) {
            dp[i][j] = inf;
            if (j-dp[i-1][j] < v[i-1]) {
                dp[i][j] = dp[i-1][j];
            }
            if (j-v[i-1] >= 0)
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]] + v[i-1]);
            if (dp[i][j] == inf) dp[i][j] = 0;
        }
    }

    cout << dp[n][c];
}

int main() {
  #if DEBUG
  setIn("test.in");
  #else
  setIO();
  #endif

  int t;
  t= 1;  
  //cin >> t;
  while (t--) 
    solve();

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

4 10
9
6
5
7

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3532kb

input:

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

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 0ms
memory: 6472kb

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:

8240

result:

ok single line: '8240'

Test #4:

score: 0
Accepted
time: 11ms
memory: 80864kb

input:

824 23969
7843
4609
5289
4566
10073
5792
302
12573
8256
17988
3970
8311
23021
16579
1671
3350
14966
23085
328
22695
2475
10369
2503
9025
8836
18228
9352
9762
12449
14974
1952
18417
14199
6086
678
22895
6878
20552
13514
7997
2129
12092
14102
23180
1677
17904
7383
16171
20457
5006
9286
20293
3849
391
...

output:

22757

result:

ok single line: '22757'

Test #5:

score: 0
Accepted
time: 24ms
memory: 137332kb

input:

513 66631
43554
28519
65416
34524
28051
21903
63896
40807
20665
38551
30709
18688
32956
30597
45551
47965
64494
14611
46684
3015
12488
8416
14993
57326
54031
47541
9004
34387
14317
35659
39555
1328
66004
1497
57082
56017
58711
47790
54640
16805
5518
8151
7662
2380
41637
10090
6956
15887
50246
5888
3...

output:

62976

result:

ok single line: '62976'

Test #6:

score: 0
Accepted
time: 24ms
memory: 179260kb

input:

502 89394
76142
16744
46048
12838
48682
47728
55812
53405
34692
68091
87875
22869
61257
59828
72566
3635
64530
44377
83840
36190
8947
83094
22496
25364
51793
38877
35958
60617
65938
32033
16876
85674
24519
45412
32893
23237
3916
55695
49207
65897
32823
8194
55723
55609
85905
2360
60288
81255
3153
65...

output:

84288

result:

ok single line: '84288'

Test #7:

score: 0
Accepted
time: 75ms
memory: 394616kb

input:

1000 100000
59299
60064
91703
62516
5152
27099
97994
97251
24914
85927
42812
397
35646
95202
40753
35672
10380
31001
51581
412
53485
28943
9206
97101
34880
83927
56052
98640
90377
11447
89159
26181
8741
54488
75170
86212
52592
47943
18017
82173
55365
92379
9123
11948
13066
6664
69045
37004
43400
166...

output:

95200

result:

ok single line: '95200'