QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#710245 | #5464. Dice Game | 123456zmy# | WA | 1ms | 3768kb | C++17 | 1.5kb | 2024-11-04 19:10:41 | 2024-11-04 19:10:41 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353
using namespace std;
#define abs(x) (x>=0?x:-x)
int qpow(int i,int j){return j?j&1?qpow(i*i%mod,j>>1)*i%mod:qpow(i*i%mod,j>>1):1;}
signed main()
{
int t;
scanf("%lld",&t);
while(t--)
{
int n;
scanf("%lld",&n);
vector<long long>cnt(31),s(31);
for(int i=0;i<=30;i++)
{
cnt[i]=((n>>i+1)<<i);
cnt[i]+=max(0ll,n%(2<<i)-(1<<i));
}
for(int i=0;i<=30;i++)
{
s[i]=cnt[i]*(1<<i);
if(i)s[i]+=s[i-1];
}
long long ans=0;
function<void(int,int,int)>dfs=[&](int l,int k,long long sum)
{
if(k==-1||abs(sum)>s[k])
{
// cerr<<l<<k<<sum<<endl;
ans+=max(0ll,sum%mod*(1<<k+1)%mod);
// if(sum>0)ans+=n*(l+l+(1<<k+1)-1)%mod*(1<<k+1)%mod+sum%mod;
// else ans+=n*(l+l+(1<<k+1)-1)%mod*(1<<k+1)%mod;
return;
}
dfs(l,k-1,sum+cnt[k]*(1<<k));
dfs(l+(1<<k),k-1,sum-cnt[k]*(1<<k));
};
long long sum0=0,lst=0;
for(int l=30;l>=0;l--)
{
if(lst+(1<<l)<=n)
{
dfs(lst,l-1,sum0+cnt[l]*(1<<l));
lst+=(1<<l);
sum0-=cnt[l]*(1<<l);
}
}
// printf("%d\n",ans);
ans+=(n-1)*n/2%mod*n%mod;
printf("%lld\n",ans%mod*qpow(n*n%mod,mod-2)%mod);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3768kb
input:
4 1 2 3 4
output:
0 249561089 776412276 2
result:
ok 4 number(s): "0 249561089 776412276 2"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3764kb
input:
100 119 75 29 10 17 29 449 71 72 12 79 117 83 80 35 272 105 497 346 287 362 140 297 167 111 419 210 212 170 413 373 210 196 39 1 101 258 496 333 293 392 2 187 431 157 342 436 106 449 136 378 243 357 325 237 254 22 292 62 435 18 446 471 18 42 377 181 350 19 389 212 58 45 70 52 63 107 71 66 355 381 30...
output:
645006489 493886987 400009943 19964893 169252513 400009943 60548260 180598904 227994126 471393174 684743533 531171954 860440606 893428747 555757286 212429333 269095960 284396636 731064371 430533886 87458214 725662616 853502563 131075830 724073586 701650152 262576881 417830609 747785300 916357319 646...
result:
wrong answer 2nd numbers differ - expected: '296012775', found: '493886987'