답안 #760153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760153 2023-06-17T08:38:37 Z The_Samurai Party (INOI20_party) C++17
23 / 100
3000 ms 468 KB
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

const ll mod = 1e9 + 7;

ll binpow(ll a, ll b, ll mod, bool dec = false) {
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans = ans * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    if (dec) {
        ans = (ans - 1 + mod) % mod;
    }
    return ans;
}

bool isTwo(ll n) {
    return (1ll << (63 - __builtin_clzll(n))) == n;
}

ll n, ans;

void calc(ll x, ll mul) {
    vector<tuple<ll, ll, bool>> g = {{x, 1, true}};
    ll others = n, sum_all = 0;
    for (int h = 0; h <= n; h++) {
        vector<tuple<ll, ll, bool>> nw;
        ll sum = 0;
        for (auto [v, t, change]: g) {
            sum += t;
            if (!change) {
                if (v * 2 <= n) {
                    nw.emplace_back(v * 2, t * 2, change);
                }
                continue;
            }
            if (x == v) {
                if (v * 2 <= n) {
                    nw.emplace_back(v * 2, t * 2, false);
                }
                if (v > 1) {
                    nw.emplace_back(v / 2, 1, true);
                }
                continue;
            }
            if (isTwo(x / v) and x % v == 0) {
                if (v * 2 + 1 <= n) {
                    nw.emplace_back(v * 2 + 1, 1, false);
                }
                if (v > 1) {
                    nw.emplace_back(v / 2, 1, true);
                }
                continue;
            }
        }
        others -= sum;
        ll k = binpow(2, sum, mod, true) * binpow(2, others, mod) % mod;
        sum_all = (sum_all + k * h) % mod;
        if (nw.empty()) {
            break;
        }
        g = nw;
    }
    mul %= mod;
    ans = (ans + sum_all * mul) % mod;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int q;
    cin >> q;
    map<ll, int> mp;
    for (int qq = 1; qq <= q; qq++) {
        cin >> n;
//        n = (1ll << 59) - 1;
        if (mp.count(n)) {
            cout << mp[n] << '\n';
            continue;
        }
        ans = 0;
        for (ll x = 1; x < n; x *= 2) {
            calc(x, x);
        }
        ans = ans * binpow(binpow(2, n, mod, true), mod - 2, mod) % mod;
        cout << ans << '\n';
        mp[n] = ans;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3078 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 212 KB Output is correct
2 Correct 42 ms 448 KB Output is correct
3 Correct 39 ms 328 KB Output is correct
4 Correct 39 ms 324 KB Output is correct
5 Correct 40 ms 336 KB Output is correct
6 Correct 38 ms 332 KB Output is correct
7 Correct 37 ms 212 KB Output is correct
8 Correct 40 ms 328 KB Output is correct
9 Correct 39 ms 320 KB Output is correct
10 Correct 37 ms 212 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 4 ms 340 KB Output is correct
17 Correct 3 ms 372 KB Output is correct
18 Correct 3 ms 328 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3074 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3078 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -