Submission #1003558

# Submission time Handle Problem Language Result Execution time Memory
1003558 2024-06-20T12:58:53 Z vjudge1 Party (INOI20_party) C++17
30 / 100
286 ms 1616 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define oo 1e9

const int MAX = 205 + 8, MOD = 1e9 + 7, LOGMAX = 200;
int n;
int Hcnt[LOGMAX][LOGMAX];
int RHcnt[LOGMAX][LOGMAX];

int binpow(int a, int b){
    int res = 1;
    while(b){
        if(b & 1) res = res * a % MOD;
        b /= 2;
        a = a * a % MOD;
    }
    return res;
}
int inv(int a){
    return binpow(a, MOD - 2);
}

int ans[LOGMAX];

int vis[MAX];
int H[MAX];
void dfs(int node, int h){
    if(vis[node] || node > n || node < 1) return;
    vis[node] = 1;
    H[h]++;
    dfs(node * 2, h + 1);
    dfs(node * 2 + 1, h + 1);
    dfs(node / 2, h + 1);
}


void solve(){
    cin >> n;
    int LG = 1, T = 1;
    while(T <= n / 2) {LG++; T *= 2;}
    if((1ll << LG) - 1 == n){
        cout << ans[LG] << '\n';
        return;
    }
    int res = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= n; j++){
            vis[j] = 0;
            H[j] = 0;
        } 
        dfs(i, 0);
        int oth = n;
        for(int j = 0; j <= n; j++){
            if(!H[j]) break;
            oth -= H[j];
            res = (res + j * (binpow(2, H[j]) - 1) % MOD * binpow(2, oth) % MOD) % MOD;
        }
    }
    cout << res * inv(binpow(2, n) - 1) % MOD << '\n';
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for(int z = 1; z < 63; z++){
        n = (1ll << z) - 1;
        int res = 0;
        int LG = z - 1;
        for(int i = 0; (1ll << i) <= n; i++){
            for(int j = 0; j <= LG + i; j++){
                Hcnt[i][j] = 0;
                RHcnt[i][j] = 0;
            }
            for(int j = 0; j <= LG - i; j++){
                Hcnt[i][j] = (1ll << j);
                RHcnt[i][j] = (1ll << max(0ll, j - 1));
            }
            if(i != 0){
                for(int j = 0; j <= LG + i - 1; j++){
                    RHcnt[i][j + 1] += RHcnt[i - 1][j];
                    Hcnt[i][j + 1] += RHcnt[i - 1][j];
                }
            }
            int oth = n;
            for(int j = 0; j <= LG + i; j++){
                oth -= Hcnt[i][j];
                res = (res + j * (binpow(2, Hcnt[i][j]) - 1 + MOD) % MOD * binpow(2, oth + i) % MOD) % MOD;
            }
        }
        ans[z] = res * inv((binpow(2, n) - 1 + MOD) % MOD) % MOD;
    }
    int t; cin >> t;
    while(t--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 604 KB Output is correct
2 Correct 40 ms 632 KB Output is correct
3 Correct 39 ms 648 KB Output is correct
4 Correct 38 ms 604 KB Output is correct
5 Correct 44 ms 852 KB Output is correct
6 Correct 40 ms 604 KB Output is correct
7 Correct 40 ms 604 KB Output is correct
8 Correct 38 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 35 ms 600 KB Output is correct
11 Correct 36 ms 604 KB Output is correct
12 Correct 37 ms 632 KB Output is correct
13 Correct 266 ms 604 KB Output is correct
14 Correct 276 ms 656 KB Output is correct
15 Correct 286 ms 600 KB Output is correct
16 Correct 280 ms 604 KB Output is correct
17 Correct 187 ms 564 KB Output is correct
18 Correct 185 ms 648 KB Output is correct
19 Correct 178 ms 632 KB Output is correct
20 Correct 187 ms 652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 600 KB Output is correct
2 Correct 35 ms 604 KB Output is correct
3 Correct 36 ms 600 KB Output is correct
4 Correct 33 ms 604 KB Output is correct
5 Correct 35 ms 600 KB Output is correct
6 Correct 33 ms 600 KB Output is correct
7 Correct 35 ms 604 KB Output is correct
8 Correct 35 ms 604 KB Output is correct
9 Correct 32 ms 644 KB Output is correct
10 Correct 31 ms 612 KB Output is correct
11 Correct 34 ms 604 KB Output is correct
12 Correct 36 ms 600 KB Output is correct
13 Correct 36 ms 604 KB Output is correct
14 Correct 36 ms 600 KB Output is correct
15 Correct 36 ms 848 KB Output is correct
16 Correct 36 ms 600 KB Output is correct
17 Correct 36 ms 604 KB Output is correct
18 Correct 31 ms 600 KB Output is correct
19 Correct 34 ms 648 KB Output is correct
20 Correct 36 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 1616 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 604 KB Output is correct
2 Correct 40 ms 632 KB Output is correct
3 Correct 39 ms 648 KB Output is correct
4 Correct 38 ms 604 KB Output is correct
5 Correct 44 ms 852 KB Output is correct
6 Correct 40 ms 604 KB Output is correct
7 Correct 40 ms 604 KB Output is correct
8 Correct 38 ms 600 KB Output is correct
9 Correct 36 ms 604 KB Output is correct
10 Correct 35 ms 600 KB Output is correct
11 Correct 36 ms 604 KB Output is correct
12 Correct 37 ms 632 KB Output is correct
13 Correct 266 ms 604 KB Output is correct
14 Correct 276 ms 656 KB Output is correct
15 Correct 286 ms 600 KB Output is correct
16 Correct 280 ms 604 KB Output is correct
17 Correct 187 ms 564 KB Output is correct
18 Correct 185 ms 648 KB Output is correct
19 Correct 178 ms 632 KB Output is correct
20 Correct 187 ms 652 KB Output is correct
21 Correct 36 ms 600 KB Output is correct
22 Correct 35 ms 604 KB Output is correct
23 Correct 36 ms 600 KB Output is correct
24 Correct 33 ms 604 KB Output is correct
25 Correct 35 ms 600 KB Output is correct
26 Correct 33 ms 600 KB Output is correct
27 Correct 35 ms 604 KB Output is correct
28 Correct 35 ms 604 KB Output is correct
29 Correct 32 ms 644 KB Output is correct
30 Correct 31 ms 612 KB Output is correct
31 Correct 34 ms 604 KB Output is correct
32 Correct 36 ms 600 KB Output is correct
33 Correct 36 ms 604 KB Output is correct
34 Correct 36 ms 600 KB Output is correct
35 Correct 36 ms 848 KB Output is correct
36 Correct 36 ms 600 KB Output is correct
37 Correct 36 ms 604 KB Output is correct
38 Correct 31 ms 600 KB Output is correct
39 Correct 34 ms 648 KB Output is correct
40 Correct 36 ms 604 KB Output is correct
41 Runtime error 32 ms 1616 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -