QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#403743#5301. Modulo Ruins the Legendxiao_hongWA 6ms3832kbC++20892b2024-05-02 18:17:002024-05-02 18:17:01

Judging History

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

  • [2024-05-02 18:17:01]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3832kb
  • [2024-05-02 18:17:00]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS cin.tie(0),cout.tie(0),ios::sync_with_stdio(0)
//#define int __int128
typedef __int128 ll;
using namespace std;
int n,k,m;
int sum=0;

ll exgcd(ll a, ll b, __int128 &x, __int128 &y) {
	if(!a) {
		x = 0, y = 1;
		return b;
	}
	ll d = exgcd(b % a, a, y, x);
	x -= b / a * y;
	return d;
}
void solve()
{
	__int128 s,d;
	cin>>n>>m;
	for(int t=1;t<=n;t++)
	{
		int yy;cin>>yy;
		sum+=yy;
	}
	int g=__gcd(n,n*(n+1)/2);
	int gg=__gcd(g,m);
	__int128 k1,k2;
	exgcd(m,g,k1,k2);
	__int128 k3=-sum/gg;
	int ans=k3*gg+sum;
	k1*=k3,k2*=k3;
	exgcd(n,n*(n+1)/2,s,d);
	s*=(ans-sum-k1*m)/g;
	d*=(ans-sum-k1*m)/g;
	s=(s%m+m)%m;d=(d%m+m)%m;//防止s d值超过m
	cout<<ans<<endl;
	cout<<(long long)s<<" "<<(long long)d<<endl; 
	
}
int main()
{
    IOS;
	int T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

6 24
1 1 4 5 1 4

output:

1
15 19

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3820kb

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: 3548kb

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

1 1000000000
963837005

output:

0
36162995 0

result:

ok ok

Test #5:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

2 1
0 0

output:

0
0 0

result:

ok ok

Test #6:

score: 0
Accepted
time: 0ms
memory: 3832kb

input:

2 1000000000
948507269 461613424

output:

0
410120693 589879307

result:

ok ok

Test #7:

score: 0
Accepted
time: 3ms
memory: 3644kb

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: 3616kb

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:

5
944450996 610576796

result:

wrong answer Result not equal to solution.