# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
760242 | 2023-06-17T10:36:36 Z | drdilyor | Party (INOI20_party) | C++17 | 3000 ms | 312 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long; #define DEBUG #if defined(ONPC) && !defined(NODEBUG) #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 = [&](ll 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 = min((int)k, d - (i - j)); ll need = i == j ? pw2(depth) - 1 : (pw2(depth)-1) - (pw2(depth-1)-1); debug(i, d, depth, j, need, size, perim); ll cperim = need >= size ? 0 : i == j ? need+1 : need; perim += cperim; cnt += min(size, need); if (cperim) assert(need + cperim <= size); assert(perim + cnt <= n); } if (lastj) perim++; if (n == cnt) break; ll level = pw2(i); ll p = comb(cnt); if (cnt + perim < n) p = sub(p, comb(cnt + perim)); debug(i, d, cnt, level, perim, p); res += (d%mod) * (level%mod) % mod * (p%mod); res %= mod; debug(res); } } 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 143 ms | 312 KB | Output is correct |
2 | Correct | 164 ms | 296 KB | Output is correct |
3 | Correct | 145 ms | 292 KB | Output is correct |
4 | Correct | 128 ms | 212 KB | Output is correct |
5 | Correct | 161 ms | 212 KB | Output is correct |
6 | Correct | 148 ms | 212 KB | Output is correct |
7 | Correct | 136 ms | 296 KB | Output is correct |
8 | Correct | 142 ms | 300 KB | Output is correct |
9 | Correct | 138 ms | 296 KB | Output is correct |
10 | Correct | 148 ms | 304 KB | Output is correct |
11 | Execution timed out | 3080 ms | 312 KB | Time limit exceeded |
12 | 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 | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |