QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#628739 | #5301. Modulo Ruins the Legend | qilou | WA | 26ms | 7740kb | C++23 | 1.4kb | 2024-10-10 21:59:08 | 2024-10-10 21:59:12 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n';
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const int N=5e5+10,inf=1e9+10;
int n,m,k,sum=0,mod,ns[N];
int vis[N];
ll exgcd(ll a,ll b,ll &x,ll &y)
{
if(!b)
{
x=1;y=0;
return a;
}
else
{
ll tx,ty;
ll d=exgcd(b,a%b,tx,ty);
x=ty;y=tx-(a/b)*ty;
return d;
}
}
int cacu(){
int res=n*(n+1)/2;
return res;
}
void judge(int s,int d){
int res=0;
res=s*n+cacu()*d;
for(int i=1;i<=n;i++){
res+=ns[i];
}
cout<<res%mod;
}
void solve(){
cin>>n>>mod;
for(int i=1;i<=n;i++){
cin>>ns[i];
sum+=ns[i];
}
int a=n,b=cacu();
int g1=__gcd(a,b);
int g2=__gcd(g1,mod);
int ans=sum%g2;
int tk1=0,temp=0;
int d=exgcd(g1,mod,tk1,temp);
// cout<<g1<<" "<<mod<<endl;
int k1=(ans-sum)/d*tk1;
int x=0,y=0;
d=exgcd(a,b,x,y);
int all=k1*g1;
// cout<<x<<" "<<y<<endl;
// cout<<all<<" "<<d<<endl;
x=x*all/d;
y=y*all/d;
// cout<<x<<" "<<y<<endl;
cout<<ans<<endl;
cout<<(x%mod+mod)%mod<<" "<<(y%mod+mod)%mod<<endl;
if(mod==998244353)judge((x%mod+mod)%mod,(y%mod+mod)%mod);
}
signed main(){
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T=1;
// cin>>T;
while(T--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5680kb
input:
6 24 1 1 4 5 1 4
output:
1 15 19
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 5744kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 5684kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
1 1000000000 963837005
output:
0 0 36162995
result:
ok ok
Test #5:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 5740kb
input:
2 1000000000 948507269 461613424
output:
0 410120693 589879307
result:
ok ok
Test #7:
score: 0
Accepted
time: 9ms
memory: 7740kb
input:
100000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 0 0
result:
ok ok
Test #8:
score: 0
Accepted
time: 26ms
memory: 7672kb
input:
100000 1000000000 253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...
output:
46613 535950000 999089281
result:
ok ok
Test #9:
score: -100
Wrong Answer
time: 25ms
memory: 5668kb
input:
100000 998244353 561002596 498658036 721339539 63377827 532179242 934651519 234198881 490149304 2056307 499913682 427679408 694677560 516580968 300129454 816286800 688594301 183049581 456627420 495848352 273497462 953217060 796225499 207179832 728054671 409492082 25003432 810431468 206421553 5569626...
output:
0 254661439 331357611 436983415
result:
wrong answer Result not equal to solution.