QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586884#5301. Modulo Ruins the Legendwsxcb#WA 76ms3700kbC++171018b2024-09-24 16:22:412024-09-24 16:22:42

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 16:22:42]
  • 评测
  • 测评结果:WA
  • 用时:76ms
  • 内存:3700kb
  • [2024-09-24 16:22:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1e18;
ll exgcd(ll a,ll b ,ll &x, ll &y)
{
	if(!b)
	{
		x=1;
		y=0;
		return a;
	}
	ll ans=exgcd(b,a%b,x,y);
	ll x0=x,y0=y;
	x=y0,y-=x0-a/b*y0;
	return ans;
}
void solve(){
	
	int n,m;
	cin>>n>>m;
	ll sum=0;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		sum+=x;
	}
	ll k=1ll*n*(n+1)/2;
	ll g=__gcd(n,m);
	ll ans=INF,pp,ansd;
	for(int i=0;i<=1000000;i++)
	{
		ll s=sum+1ll*i*k;
		s%=m;
		ll s1=s;
		s=m-s;
		ll l=0,r=1e9,pos;
		while(l<=r)
		{
			ll mid=(l+r)/2;
			if(mid*g>=s){
				r=mid-1;
				pos=mid;
			}
			else
				l=mid+1;
		}
		s1=(s1+g*pos)%m;
		if(s1<ans)
		{
			ans=s1;
			ansd=i;
			pp=pos*g;
			
		}
	}
	cout<<ans<<'\n';
	ll x,y;
	ll d=exgcd(n,m,x,y);
	ll cnt=pp/d;
	x*=cnt;
	ll res=abs(m/d);
	cout<<(x%res+res)%res<<' ';
	cout<<ansd;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int T = 1;
	while(T--){
		solve();
	}
	
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 45ms
memory: 3700kb

input:

6 24
1 1 4 5 1 4

output:

1
2 1

result:

ok ok

Test #2:

score: 0
Accepted
time: 45ms
memory: 3608kb

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

score: 0
Accepted
time: 45ms
memory: 3556kb

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

score: -100
Wrong Answer
time: 76ms
memory: 3620kb

input:

1 1000000000
963837005

output:

0
963837005 0

result:

wrong answer Result not equal to solution.