# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
635878 |
2022-08-27T09:06:17 Z |
S2speed |
Party (INOI20_party) |
C++17 |
|
3000 ms |
340 KB |
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define all(x) x.begin() , x.end()
#define sze(x) (ll)(x.size())
typedef long long ll;
const ll maxn = 206 , md = 1e9 + 7 , inf = 2e16;
inline ll tav(ll n , ll k){
ll res = 1;
while(k > 0){
if(k & 1){
res *= n; res %= md;
}
n *= n; n %= md;
k >>= 1;
}
return res;
}
ll n , ans[maxn];
vector<ll> adj[maxn] , bfs;
ll dis[maxn] , cnt[maxn] , res;
void BFS(ll r){
memset(dis , 63 , sizeof(dis));
bfs.clear();
dis[r] = 0;
bfs.push_back(r);
ll x = 0;
while(x < sze(bfs)){
ll v = bfs[x++];
for(auto i : adj[v]){
if(dis[i] < inf) continue;
dis[i] = dis[v] + 1;
bfs.push_back(i);
}
}
return;
}
void sub1(){
if(ans[n] != -1){
cout<<ans[n]<<'\n';
return;
}
res = 0;
for(ll i = 0 ; i < n ; i++) adj[i].clear();
for(ll i = 1 ; i < n ; i++){
ll par = (i - 1) >> 1;
adj[par].push_back(i); adj[i].push_back(par);
}
for(ll i = 0 ; i < n ; i++){
BFS(i);
memset(cnt , 0 , sizeof(cnt));
for(ll j = 0 ; j < n ; j++){
cnt[dis[j]]++;
}
ll ps = n;
for(ll d = 0 ; d < n ; d++){
if(cnt[d] == 0) break;
ps -= cnt[d];
ll h = (tav(2 , cnt[d]) - 1) * tav(2 , ps) % md * d % md;
res += h;
}
}
// cout<<res<<'\n';
res %= md;
res *= tav(tav(2 , n) - 1 , md - 2);
res %= md;
ans[n] = res;
cout<<res<<'\n';
return;
}
ll tl[130];
void sub2(){
ll t = -1;
for(ll i = 0 ; i < 65 ; i++){
if((1ll << i) == n + 1){
t = i;
break;
}
}
if(t == -1) return;
res = 0;
for(ll i = 0 , z = 1 ; i < t ; i++ , z <<= 1){
memset(tl , 0 , sizeof(tl));
ll v = z , d = i , y = 0 , o = 0;
if((z << 1) == n + 1){
y = 1;
tl[1] = 1;
}
tl[t - i - 2] = (1ll << (t - i - 1));
ll cur = 1 , ps = n;
for(ll j = 0 ; j < 130 && ps > 0 ; j++){
ps -= cur;
ll h = (tav(2 , cur) - 1) * tav(2 , ps) % md * j % md;
o += h;
cur -= y;
y = tl[j];
cur <<= 1;
if(v == 1){
cur--;
v = 0;
}
if(v > 1){
v >>= 1; d--;
tl[j + t - d - 1] = (1ll << (t - d - 2));
}
cur += (j == 0);
}
o %= md;
o *= z % md; o %= md;
res += o;
}
// cout<<res<<'\n';
res %= md;
res *= tav(tav(2 , n) - 1 , md - 2);
res %= md;
cout<<res<<'\n';
return;
}
void solve(){
cin>>n;
if(n <= 200){
sub1();
return;
}
sub2();
return;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
memset(ans , -1 , sizeof(ans));
ll T;
cin>>T;
while(T--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
328 KB |
Output is correct |
3 |
Correct |
6 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
212 KB |
Output is correct |
2 |
Correct |
126 ms |
332 KB |
Output is correct |
3 |
Correct |
109 ms |
324 KB |
Output is correct |
4 |
Correct |
98 ms |
320 KB |
Output is correct |
5 |
Correct |
113 ms |
324 KB |
Output is correct |
6 |
Correct |
111 ms |
340 KB |
Output is correct |
7 |
Correct |
99 ms |
320 KB |
Output is correct |
8 |
Correct |
111 ms |
340 KB |
Output is correct |
9 |
Correct |
101 ms |
340 KB |
Output is correct |
10 |
Correct |
111 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
3046 ms |
312 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
328 KB |
Output is correct |
3 |
Correct |
6 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
106 ms |
212 KB |
Output is correct |
22 |
Correct |
126 ms |
332 KB |
Output is correct |
23 |
Correct |
109 ms |
324 KB |
Output is correct |
24 |
Correct |
98 ms |
320 KB |
Output is correct |
25 |
Correct |
113 ms |
324 KB |
Output is correct |
26 |
Correct |
111 ms |
340 KB |
Output is correct |
27 |
Correct |
99 ms |
320 KB |
Output is correct |
28 |
Correct |
111 ms |
340 KB |
Output is correct |
29 |
Correct |
101 ms |
340 KB |
Output is correct |
30 |
Correct |
111 ms |
340 KB |
Output is correct |
31 |
Execution timed out |
3046 ms |
312 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |