QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#644693 | #7615. Sequence Folding | ucup-team4479# | WA | 249ms | 12400kb | C++23 | 1.3kb | 2024-10-16 15:08:04 | 2024-10-16 15:08:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=100005;
long long n;
int m;
long long a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=m;i++)
cin>>a[i];
int c=__lg(n);
vector<pair<long long,array<long long,2>>>f;
for(int i=1;i<=m;i++)
f.emplace_back(a[i],array<long long,2>{1,0});
sort(f.begin(),f.end());
for(int i=c;i>=2;i--)
{
vector<pair<long long,array<long long,2>>>npos;
for(auto &[p,dp]:f)
{
long long np=p;
if(p>(1ll<<(c-1))) np=(1ll<<c)-p+1;
npos.emplace_back(np,array<long long,2>{0,1ll<<(c-i+1)});
}
sort(npos.begin(),npos.end());
npos.erase(unique(npos.begin(),npos.end()),npos.end());
for(auto &[p,dp]:f)
{
long long np=p;
if(p>(1ll<<(c-1))) np=(1ll<<c)-p+1;
auto it=lower_bound(npos.begin(),npos.end(),make_pair(np,array<long long,2>{0,0}));
it->second[1]-=1ll<<(c-i);
it->second[0]+=dp[0];
it->second[1]+=dp[1];
}
f=npos;
}
array<long long,2>dp=f[0].second;
long long ans=min(dp[0],dp[1]);
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
8 3 1 5 8
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
1 1 1
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 249ms
memory: 12400kb
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...
output:
1
result:
wrong answer 1st lines differ - expected: '99999', found: '1'