QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#623854#5301. Modulo Ruins the Legendadivse#RE 0ms3656kbC++20895b2024-10-09 14:13:192024-10-09 14:13:19

Judging History

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

  • [2024-10-09 14:13:19]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3656kb
  • [2024-10-09 14:13:19]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 100005;
const int inf = 1e9;

int n, m, a, q;

int exgcd(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int g = exgcd(b, a % b, x, y);
	int temp = x;
	x = y;
	y = temp - (a / b) * y;
	return g;
}

signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		int x; cin >> x;
		q += x; q %= m;
	}
	int x, y, g;
	g = exgcd(n, n * (n + 1) / 2, x, y);
	g %= m;
	
	if (q % g <= (g - (m - q) % g) % g) {
		x = -x * (q / g) % m;
		y = -y * (q / g) % m;
		cout << q % g << endl;
	} else {
		x = x * ((m - q) / g);
		y = y * ((m - q) / g);
		cout << (g - (m - q) % g) % g << endl;
	}
	x = (x % m + m) % m;
	y = (y % m + m) % m;
	cout << x << ' ' << y << endl;
	
	return 0;
}

详细

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
15 19

result:

ok ok

Test #2:

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

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

score: -100
Runtime Error

input:

1 1
0

output:


result: