QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#671739#5301. Modulo Ruins the Legendbessie_goes_moo#WA 0ms3676kbC++141.3kb2024-10-24 14:16:532024-10-24 14:16:54

Judging History

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

  • [2024-10-24 14:16:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2024-10-24 14:16:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int T, n, a[N], m, sum;
inline int read() {
	int al = 0, fh = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9') {
		if (ch == '-')
			fh = -1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') {
		al = al * 10 + ch - '0';
		ch = getchar();
	}
	return al * fh;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
map<int, int> ma;
int cel(int a, int b) {
	return a % b == 0 ? a / b : a / b + 1;
}
void exgcd(int a,int b,int &x,int &y)
{
	if(!b)
	{
		x=1;
		y=0;
		return;
	}
	int p;
	exgcd(b,a%b,x,y);
	p=x;
	x=y;
	y=p-(a/b)*y;
	return;
}
signed main() {
	n = read();
	m = read();
	for (int i = 1; i <= n; i++) {
		a[i] = read();
		sum += a[i];
	}
	int s = sum % m, g = gcd(n, n * (n + 1) / 2) % m, ans = 0, now = 0, chu = 0;
	ans = s;
	int ans_chu = 0;
	now = s;
	if (g == 0)
	{
		cout << "0 0";
		return 0;
	}
	while (ma[now] == 0) {
		ma[now] = 1;
		int u = cel(m - now, g);
		now += u * g;
		now %= m;
		chu += u;
		if (now < ans) {
			ans = now;
			ans_chu = chu;
		}
	}
	int x, y;
	exgcd(n, (n + 1)*n / 2, x, y);
	x=(x%m+m)%m;
	y=(y%m+m)%m;
	x*=ans_chu;
	x%=m;
	y*=ans_chu;
	y%=m;
	cout << x << " " << y << endl;
	//cout << ans << " " << ans_chu << endl;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3676kb

input:

6 24
1 1 4 5 1 4

output:

15 3

result:

wrong output format Unexpected end of file - int32 expected