QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#747918 | #5301. Modulo Ruins the Legend | hnust_100team# | WA | 6ms | 3836kb | C++17 | 1.8kb | 2024-11-14 18:44:31 | 2024-11-14 18:44:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n,m;cin>>n>>m;
vector<int>a(n+1);
int sum=0;
for(int i=1;i<=n;i++){
cin>>a[i];
sum+=a[i];
}
sum=m-sum%m;
int c1,c2;
if(n%2!=0){
int g=__gcd(n,m);
int p=n/g,q=m/g;
int x,y;
for(int i=0;i<=n;i++){
if((i*q+1)%p==0){
x=(i*q+1)/p;
break;
}
}
int dis1=sum-(sum/g)*g,dis2=(sum/g)*g+g-sum;
x%=m;
if(dis1<=dis2){
cout<<dis1<<"\n";
cout<<(x*((sum/g)%m))%m<<" "<<"0"<<"\n";
return;
}else{
cout<<dis2<<"\n";
cout<<((x*((sum/g)%m))%m+x)%m<<" "<<"0"<<"\n";
return;
}
}else{
int g=__gcd(n/2,m);
int cnt1,cnt2;//n/2 : cnt1+cnt2;
int km=m*(n/2);
km=km*((n+1)/km)+km;
if(km%2==0){
cnt2=1;
cnt1=(km+1-n-1)/2;
}else{
cnt1=(km+1)/2;
cnt2=0;
}
// cout<<cnt1<<" "<<cnt2<<" :"<<cnt1*n+cnt2*n*(n+1)/2<<" "<<(cnt1*n+cnt2*n*(n+1)/2)%m<<"\n";
int p=(n/2)/g,q=m/g;
// cout<<g<<" "<<p<<"*"<<q<<"\n";
int x,y;
for(int i=0;i<=n;i++){
// cout<<(i*q+1)<<" "<<p<<"\n";
if((i*q+1)%p==0){
x=(i*q+1)/p;
break;
}
}
// cout<<x<<"\n";
int dis1=sum-(sum/g)*g,dis2=(sum/g)*g+g-sum;
// cout<<cnt1<<" "<<cnt2<<" "<<x<<" "<<sum<<" "<<g<<"\n";
cnt1%=m;cnt2%=m;x%=m;
if(dis1<=dis2){
cout<<dis1<<"\n";
c1=(cnt1*((x*((sum/g)%m)%m)%m))%m,c2=(cnt2*((x*((sum/g)%m)%m)%m))%m;
cout<<c1<<" "<<c2<<"\n";
// cout<<(m-sum+c1*n+c2*n*(n+1)/2)%m<<"\n";
return;
}else{
cout<<dis2<<"\n";
c1=(cnt1*(((x*((sum/g)%m)%m)%m+x)%m))%m,c2=(cnt2*(((x*((sum/g)%m))%m+x)%m))%m;
cout<<c1<<" "<<c2<<"\n";
// cout<<(m-sum+c1*n+c2*(n+1)*n/2)%m<<"\n";
return;
}
}
}
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: 0ms
memory: 3548kb
input:
6 24 1 1 4 5 1 4
output:
1 3 3
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
1 1000000000 963837005
output:
0 36162995 0
result:
ok ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 0ms
memory: 3480kb
input:
2 1000000000 948507269 461613424
output:
0 910120693 589879307
result:
ok ok
Test #7:
score: 0
Accepted
time: 3ms
memory: 3800kb
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: -100
Wrong Answer
time: 6ms
memory: 3836kb
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:
3387 536000000 9280
result:
wrong answer Result not equal to solution.