답안 #760157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760157 2023-06-17T08:44:50 Z drdilyor Party (INOI20_party) C++17
0 / 100
167 ms 304 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++) {
            ll cnt = 0, perim=0;
            int lastj = 0;
            for (int j = i; j >= 0 && i - j < d; j--) {
                lastj = j;
                ll size = i == j ? pw2(k-j)-1 : pw2(k - j -1);
                int depth = d - (i - j);
                ll need = i == j ? pw2(depth) - 1 : (pw2(depth)-1) - (pw2(depth-1)-1);
                debug(i, d, j, need, size, perim);
                perim += need >= size ? 0 : i == j ? need+1 : need;
                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:57:17: note: in expansion of macro 'debug'
   57 |                 debug(i, d, j, need, size, perim);
      |                 ^~~~~
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));
      |     ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 167 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -