QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#411338 | #3170. Lunchtime Name Recall | ucup-team1716 | WA | 6ms | 27916kb | C++14 | 3.5kb | 2024-05-15 11:43:44 | 2024-05-15 11:43:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mk make_pair
const int MAXS = 28628;
const int MAXPairs = 300000;
int n, m;
int cnt;
int num[35], num2[35];
map<vector<int>, int> mp;
vector<int> vecs[MAXS + 5];
vector<int> state[35], state2[35];
void dfs(vector<int> v, int sum) {
assert(v.size());
assert(!mp[v]);
mp[v] = ++cnt;
vecs[cnt] = v;
state[sum].push_back(cnt);
if (v.size() % 2 == 0)
state2[sum].push_back(cnt);
for (int i = v.back(); sum + i <= n; ++i) {
v.push_back(i);
dfs(v, sum + i);
v.pop_back();
}
}
int a[15];
int cnt_pairs;
pair<int, int> states_pairs[MAXPairs + 5];
map<pair<int, int>, int> mp_pairs;
bool dp[31][16][MAXPairs + 5];
void print(vector<int> v) {
cout << "[";
for (int i = 0; i < (int)v.size(); ++i) {
cout << v[i] << ", ";
}
cout << "]" << endl;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> a[i];
a[i] = min(a[i], n - a[i]); // to reduce constant
}
// n = 30;
for (int i = 1; i <= n; ++i) {
vector<int> v;
v.push_back(i);
dfs(v, i);
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < (int)state[i].size(); ++j) {
for (int k = 0; k < (int)state2[n - i].size(); ++k) {
states_pairs[++cnt_pairs] = mk(state[i][j], state2[n - i][k]);
mp_pairs[mk(state[i][j], state2[n - i][k])] = cnt_pairs;
}
}
}
for (int j = 0; j < (int)state[n].size(); ++j) {
states_pairs[++cnt_pairs] = mk(state[n][j], 0); // do not split anything
mp_pairs[mk(state[n][j], 0)] = cnt_pairs;
}
for (int k = 0; k < (int)state2[n].size(); ++k) {
states_pairs[++cnt_pairs] = mk(0, state2[n][k]); // split everything (do not leave anything)
mp_pairs[mk(0, state2[n][k])] = cnt_pairs;
}
// when n = 30, cnt_pairs is 294652; roughly 3*10^5
vector<int> v;
v.push_back(n);
// cout << mp[v] << endl; // 28628, when n = 30
dp[0][0][mp_pairs[mk(mp[v], 0)]] = 1;
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= cnt_pairs; ++j) {
if (dp[i - 1][0][j]) {
vector<int> v = vecs[states_pairs[j].fi];
for (int k = 0; k < (int)vecs[states_pairs[j].se].size(); ++k)
v.push_back(vecs[states_pairs[j].se][k]);
// i.e., v = putting together the two vectors
sort(v.begin(), v.end());
assert(mp[v] != 0);
dp[i][a[i]][mp_pairs[mk(mp[v], 0)]] = 1;
}
}
for (int j = a[i]; j >= 1; --j) { // number of 1s remaining
for (int k = 1; k <= cnt_pairs; ++k) { // current state: (unsplitted, splitted)
if (dp[i][j][k]) {
vector<int> v1 = vecs[states_pairs[k].fi], v2 = vecs[states_pairs[k].se];
for (int l = 0; l < (int)v1.size(); ++l) {
for (int m = 1; m < v1[l] && m <= j; ++m) {
vector<int> nv1, nv2 = v2;
for (int t = 0; t < (int)v1.size(); ++t)
if (t != l)
nv1.push_back(v1[t]);
nv2.push_back(m);
nv2.push_back(v1[l] - m);
sort(nv2.begin(), nv2.end());
// assert(mp[nv2] != 0);
dp[i][j - m][mp_pairs[mk(mp[nv1], mp[nv2])]] = 1;
}
}
}
}
}
}
int ans = 0;
for (int j = 1; j <= cnt_pairs; ++j) {
if (dp[m][0][j]) {
vector<int> v1 = vecs[states_pairs[j].fi], v2 = vecs[states_pairs[j].se];
int num1s = 0;
for (int k = 0; k < (int)v1.size(); ++k)
num1s += (v1[k] == 1);
for (int k = 0; k < (int)v2.size(); ++k)
num1s += (v2[k] == 1);
ans = max(ans, num1s);
}
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12424kb
input:
4 2 2 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 18872kb
input:
16 3 6 8 8
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 0ms
memory: 14032kb
input:
5 2 2 2
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 20732kb
input:
16 3 8 8 8
output:
6
result:
ok single line: '6'
Test #5:
score: -100
Wrong Answer
time: 6ms
memory: 27916kb
input:
20 7 1 1 1 1 6 8 8
output:
9
result:
wrong answer 1st lines differ - expected: '11', found: '9'