QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#177230#5301. Modulo Ruins the LegendballanceWA 0ms3692kbC++231.8kb2023-09-12 18:21:432023-09-12 18:21:44

Judging History

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

  • [2023-09-12 18:21:44]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3692kb
  • [2023-09-12 18:21:43]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <sstream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<array>
#include<queue>
#include<cstring>
#include<stdio.h>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<unordered_map>
#include<random>
#include<bitset>
#include <functional>
//#include <bits/stdc++.h>
typedef long long ll;//unsigned 
typedef long double ld;
#define pii pair<int,int>
#define pip pair<int,pii>
#define pb push_back
#define fi first
#define se second
#define lowbit(x) (x&-x)
#define f(x)(y) x+y
//#define int ll
using namespace std;
minstd_rand gen;
const ld PI = 3.14159265358979323846264338327950288419716939937510L;
const ld eps = 1e-10;

const int N = 100010, M = 20010;
ld a[N];
ll gcd(ll x, ll y)
{
	if (x > y)
		swap(x, y);
	if (x == 0)return y;
	return gcd(y % x, x);
}
ll moni(ll x, ll p)
{
	if (x == 1)
		return 1;
	return ((1 - p * moni(p % x, x)) / x + p * p) % p;
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, m; cin >> n >> m;
	ll sum = 0;
	for (int i = 1; i <= n; i++)
	{
		int a; cin >> a;
		sum += a;
	}
	ll x, y;
	ll kk[2];
	int GCD = gcd(n, m);
	{
		int k = sum % GCD;
		kk[0] = k;
		if (k == sum)
		{
			x = 0;
			goto door;
		}
		int right = (k - sum + m) % m;
		x = right / GCD * moni(n / GCD, m / GCD);
	}
door:;
	{
		int k = (sum + n * (n + 1) / 2) % GCD;
		if (k == sum)
		{
			y = 0;
			goto door1;
		}
		kk[1] = k;
		int right = (k - sum + m - n * (n + 1) / 2 % m + m) % m;
		y = right / GCD * moni(n / GCD, m / GCD);
	}
door1:;
	if (kk[0] < kk[1])
		cout << kk[0] << '\n' << x << ' ' << 0;
	else
		cout << kk[1] << '\n' << y << " 1";
	
}
/*
6
0 0
1 -1 
2 0
2 1 
1 1 
0 1

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
2 1

result:

ok ok

Test #2:

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

input:

7 29
1 9 1 9 8 1 0

output:

0
25 1

result:

ok ok

Test #3:

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

input:

1 1
0

output:

0
0 1

result:

wrong answer Integer parameter [name=d] equals to 1, violates the range [0, 0]