QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140045 | #3170. Lunchtime Name Recall | Kirill22# | WA | 1ms | 3612kb | C++23 | 1.6kb | 2023-08-15 00:35:00 | 2023-08-15 00:35:01 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
long double start = clock();
int n, m, a[10], ans = 0, t = 0;
set<vector<int>> used[11];
void CheckTime() {
if (t++ == 100) {
t = 0;
if ((long double) (clock() - start) / CLOCKS_PER_SEC > 6) {
cout << ans;
exit(0);
}
}
}
void dfs(int j, vector<int> c) {
CheckTime();
sort(c.begin(), c.end());
if (j == m) {
int cnt = 0;
for (auto x : c) {
cnt += x == 1;
}
if (ans < cnt) {
cout << cnt << endl;
ans = cnt;
}
return;
}
if (used[j].find(c) != used[j].end()) {
return;
}
used[j].insert(c);
vector<int> tmp;
function<void(int, int)> gen = [&] (int i, int x) {
if (i == (int) c.size()) {
if (!x) {
dfs(j + 1, tmp);
}
return;
}
for (int v = 0; v <= min(x, c[i]); v++) {
if (v) {
tmp.push_back(v);
}
if (v != c[i]) {
tmp.push_back(c[i] - v);
}
gen(i + 1, x - v);
if (v) {
tmp.pop_back();
}
if (v != c[i]) {
tmp.pop_back();
}
}
};
gen(0, a[j]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[i];
a[i] = min(a[i], n - a[i]);
}
dfs(0, {n});
cout << ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3612kb
input:
4 2 2 2
output:
4 4
result:
wrong output format Extra information in the output file