QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#873863 | #3170. Lunchtime Name Recall | LaStataleBlue | WA | 148ms | 4608kb | C++17 | 1.9kb | 2025-01-27 03:24:20 | 2025-01-27 03:24:21 |
Judging History
answer
#include <bits/stdc++.h>
#define int uint16_t
using namespace std;
const int MN = 32;
const int MM = 16;
int n,m;
array<int,MM> a;
const array<int,31> nbit = { 0, 0, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
array<int,31> indb = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
inline int gsiz(uint64_t bs, int i) {
return (bs>>indb[i])&((int(1)<<nbit[i])-1);
}
inline void gadd(uint64_t& bs, int i) {
bs += uint64_t(1)<<indb[i];
}
inline void grem(uint64_t& bs, int i) {
bs -= uint64_t(1)<<indb[i];
}
int score(uint64_t bs) {
int ans = n;
for(int i=2; i<=30; ++i) ans-=gsiz(bs, i)*i;
return ans;
}
void dbg(uint64_t bs) {
for(int i=2; i<=30; ++i) for(int _=0; _<gsiz(bs,i); ++_) {
cerr<<i<<' ';
}
cerr<<endl;
}
void calc(const uint64_t nop, const uint64_t op, const int i, const int nb, int md, int one, vector<uint64_t>& opz) {
if(i==1) {
if(nb<=score(op+nop)-one) opz.push_back(op+nop);
return;
}
md=min(md,int(i-1));
md=min(md,nb);
if(md && gsiz(op,i)) {
for(int d=1; d<=md; ++d) {
uint64_t op2 = op;
uint64_t nop2 = nop;
grem(op2,i);
if(d>1) gadd(nop2,d);
if(i-d>1) gadd(nop2,i-d);
calc(nop2, op2, i, nb-d, d, int(one+(d==1)+(i-d==1)), opz);
}
}
calc(nop, op, i-1, nb, nb, one, opz);
}
unordered_set<uint64_t> memo[31];
int bnb(uint64_t bs, int ai) {
if(ai==m) return score(bs);
if(memo[ai].count(bs)) return 0;
memo[ai].insert(bs);
int ub=n;
vector<uint64_t> nxt;
calc(0,bs,30,a[ai],a[ai],0,nxt);
sort(nxt.begin(), nxt.end());
uint64_t last = -1;
int res=0;
for(auto &nbs:nxt) if(nbs!=last) {
last=nbs;
res=max(res,bnb(nbs,ai+1));
if(res==ub) break;
}
return res;
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
for(int i=1; i<=30; ++i) indb[i]=indb[i-1]+nbit[i-1];
cin>>n>>m;
for(int i=0; i<m; ++i) cin>>a[i];
uint64_t b0=0;
gadd(b0,n);
cout<<bnb(b0,0)<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
4 2 2 2
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
16 3 6 8 8
output:
5
result:
ok single line: '5'
Test #3:
score: 0
Accepted
time: 1ms
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: 1ms
memory: 3584kb
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: 3712kb
input:
9 4 1 1 3 3
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3712kb
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: 3584kb
input:
10 3 4 4 4
output:
7
result:
ok single line: '7'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
12 3 6 6 6
output:
6
result:
ok single line: '6'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
10 5 2 2 2 2 2
output:
7
result:
ok single line: '7'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3712kb
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: 0ms
memory: 3712kb
input:
7 4 5 5 1 2
output:
5
result:
ok single line: '5'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
2 1 1
output:
2
result:
ok single line: '2'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 1 1
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 1ms
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: 3712kb
input:
5 6 2 2 2 2 2 2
output:
5
result:
ok single line: '5'
Test #22:
score: 0
Accepted
time: 97ms
memory: 3712kb
input:
30 5 15 15 15 15 13
output:
28
result:
ok single line: '28'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3712kb
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: 122ms
memory: 4480kb
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: 148ms
memory: 4096kb
input:
30 7 9 9 9 9 9 9 2
output:
28
result:
ok single line: '28'
Test #26:
score: 0
Accepted
time: 145ms
memory: 3712kb
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: 1ms
memory: 3584kb
input:
30 10 1 2 3 4 5 6 7 8 9 10
output:
30
result:
ok single line: '30'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
30 10 11 12 13 14 15 16 17 18 19 20
output:
30
result:
ok single line: '30'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
30 10 20 21 22 23 24 25 26 27 28 29
output:
30
result:
ok single line: '30'
Test #30:
score: 0
Accepted
time: 35ms
memory: 3840kb
input:
30 10 4 4 4 5 5 5 5 5 5 5
output:
28
result:
ok single line: '28'
Test #31:
score: 0
Accepted
time: 120ms
memory: 3840kb
input:
30 10 2 2 2 3 3 3 8 8 9 11
output:
28
result:
ok single line: '28'
Test #32:
score: 0
Accepted
time: 109ms
memory: 3840kb
input:
30 10 2 2 2 3 3 3 9 9 9 9
output:
28
result:
ok single line: '28'
Test #33:
score: 0
Accepted
time: 42ms
memory: 4608kb
input:
30 10 12 12 12 12 3 2 2 2 2 2
output:
28
result:
ok single line: '28'
Test #34:
score: 0
Accepted
time: 42ms
memory: 4608kb
input:
30 10 10 9 9 9 3 3 2 2 2 2
output:
28
result:
ok single line: '28'
Test #35:
score: 0
Accepted
time: 51ms
memory: 4608kb
input:
30 10 10 9 9 8 5 2 2 2 2 2
output:
28
result:
ok single line: '28'
Test #36:
score: 0
Accepted
time: 82ms
memory: 4224kb
input:
30 10 9 9 9 8 8 3 2 2 1 1
output:
28
result:
ok single line: '28'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
30 10 1 1 1 1 1 1 1 1 1 1
output:
10
result:
ok single line: '10'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
30 10 2 2 2 2 2 2 2 2 2 2
output:
15
result:
ok single line: '15'
Test #39:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
30 10 3 3 3 3 3 3 3 3 3 3
output:
20
result:
ok single line: '20'
Test #40:
score: 0
Accepted
time: 9ms
memory: 3840kb
input:
30 10 4 4 4 4 4 4 4 4 4 4
output:
25
result:
ok single line: '25'
Test #41:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
30 10 5 5 5 5 5 5 5 5 5 5
output:
30
result:
ok single line: '30'
Test #42:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
30 3 2 2 2
output:
4
result:
ok single line: '4'
Test #43:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
30 6 2 2 2 2 2 2
output:
9
result:
ok single line: '9'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
30 9 2 2 2 2 2 2 2 2 2
output:
13
result:
ok single line: '13'
Test #45:
score: 0
Accepted
time: 42ms
memory: 3712kb
input:
30 10 2 3 4 5 5 5 5 5 6 6
output:
28
result:
ok single line: '28'
Test #46:
score: 0
Accepted
time: 37ms
memory: 3968kb
input:
30 10 2 4 5 5 5 5 5 5 5 6
output:
28
result:
ok single line: '28'
Test #47:
score: -100
Wrong Answer
time: 81ms
memory: 3840kb
input:
30 10 15 15 15 15 29 29 29 29 29 29
output:
0
result:
wrong answer 1st lines differ - expected: '20', found: '0'