QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412084#3170. Lunchtime Name RecallohiostatescarletWA 1529ms3876kbC++171.6kb2024-05-16 03:54:402024-05-16 03:54:42

Judging History

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

  • [2024-05-16 03:54:42]
  • 评测
  • 测评结果:WA
  • 用时:1529ms
  • 内存:3876kb
  • [2024-05-16 03:54:40]
  • 提交

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 (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';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 1529ms
memory: 3588kb

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: 3812kb

input:

7 3
3
2
1

output:

4

result:

ok single line: '4'

Test #7:

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

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

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

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

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

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

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

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

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

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

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

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

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

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

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

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

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

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

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

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

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

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

score: -100
Wrong Answer
time: 0ms
memory: 3632kb

input:

3 5
1
1
1
1
1

output:

5

result:

wrong answer 1st lines differ - expected: '3', found: '5'