QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358935 | #7615. Sequence Folding | zyz07 | TL | 0ms | 3564kb | C++17 | 1.3kb | 2024-03-20 09:12:50 | 2024-03-20 09:12:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(auto Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(auto Ti=(Ta);Ti>=(Tb);--Ti)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define range(Tx) begin(Tx),end(Tx)
using ll=long long;
ll next(ll x){
return (x==(x&-x)?1:2)<<__lg(x);
}
const int M=1e5+5;
ll n,p[M];
int m;
vector<ll> vec{1};
vector<array<ll,2>> f;
bool one(ll x){
return *lower_bound(p+1,p+m+1,x)==x;
}
array<ll,2> dp(ll x){
auto it=lower_bound(range(vec),x);
if(it==vec.end()||*it!=x){
return {0,1};
}
return f[it-vec.begin()];
}
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n>>m;
For(i,1,m){
cin>>p[i];
for(ll j=p[i];j>1;j=next(j)-j+1){
vec.push_back(j);
}
}
sort(range(vec));
vec.erase(unique(range(vec)),vec.end());
f.resize(vec.size());
Dec(i,int(vec.size())-1,0){
ll x=vec[i],f[2][2]{{0,1},{1,0}},g[2][2];
for(ll k=next(x),y;(y=k*2-x+1)<=n;k*=2){
auto fv=dp(y);
memset(g,0x3f,sizeof(g));
For(i,0,1){
g[i][0]=min(f[i][0],f[i][1]+1)+fv[0];
g[i][1]=min(f[i][1],f[i][0]+1)+fv[1];
}
memcpy(f,g,sizeof(g));
}
if(one(x)){
::f[i]={min(f[0][0]+1,f[0][1]),min(f[1][0]+1,f[1][1])};
}else{
::f[i]={min(f[0][0],f[0][1]+1),min(f[1][0],f[1][1]+1)};
}
}
cout<<min(f[0][0],f[0][1])<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3480kb
input:
8 3 1 5 8
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
1 1 1
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Time Limit Exceeded
input:
17179869184 100000 138476 774165 993977 1152277 1236393 1244970 1534017 1693701 1763926 1778781 1842066 1874644 1885666 2120429 2485344 2977941 3158255 3340476 3504862 4000117 4066652 4197639 4338723 4389163 4576965 4761601 5097091 5175412 5295902 5810551 5855982 6001770 6111262 6163309 6351547 6582...