QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140046#3170. Lunchtime Name RecallKirill22#TL 7ms3652kbC++231.6kb2023-08-15 00:35:572023-08-15 00:35:58

Judging History

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

  • [2023-08-15 00:35:58]
  • 评测
  • 测评结果:TL
  • 用时:7ms
  • 内存:3652kb
  • [2023-08-15 00:35:57]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

long double start = clock();

int n, m, a[10], ans = 0, t = 0;
set<vector<int>> used[11];

void CheckTime() {
    if (t++ == 100) {
        t = 0;
        if ((long double) (clock() - start) / CLOCKS_PER_SEC > 6) {
            cout << ans;
            exit(0);
        }
    }
}

void dfs(int j, vector<int> c) {
	CheckTime();
    sort(c.begin(), c.end());
    if (j == m) {
        int cnt = 0;
        for (auto x : c) {
            cnt += x == 1;
        }
        if (ans < cnt) {
            ans = cnt;
        }
        return;
    }
    if (used[j].find(c) != used[j].end()) {
        return;
    }
    used[j].insert(c);
    vector<int> tmp;
    function<void(int, int)> gen = [&] (int i, int x) {
        if (i == (int) c.size()) {
            if (!x) {
                dfs(j + 1, tmp);
            }
            return;
        }
        for (int v = 0; v <= min(x, c[i]); v++) {
            if (v) {
                tmp.push_back(v);
            }
            if (v != c[i]) {
                tmp.push_back(c[i] - v);
            }
            gen(i + 1, x - v);
            if (v) {
                tmp.pop_back();
            }
            if (v != c[i]) {
                tmp.pop_back();
            }
        }
    };
    gen(0, a[j]);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        a[i] = min(a[i], n - a[i]);
    }
    dfs(0, {n});
    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3524kb

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

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

input:

20 7
1
1
1
1
6
8
8

output:

11

result:

ok single line: '11'

Test #6:

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

input:

7 3
3
2
1

output:

4

result:

ok single line: '4'

Test #7:

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

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

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

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

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

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

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

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

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

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

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

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

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

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

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

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

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

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

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

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

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

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

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

input:

3 5
1
1
1
1
1

output:

3

result:

ok single line: '3'

Test #21:

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

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: