# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
760154 | 2023-06-17T08:39:23 Z | drdilyor | Party (INOI20_party) | C++17 | 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
# | 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 | - |