QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412090#3170. Lunchtime Name RecallohiostatescarletWA 2ms3872kbC++172.2kb2024-05-16 04:34:262024-05-16 04:34:26

Judging History

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

  • [2024-05-16 04:34:26]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3872kb
  • [2024-05-16 04:34:26]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define L long long
typedef array<int, 30> A;
void partitions(A&curr, vector<int> out, int i, int split, set<A>&used, set<A>&nex, int last) {
    if (i == 30 || !curr[i]) {
        if (split) return;
        sort(out.begin(), out.end());
        A newA = {0};
        for (int j = 0; j < out.size(); j++) {
            newA[j] = out[j];
        }
        if (!used.count(newA)) {
            // for (int j = 0; j < 30 && curr[j]; j++) cout << curr[j] << " ";
            // cout << "=> ";
            // for (int j = 0; j < 30 && newA[j]; j++) cout << newA[j] << " ";
            // cout << "\n";
            used.insert(newA);
            nex.insert(newA);
        }
    } else {
        int maxSplit = min(split, curr[i]);
        int minSplit = (i > 0 && curr[i] == curr[i-1]) ? last : 0;
        for (int j = minSplit; j <= maxSplit; j++) {
            if (j!=0 && j != curr[i]) {
                out.push_back(j);
                out.push_back(curr[i]-j);
                partitions(curr, out, i+1, split-j, used, nex, j);
                out.pop_back();
                out.pop_back();
            } else {
                out.push_back(curr[i]);
                partitions(curr, out, i+1, split-j, used, nex, j);
                out.pop_back();
            }
        }
    }
}

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);
    }
    sort(nums.begin(),nums.end());
    A start = {0};
    start[0] = n;
    set<A> used;
    set<A> curr;
    curr.insert(start);
    used.insert(start);
    for (int v : nums) {
        set<A> nex;
        for (auto a = curr.begin(); a != curr.end(); a++) {
            A av = *a;
            partitions(av, vector<int>(), 0, v, used, nex, 0);
        }
        swap(nex, curr);
    }
    int res = 0;
    for (auto a = curr.begin(); a != curr.end(); a++) {
        int o = 0;
        for (int i = 0; i < 30 && (*a)[i]; i++) {
            if ((*a)[i] == 1) {
                o++;
            }
        }
        res = max(res, o);
    }
    cout << res << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3688kb

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

input:

7 3
3
2
1

output:

4

result:

ok single line: '4'

Test #7:

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

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

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

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

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

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

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

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

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

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

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

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

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

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

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

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

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

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

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

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

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

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

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

input:

3 5
1
1
1
1
1

output:

0

result:

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