QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#235750#5301. Modulo Ruins the Legendushg8877#RE 37ms3560kbC++20644b2023-11-03 08:21:592023-11-03 08:21:59

Judging History

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

  • [2023-11-03 08:21:59]
  • 评测
  • 测评结果:RE
  • 用时:37ms
  • 内存:3560kb
  • [2023-11-03 08:21:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
int n,m;ll s;
void construct(ll x,ll y,ll p){
	int g=__gcd(x,y);
	x/=g,y/=g,p/=g;
	map<ll,ll> mp;
	for(int i=1;i<=1e6;i++){
		ll k=rnd()%m;
		mp[k*x%m]=k;
	}
	while(1){
		ll k=rnd()%m;
		if(mp.count((p-y*k%m+m)%m)){
			cout<<mp[(p-y*k%m+m)%m]<<' '<<k<<endl;
			return;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1,a;i<=n;i++){
		cin>>a;s+=a;
	}
	ll a=1ll*n*(n+1)/2%m,b=n%m;s%=m;
	ll g=__gcd(__gcd(a,b),(ll)m);
	cout<<s%g<<endl;
	construct(b,a,(m+s%g-s)%m);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 31ms
memory: 3560kb

input:

6 24
1 1 4 5 1 4

output:

1
5 23

result:

ok ok

Test #2:

score: 0
Accepted
time: 37ms
memory: 3512kb

input:

7 29
1 9 1 9 8 1 0

output:

0
13 4

result:

ok ok

Test #3:

score: -100
Runtime Error

input:

1 1
0

output:

0

result: