QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#873855 | #3170. Lunchtime Name Recall | LaStataleBlue | WA | 4ms | 3712kb | C++17 | 1.7kb | 2025-01-27 03:10:16 | 2025-01-27 03:10:16 |
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, vector<uint64_t>& opz) {
if(i==1) {
if(nb<=score(op+nop)) 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, opz);
}
}
calc(nop, op, i-1, nb, nb, opz);
}
int bnb(uint64_t bs, int ai) {
if(ai==m) return score(bs);
int ub=n;
vector<uint64_t> nxt;
calc(0,bs,30,a[ai],a[ai],nxt);
int res=0;
for(auto &nbs:nxt) {
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;
}
详细
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: 3712kb
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: 1ms
memory: 3584kb
input:
16 3 8 8 8
output:
6
result:
ok single line: '6'
Test #5:
score: 0
Accepted
time: 4ms
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: 3456kb
input:
7 3 3 2 1
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
9 4 1 1 3 3
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
10 3 4 4 3
output:
6
result:
ok single line: '6'
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 3584kb
input:
10 3 4 4 5
output:
7
result:
wrong answer 1st lines differ - expected: '6', found: '7'