Submission #760154

# Submission time Handle Problem Language Result Execution time Memory
760154 2023-06-17T08:39:23 Z drdilyor Party (INOI20_party) C++17
0 / 100
1 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef ONPC
#define debug(args...) cout << "["<< #args << "]= "; debug_out(args);
#else
#define debug(args...) 42;
#endif
void debug_out() {
    cout << endl;
}
template<typename H, typename... T>
void debug_out(H h, T... t) {
    cout << h;
    if (sizeof...(t)) cout << ", ";
    debug_out(t...);
}

constexpr int mod = 1e9 + 7;
ll modpow(ll a, ll b) {
    a %= mod;
    ll res = 1;
    while (b) {
        if (b&1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
ll inv(ll x) {
    return modpow(x, mod-2);
}
ll pw2(ll x) {
    return x < 0 ? 0 :(1LL << x);
}
ll sub(ll a, ll b) {
    a -= b;
    return a < 0 ? a + mod : a;
}

ll solve(ll n) {
    ll k = __lg(n+1);
    if ((1ll<<k)-1 != n) return -1;
    debug(n, k);
    auto comb = [&](int chosen)->ll{ return sub(modpow(2, n - chosen), 1); };
    ll res = 0;

    for (int i = 0; i < k; i++) {
        for (int d = 1; d <= k*2; d++) {
            int cnt = 0, perim=0;
            int lastj = 0;
            for (int j = i; j >= 0 && i - j < d; j--) {
                lastj = j;
                ll size = i == j ? ((1<< (k - j))-1) : (1 << (k - j-1));
                int depth = d - (i - j);
                ll need = i == j ? pw2(depth) - 1 : (pw2(depth)-1) - (pw2(depth-1)-1);
                perim += need >= size ? 0 : i == j ? need+1 : need;
                if (perim) assert(need + perim <= size);
                cnt += min(size, need);
            }
            if (lastj) perim++;
            if (n == cnt) break;
            assert(cnt < n);
            ll level = pw2(i);
            ll p = comb(cnt);
            if (cnt + perim < n)
                p -= comb(cnt + perim); 
            debug(i, d, cnt, level, perim, p);
            debug(d*level % mod * p);
            res += d * level % mod * p;
            res %= mod;
        }
    }
    debug(res, comb(0));
    return res * inv(comb(0)) % mod;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int q; cin >> q;
    while (q--) {
        ll n; cin >> n;
        cout << solve(n) << '\n';
    }
}

Compilation message

Main.cpp: In function 'll solve(ll)':
Main.cpp:7:24: warning: statement has no effect [-Wunused-value]
    7 | #define debug(args...) 42;
      |                        ^~
Main.cpp:44:5: note: in expansion of macro 'debug'
   44 |     debug(n, k);
      |     ^~~~~
Main.cpp:7:24: warning: statement has no effect [-Wunused-value]
    7 | #define debug(args...) 42;
      |                        ^~
Main.cpp:68:13: note: in expansion of macro 'debug'
   68 |             debug(i, d, cnt, level, perim, p);
      |             ^~~~~
Main.cpp:7:24: warning: statement has no effect [-Wunused-value]
    7 | #define debug(args...) 42;
      |                        ^~
Main.cpp:69:13: note: in expansion of macro 'debug'
   69 |             debug(d*level % mod * p);
      |             ^~~~~
Main.cpp:7:24: warning: statement has no effect [-Wunused-value]
    7 | #define debug(args...) 42;
      |                        ^~
Main.cpp:74:5: note: in expansion of macro 'debug'
   74 |     debug(res, comb(0));
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -