QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106811 | #3170. Lunchtime Name Recall | skittles1412 | ML | 946ms | 248988kb | C++17 | 2.5kb | 2023-05-19 12:35:06 | 2023-05-19 12:35:07 |
Judging History
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];
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()(left)(hashv(gen))(hashv(comps)).x;
auto it = memo[ind].find(key);
if (it != memo[ind].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][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: 2ms
memory: 3508kb
input:
4 2 2 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3596kb
input:
16 3 6 8 8
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3456kb
input:
5 2 2 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
16 3 8 8 8
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 5ms
memory: 4476kb
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: 3584kb
input:
7 3 3 2 1
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3520kb
input:
9 4 1 1 3 3
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3428kb
input:
10 3 4 4 3
output:
6
result:
ok single line: '6'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
10 3 4 4 5
output:
6
result:
ok single line: '6'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
10 3 4 4 4
output:
7
result:
ok single line: '7'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3512kb
input:
12 3 6 6 6
output:
6
result:
ok single line: '6'
Test #12:
score: 0
Accepted
time: 2ms
memory: 3472kb
input:
10 5 2 2 2 2 2
output:
7
result:
ok single line: '7'
Test #13:
score: 0
Accepted
time: 3ms
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: 3480kb
input:
10 2 3 3
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3608kb
input:
10 6 8 5 2 8 8 1
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
7 4 5 5 1 2
output:
5
result:
ok single line: '5'
Test #17:
score: 0
Accepted
time: 2ms
memory: 3472kb
input:
2 1 1
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
3 1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 2ms
memory: 3508kb
input:
30 1 15
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3504kb
input:
3 5 1 1 1 1 1
output:
3
result:
ok single line: '3'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3492kb
input:
5 6 2 2 2 2 2 2
output:
5
result:
ok single line: '5'
Test #22:
score: 0
Accepted
time: 415ms
memory: 101532kb
input:
30 5 15 15 15 15 13
output:
28
result:
ok single line: '28'
Test #23:
score: 0
Accepted
time: 573ms
memory: 112840kb
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: 459ms
memory: 113928kb
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: 652ms
memory: 163108kb
input:
30 7 9 9 9 9 9 9 2
output:
28
result:
ok single line: '28'
Test #26:
score: 0
Accepted
time: 946ms
memory: 248988kb
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: 891ms
memory: 175432kb
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