Submission #1003106

#TimeUsernameProblemLanguageResultExecution timeMemory
1003106vjudge1Party (INOI20_party)C++17
0 / 100
3067 ms82424 KiB
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9+7; const int N = 2100, LG=10; long long binpow(long long a, long long b, long long MOD) { a%=MOD; long long res = 1; while(b) { if(b&1){ res=(res*a)%MOD; } a=(a*a)%MOD; b>>=1ll; } res%=MOD; return res; } int dist[N][N]; int tmp; vector<int> g[N]; void dfs(int at, int p=0) { for(int to:g[at]) { if(to == p)continue; dist[tmp][to] = dist[tmp][at]+1; dfs(to, at); } } int main () { cin.tie(0)->sync_with_stdio(0); int q; cin >> q; while(q--) { int n; cin >> n; memset(dist, 0, sizeof dist); for(int i = 1;i<=n;i++) { if(2*i <= n) { g[i].push_back(2*i); g[2*i].push_back(i); } if(2*i+1 <=n) { g[i].push_back(2*i+1); g[2*i+1].push_back(i); } } for(int i = 1;i<=n;i++) { tmp = i; dfs(i, 0); } long long ans=0; for(int i = 1;i<=n;i++) { for(int j = 0;j<=n;j++) { long long pw1 = 1, pw2=1; int cnt=0; for(int k = 1;k<=n;k++) { if(dist[i][k] < j) { pw1=(pw1*binpow(2, mod-2, mod))%mod; } else if(dist[i][k] == j) { pw2=(pw2*binpow(2, mod-2, mod))%mod; } } ans+=((pw1*(1-pw2))%mod*j)%mod; ans%=mod; ans+=mod; ans%=mod; } } ans=(ans*binpow(2,n, mod))%mod; ans=(ans*binpow(binpow(2,n, mod)-1+mod, mod-2, mod))%mod; cout << ans << "\n"; for(int i = 1;i<=n;i++) { g[i].clear(); } } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:54:13: warning: unused variable 'cnt' [-Wunused-variable]
   54 |         int cnt=0;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...