QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376843 | #3170. Lunchtime Name Recall | ckiseki# | TL | 1619ms | 4820kb | C++20 | 2.7kb | 2024-04-04 17:32:30 | 2024-04-04 17:32:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << "\n";
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
#include <experimental/iterator>
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> a(m);
for (int i = 0; i < m; i++)
cin >> a[i];
set<long long> dp[11];
vector<long long> wei(n + 1, 1);
wei[0] = n;
for (int i = 1; i <= n; i++) {
wei[i] = n / i + 1;
}
vector<long long> prewei(n + 1, 1);
for (int i = 1; i <= n; i++)
prewei[i] = prewei[i - 1] * wei[i - 1];
orange(all(wei));
orange(all(prewei));
dp[0].insert(prewei[n]);
auto decode = [&](long long enc_v) {
vector<int> v;
for (int j = 1; j <= n; j++) {
int c = enc_v / prewei[j] % wei[j];
for (int t = 0; t < c; t++)
v.push_back(j);
}
return v;
};
// auto v = decode(prewei[n]);
// orange(all(v));
// return 0;
for (int i = 0; i < m; i++) {
for (auto enc_v : dp[i]) {
auto v = decode(enc_v);
vector<set<long long>> cur(a[i] + 1);
cur[0].insert(0);
// vector<size_t> sizes;
for (size_t j = 0; j < v.size(); j++) {
vector<set<long long>> nxt(a[i] + 1);
for (int y = 0; y <= v[j]; y++) {
for (int x = 0; x + y <= a[i]; x++) {
for (auto u : cur[x]) {
if (y)
u += prewei[y];
if (v[j] - y)
u += prewei[v[j] - y];
// if (y)
// u.push_back(y);
// if (v[j] - y)
// u.push_back(v[j] - y);
// sort(all(u));
nxt[x + y].insert(u);
}
}
}
cur = nxt;
// size_t s = 0;
// for (int x = 0; x <= a[i]; x++)
// s += cur[x].size();
// sizes.push_back(s);
}
for (auto u : cur[a[i]]) {
dp[i + 1].insert(u);
}
}
debug(dp[i].size());
}
debug(dp[m].size());
int ans = 0;
for (auto enc_v : dp[m]) {
auto v = decode(enc_v);
int cnt = 0;
for (int x : v)
if (x == 1)
++cnt;
ans = max(ans, cnt);
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3772kb
input:
4 2 2 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
16 3 6 8 8
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
5 2 2 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
16 3 8 8 8
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 4ms
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: 1ms
memory: 3556kb
input:
7 3 3 2 1
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3600kb
input:
9 4 1 1 3 3
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
10 3 4 4 3
output:
6
result:
ok single line: '6'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
10 3 4 4 5
output:
6
result:
ok single line: '6'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
10 3 4 4 4
output:
7
result:
ok single line: '7'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
12 3 6 6 6
output:
6
result:
ok single line: '6'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
10 5 2 2 2 2 2
output:
7
result:
ok single line: '7'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
10 6 2 2 2 2 2 2
output:
10
result:
ok single line: '10'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
10 2 3 3
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
10 6 8 5 2 8 8 1
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
7 4 5 5 1 2
output:
5
result:
ok single line: '5'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3492kb
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: 3844kb
input:
30 1 15
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
3 5 1 1 1 1 1
output:
3
result:
ok single line: '3'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
5 6 2 2 2 2 2 2
output:
5
result:
ok single line: '5'
Test #22:
score: 0
Accepted
time: 606ms
memory: 4172kb
input:
30 5 15 15 15 15 13
output:
28
result:
ok single line: '28'
Test #23:
score: 0
Accepted
time: 759ms
memory: 4580kb
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: 604ms
memory: 4820kb
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: 755ms
memory: 4516kb
input:
30 7 9 9 9 9 9 9 2
output:
28
result:
ok single line: '28'
Test #26:
score: 0
Accepted
time: 1619ms
memory: 4532kb
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: 1065ms
memory: 4472kb
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