QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412079#3170. Lunchtime Name RecallohiostatescarletWA 2709ms3672kbC++171.6kb2024-05-16 03:32:182024-05-16 03:32:18

Judging History

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

  • [2024-05-16 03:32:18]
  • 评测
  • 测评结果:WA
  • 用时:2709ms
  • 内存:3672kb
  • [2024-05-16 03:32:18]
  • 提交

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 < n; 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 < n; j++) {
                    if ((curr>>j)&1) {
                        nums[j]--;
                    }
                }
            }
            mask &= ~minBits;
            nex &= mask;
            solve(nex, mask, distinct + (minV == 1), remain-minV);
            for (int j = 0; j < n; 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: 3640kb

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

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

input:

20 7
1
1
1
1
6
8
8

output:

11

result:

ok single line: '11'

Test #6:

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

input:

7 3
3
2
1

output:

3

result:

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