QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#232501#3170. Lunchtime Name Recall8BQube#TL 6854ms4612kbC++201.9kb2023-10-30 15:39:522023-10-30 15:39:52

Judging History

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

  • [2023-10-30 15:39:52]
  • 评测
  • 测评结果:TL
  • 用时:6854ms
  • 内存:4612kb
  • [2023-10-30 15:39:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()

set<vector<int>> dp, ndp, done;

void get_dp(int n, int a) {
    //cerr << "get_dp " << a << "\n";
    auto relax = [&](vector<int> mask) {
        /*cerr << "insert ";
        for (int p : mask)
            cerr << p << " ";
        cerr << endl;*/
        sort(ALL(mask));
        ndp.insert(mask);
    };

    for (auto cur : dp) {
        if (done.find(cur) != done.end()) continue;
        done.insert(cur);
        vector<int> nset;
        reverse(ALL(cur));
        auto _dfs = [&](auto dfs, int u, int one, int sum) {
            if (u == SZ(cur)) {
                if (one <= sum) 
                    relax(nset);
                return;
            }
            for (int i = max(0, one - (sum - cur[u])); i <= one && i <= cur[u]; ++i) {
                int osz = SZ(nset);
                if (i > 1)
                    nset.pb(i);
                if (cur[u] - i > 1)
                    nset.pb(cur[u] - i);
                dfs(dfs, u + 1, one - i, sum - cur[u]);
                nset.resize(osz);
            }
        };
        _dfs(_dfs, 0, a, n);
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    dp.insert({n});
    while (m--) {
        int a;
        cin >> a;
        ndp.clear();
        get_dp(n, min(a, n - a));
        dp.swap(ndp);
        if (dp.find({}) != dp.end()) break;
    }
    int ans = 0;
    for (auto p : dp) {
        int sum = 0;
        for (int q : p)
            sum += q;
        ans = max(ans, n - sum);
    }
    for (auto p : done) {
        int sum = 0;
        for (int q : p)
            sum += q;
        ans = max(ans, n - sum);
    }
    cout << ans << "\n";
}

詳細信息

Test #1:

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

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

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

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

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

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

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

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

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

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

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

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

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

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

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

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

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

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

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

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

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

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

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

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

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

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

input:

3 5
1
1
1
1
1

output:

3

result:

ok single line: '3'

Test #21:

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

input:

5 6
2
2
2
2
2
2

output:

5

result:

ok single line: '5'

Test #22:

score: 0
Accepted
time: 6035ms
memory: 4560kb

input:

30 5
15
15
15
15
13

output:

28

result:

ok single line: '28'

Test #23:

score: 0
Accepted
time: 6854ms
memory: 4268kb

input:

30 10
15
15
15
15
15
1
1
1
1
1

output:

30

result:

ok single line: '30'

Test #24:

score: 0
Accepted
time: 2790ms
memory: 4612kb

input:

30 10
15
10
10
10
10
1
1
1
1
1

output:

28

result:

ok single line: '28'

Test #25:

score: 0
Accepted
time: 2533ms
memory: 4508kb

input:

30 7
9
9
9
9
9
9
2

output:

28

result:

ok single line: '28'

Test #26:

score: 0
Accepted
time: 5997ms
memory: 4012kb

input:

30 10
2
2
2
3
3
3
6
11
14
15

output:

28

result:

ok single line: '28'

Test #27:

score: 0
Accepted
time: 2101ms
memory: 4316kb

input:

30 10
1
2
3
4
5
6
7
8
9
10

output:

30

result:

ok single line: '30'

Test #28:

score: -100
Time Limit Exceeded

input:

30 10
11
12
13
14
15
16
17
18
19
20

output:


result: