QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873852 | #3170. Lunchtime Name Recall | LaStataleBlue# | TL | 7ms | 3712kb | C++23 | 2.8kb | 2025-01-27 02:59:31 | 2025-01-27 02:59:32 |
Judging History
answer
// #pragma GCC optimize("Ofast")
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <climits>
#include <iomanip>
using namespace std;
#define int uint16_t
void solve([[maybe_unused]] int t)
{
int n, m;
cin >> n >> m;
// n = 30;
// m = 10;
vector<int> a(m);
for (auto &i : a)
cin >> i;
// i = n / 2;
vector<map<int, int>> dp(m);
auto hash = [](vector<int> &v) -> int
{
vector<int> freq(31);
for (auto i : v)
freq[i]++;
long long ans = 0, base = 47;
for (auto i : freq)
{
ans *= base;
ans += i + 1;
}
return ans;
};
vector<int> curr;
curr.reserve(n);
auto calc = [&](auto &calc, vector<int> &v, int ind, int x, set<vector<int>> &opz) -> void
{
if (ind == v.size())
{
if (x == 0)
{
opz.insert(curr);
}
return;
}
for (int i = 0; i <= min(v[ind], x); i++)
{
if (i)
curr.push_back(i);
if (v[ind] - i)
curr.push_back(v[ind] - i);
calc(calc, v, ind + 1, x - i, opz);
if (v[ind] - i)
curr.pop_back();
if (i)
curr.pop_back();
}
};
auto f = [&](auto &f, vector<int> v, int ind)
{
int cont = 0;
for (auto i : v)
if (i == 1)
cont++;
if (ind == m)
{
return cont;
}
if (cont == n)
return cont;
sort(v.begin(), v.end());
if (dp[ind].count(hash(v)))
return dp[ind][hash(v)];
int res = 0;
set<vector<int>> opz;
calc(calc, v, 0, a[ind], opz);
vector<vector<int>> vv;
vv.reserve(opz.size());
for (auto i : opz)
vv.push_back(i);
sort(vv.begin(), vv.end(), [](auto &i, auto &j)
{ return i.size() > j.size(); });
for (auto &i : vv)
{
res = max(res, f(f, i, ind + 1));
if (res == n)
{
cout << n << "\n";
exit(0);
}
}
return dp[ind][hash(v)] = res;
};
vector<int> st = {n};
cout << signed(f(f, st, 0)) << "\n";
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n = 1;
// cin >> n;
for (int i = 1; i <= n; i++)
solve(i);
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
input:
4 2 2 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3456kb
input:
16 3 6 8 8
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
5 2 2 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
16 3 8 8 8
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 7ms
memory: 3712kb
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: 3584kb
input:
7 3 3 2 1
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
9 4 1 1 3 3
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 3 4 4 3
output:
6
result:
ok single line: '6'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 3 4 4 5
output:
6
result:
ok single line: '6'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
10 3 4 4 4
output:
7
result:
ok single line: '7'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
12 3 6 6 6
output:
6
result:
ok single line: '6'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 5 2 2 2 2 2
output:
7
result:
ok single line: '7'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 6 2 2 2 2 2 2
output:
10
result:
ok single line: '10'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 2 3 3
output:
2
result:
ok single line: '2'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 6 8 5 2 8 8 1
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
7 4 5 5 1 2
output:
5
result:
ok single line: '5'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 1 1
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
30 1 15
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 5 1 1 1 1 1
output:
3
result:
ok single line: '3'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3584kb
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