QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213973#5301. Modulo Ruins the LegendsundageWA 0ms3656kbC++171.2kb2023-10-14 16:49:472023-10-14 16:49:47

Judging History

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

  • [2023-10-14 16:49:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2023-10-14 16:49:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, m;
int a[100005];
int sum = 0;
int extend_gcd(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int d = extend_gcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

void solve() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum %= m;
	int cnt = sum;
	sum = m - sum;
	int xx = n * (n + 1) / 2;
	int yy = n;
	int s = 0, d = 0;
	int q = extend_gcd(yy, xx, s, d);
	int s1 = 0, d1 = 0;
	int t = extend_gcd(q, m, d1, s1);
	int ans = 0;
	if (sum % t) {
		ans = ((sum / t) + 1) * t - sum;
	} else {
		ans = (sum / t) * t - sum;
	}
	d1 *= ((ans - sum) / t) % m;
	d1 %= m;
	d = d1 * d, s = d1 * s;
	s %= m;
	d %= m;
	s += m;
	d += m;
	s %= m;
	d %= m;
	if (ans > cnt) {
		cout << cnt << endl;
		cout << 0 << " " << 0 << endl;
		return;
	}
	cout << ans << endl;
	cout << s << " " << d << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}
//813586357 839886562
//877878853 839886562


詳細信息

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
6 22

result:

wrong answer Result not equal to solution.