QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412085#3170. Lunchtime Name RecallohiostatescarletTL 1582ms3684kbC++171.6kb2024-05-16 03:55:432024-05-16 03:55:44

Judging History

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

  • [2024-05-16 03:55:44]
  • 评测
  • 测评结果:TL
  • 用时:1582ms
  • 内存:3684kb
  • [2024-05-16 03:55:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define L long long
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> nums(m,0);
    for (int i = 0; i < m; i++) {
        int v;
        cin >> v;
        nums[i] = min(v, n - v);
    }
    int best = 0;
    function<void(int,int,int,int)> solve = [&](int curr, int mask, int distinct, int remain) {
        if (remain < 0) return;
        if (curr) {
            int minV = 30;
            int minBits = 0;
            for (int j = 0; j < m; j++) {
                if ((curr>>j)&1) {
                    if (nums[j] < minV) {
                        minV = nums[j];
                        minBits = 1<<j;
                    } else if (nums[j] == minV) {
                        minBits |= 1<<j;
                    }
                }
            }
            int nex = (curr-1)&mask;
            for (int i = 0; i < minV; i++) {
                solve(nex, mask, distinct + (i == 1), remain-i);
                for (int j = 0; j < m; j++) {
                    if ((curr>>j)&1) {
                        nums[j]--;
                    }
                }
            }
            mask &= ~minBits;
            solve((curr|((1<<(31-__builtin_clz(minBits)))-1))&mask, mask, distinct + (minV == 1), remain-minV);
            for (int j = 0; j < m; j++) {
                if ((curr>>j)&1) {
                    nums[j] += minV;
                }
            }
        } else if (!mask) {
            best = max(best, distinct + (remain == 1));
        }
    };
    int v = (1<<m)-1;
    solve(v,v,0,n);
    cout << best << '\n';
}

详细

Test #1:

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

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 1582ms
memory: 3484kb

input:

20 7
1
1
1
1
6
8
8

output:

11

result:

ok single line: '11'

Test #6:

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

input:

7 3
3
2
1

output:

4

result:

ok single line: '4'

Test #7:

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

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

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

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

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

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

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

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

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

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

score: 0
Accepted
time: 3ms
memory: 3524kb

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

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

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

score: 0
Accepted
time: 7ms
memory: 3488kb

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

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

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

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

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

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

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

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

input:

3 5
1
1
1
1
1

output:

3

result:

ok single line: '3'

Test #21:

score: 0
Accepted
time: 6ms
memory: 3488kb

input:

5 6
2
2
2
2
2
2

output:

5

result:

ok single line: '5'

Test #22:

score: -100
Time Limit Exceeded

input:

30 5
15
15
15
15
13

output:


result: