Submission #1292580

#TimeUsernameProblemLanguageResultExecution timeMemory
1292580BuiDucManh123Party (INOI20_party)C++20
30 / 100
248 ms588 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define taskname ""
const int mod = 1e9+7;
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
#define int ll
const int ans[] = {0,0,571428577,401574811,68575102,347470132,149707164,295038330,246944817,168459846,848759170,753916649,874259235,436845857,455803345,732110426,912252260,380931639,725126576,755085026,497747095,601032270,132018618,195747679,326166778,90750519,950969612,561147124,716973945,398359507,245333203,645374876,58517764,882537570,387870120,174478760,770163916,657328870,392199940,752435265,596273060,880391751,607922078,465118232,314990412,429160328,670114601,83625202,713881005,807523234,400261067,826581252,770146593,608067344,280418783,20107917,573628670,767615667,381834390,980680016};
 vector<int> g[209];
 int cnt[209];
ll mu(ll a, ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}
void dfs(int u, int p, int d){
    if(d)
    cnt[d]++;
    for(int v : g[u]){
        if(v == p) continue;
        dfs(v, u, d + 1);
    }
}
void solve(){
    int n;
    cin >> n;
    if(n <= 200){
        for(int i = 1; i <= n; i++){
            g[i].clear();
        }
        for(int i = 1; i <= n; i++){
            if(i > 1){
                g[i].pb(i / 2);
            }
            if(i * 2 <= n){
                g[i].pb(i * 2);
            }
            if(i * 2 < n){
            g[i].pb(i * 2 + 1);
            }
        }
        int res = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j < n; j++){
                cnt[j] = 0;
            }
            dfs(i, i, 0);
            int sum = n - 1;
            for(int j = 1; j < n; j++){
                res = (res + mu(2, sum) + mod - 1) % mod;
                sum -= cnt[j];
            }

        }
        res = res * mu(mu(2, n) - 1, mod - 2) % mod;
        cout << res << "\n";
    }else{

        cout << ans[__lg(n + 1)] << "\n";
    }
}
signed main() {
    if (fopen(taskname".inp","r")) {
        freopen(taskname".inp","r",stdin);
        freopen(taskname".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test = 1;
    cin >> test;
    while(test--){
        solve();
    }
    return 0;
}


Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |         freopen(taskname".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(taskname".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...