QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106812#3170. Lunchtime Name Recallskittles1412ML 955ms157940kbC++172.5kb2023-05-19 12:39:242023-05-19 12:39:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-19 12:39:26]
  • 评测
  • 测评结果:ML
  • 用时:955ms
  • 内存:157940kb
  • [2023-05-19 12:39:24]
  • 提交

answer

#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                              \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
    dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr   \
    if (false) \
    cerr
#endif

using u8 = uint8_t;
using u64 = uint64_t;

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

struct Hasher {
    u64 x;

    Hasher& operator()(u64 v) {
        x ^= x >> 29;
        x ^= x << 37;
        x ^= x >> 17;
        x ^= x << 23;
        x ^= v;
        return *this;
    }
};

constexpr int maxn = 15, maxm = 35;

int n, m, arr[maxn];
u64 hashes[maxm];
__gnu_pbds::gp_hash_table<u64, int> memo[maxn][maxm];

template <typename T>
u64 hashv(const T& arr) {
    u64 ans = 0;
    for (auto& a : arr) {
        ans += hashes[a];
    }
    return ans;
}

int dp(int ind, int left, basic_string<u8> gen, basic_string<u8> comps) {
    if (ind == n) {
        int ans = int(count(begin(comps), end(comps), 1));
        if (ans == m) {
            // cout << ans << endl;
            // exit(0);
        }
        return ans;
    } else if (!sz(comps)) {
        if (left) {
            return 0;
        }
        return dp(ind + 1, arr[ind + 1], {}, gen);
    }
    u64 key = Hasher()(hashv(gen))(hashv(comps)).x;
    auto it = memo[ind][left].find(key);
    if (it != memo[ind][left].end()) {
        return it->second;
    }
    int ans = 0, cx = comps.back();
    comps.pop_back();
    for (int i = 0; i <= min(cx, left); i++) {
        auto ngen = gen;
        auto push = [&](int u) -> void {
            if (u) {
                ngen.push_back(u);
            }
        };
        push(i);
        push(cx - i);
        ans = max(ans, dp(ind, left - i, ngen, comps));
    }
    return memo[ind][left][key] = ans;
}

void solve() {
    mt19937_64 cowng(chrono::steady_clock::now().time_since_epoch().count());
    for (auto& a : hashes) {
        a = cowng();
    }
    cin >> m >> n;
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    // shuffle(arr, arr + n, cowng);
    cout << dp(0, arr[0], {}, {u8(m)}) << endl;
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}

詳細信息

Test #1:

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

input:

4 2
2
2

output:

4

result:

ok single line: '4'

Test #2:

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

input:

16 3
6
8
8

output:

5

result:

ok single line: '5'

Test #3:

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

input:

5 2
2
2

output:

3

result:

ok single line: '3'

Test #4:

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

input:

16 3
8
8
8

output:

6

result:

ok single line: '6'

Test #5:

score: 0
Accepted
time: 5ms
memory: 4392kb

input:

20 7
1
1
1
1
6
8
8

output:

11

result:

ok single line: '11'

Test #6:

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

input:

7 3
3
2
1

output:

4

result:

ok single line: '4'

Test #7:

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

input:

9 4
1
1
3
3

output:

5

result:

ok single line: '5'

Test #8:

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

input:

10 3
4
4
3

output:

6

result:

ok single line: '6'

Test #9:

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

input:

10 3
4
4
5

output:

6

result:

ok single line: '6'

Test #10:

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

input:

10 3
4
4
4

output:

7

result:

ok single line: '7'

Test #11:

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

input:

12 3
6
6
6

output:

6

result:

ok single line: '6'

Test #12:

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

input:

10 5
2
2
2
2
2

output:

7

result:

ok single line: '7'

Test #13:

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

input:

10 6
2
2
2
2
2
2

output:

10

result:

ok single line: '10'

Test #14:

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

input:

10 2
3
3

output:

2

result:

ok single line: '2'

Test #15:

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

input:

10 6
8
5
2
8
8
1

output:

10

result:

ok single line: '10'

Test #16:

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

input:

7 4
5
5
1
2

output:

5

result:

ok single line: '5'

Test #17:

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

input:

2 1
1

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
1

output:

1

result:

ok single line: '1'

Test #19:

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

input:

30 1
15

output:

0

result:

ok single line: '0'

Test #20:

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

input:

3 5
1
1
1
1
1

output:

3

result:

ok single line: '3'

Test #21:

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

input:

5 6
2
2
2
2
2
2

output:

5

result:

ok single line: '5'

Test #22:

score: 0
Accepted
time: 387ms
memory: 82880kb

input:

30 5
15
15
15
15
13

output:

28

result:

ok single line: '28'

Test #23:

score: 0
Accepted
time: 594ms
memory: 121780kb

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: 444ms
memory: 108012kb

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: 646ms
memory: 130180kb

input:

30 7
9
9
9
9
9
9
2

output:

28

result:

ok single line: '28'

Test #26:

score: 0
Accepted
time: 921ms
memory: 157800kb

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: 955ms
memory: 157940kb

input:

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

output:

30

result:

ok single line: '30'

Test #28:

score: -100
Memory Limit Exceeded

input:

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

output:


result: