QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#458503 | #7615. Sequence Folding | kia | WA | 80ms | 39800kb | C++20 | 2.4kb | 2024-06-29 17:41:34 | 2024-06-29 17:41:36 |
Judging History
answer
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
ll t, n, m, a[N], dp[2][20*N], cnt;
set<ll> st;
void divide(int id, ll l, ll r) {
auto it = (st.lower_bound(l));
if(it == st.end() || (*it) > r) {
dp[0][id] = 0, dp[1][id] = (r-l+1);
return;
}
if((*it) == r && l == r) {
dp[0][id] = 1, dp[1][id] = 0;
return;
}
ll mid = (l+r-1)/2;
ll lft=++cnt, rgt=++cnt;
divide(lft,l,mid); divide(rgt,mid+1,r);
dp[0][id] = min({
dp[0][lft]+dp[0][rgt],
dp[0][lft]+dp[1][rgt]+1,
dp[1][lft]+dp[0][rgt]+1,
dp[1][lft]+dp[1][rgt]+2
});
dp[1][id] = min({
dp[0][lft]+dp[0][rgt]+2,
dp[0][lft]+dp[1][rgt]+1,
dp[1][lft]+dp[0][rgt]+1,
dp[1][lft]+dp[1][rgt]
});
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m;
ll num = 0;
while((1ll<<num) < n) num++;
for(int i=1; i<=m; i++) {
ll x; cin>>x; ll y=0;
for(ll j=0; j<=num; j++) {
if((x>>j)%2ll == 1) y += (1ll<<(num-j));
}
st.insert(y);
}
divide(++cnt, 1, n);
cout<<min(dp[0][1], dp[1][1]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5716kb
input:
8 3 1 5 8
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
1 1 1
output:
0
result:
ok single line: '0'
Test #3:
score: -100
Wrong Answer
time: 80ms
memory: 39800kb
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:
49964
result:
wrong answer 1st lines differ - expected: '99999', found: '49964'