QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#458919#7615. Sequence FoldingkiaWA 960ms229220kbC++202.5kb2024-06-29 20:38:322024-06-29 20:38:32

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 20:38:32]
  • 评测
  • 测评结果:WA
  • 用时:960ms
  • 内存:229220kb
  • [2024-06-29 20:38:32]
  • 提交

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;
map<ll, bool> mp;

void divide(int id, ll v, ll h) {
    if(mp[v] == 0) {
        dp[0][id] = 0, dp[1][id] = n/(1ll<<h);
        return;
    }
    if((1ll<<h) == n) {
        if(st.find(v)!=st.end()) {
            dp[0][id] = 1, dp[1][id] = 0;
        } else {
            dp[1][id] = 1, dp[0][id] = 0;
        }
        return;
    }

    ll lft=++cnt, rgt=++cnt;
    divide(lft, v, h+1); divide(rgt, (1ll<<(h+1))-v+1, h+1);

    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++;
    
    // fuck(num);
    for(int i=1; i<=m; i++) {
        ll x; cin>>x;
        st.insert(x);
        
        mp[x] = 1;
        for(ll h=num; h>0; h--) {
            x = (1ll<<h) - x + 1;
            mp[x] = 1;
        }
    }
    mp[1] = 1;

    divide(++cnt, 1, 0);
    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: 5724kb

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Wrong Answer
time: 960ms
memory: 229220kb

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:

0

result:

wrong answer 1st lines differ - expected: '99999', found: '0'