QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217976#5301. Modulo Ruins the LegendhazeRE 1ms3580kbC++201.9kb2023-10-17 16:45:302023-10-17 16:45:30

Judging History

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

  • [2023-10-17 16:45:30]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3580kb
  • [2023-10-17 16:45:30]
  • 提交

answer

#include<bits/stdc++.h>
#define irep(i,l,r) for(int (i) = (l); (i) <= (r); ++(i))
#define drep(i,r,l) for(int (i) = (r); (i) >= (l); --(i))
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-abs(pp)/abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
#define LL __int128
using namespace std;

inline ll read(){
	char ch = getchar();
	ll s = 0; bool w = 0;
	while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
	while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
	return w ? - s : s;
}

inline char rc(){
	char ch = getchar();
	while(1){
		if(ch >= 'A' && ch <= 'Z')return ch;
		if(ch >= 'a' && ch <= 'z')return ch;
		ch = getchar();
	}
}

template<class T1, class T2>
T1 min(T1 AA, T2 BB){return AA > BB ? BB : AA;}
template<class T1, class T2>
T1 max(T1 AA, T2 BB){return AA < BB ? BB : AA;}

const int itinf = 1e9;
const ll llinf = 4e18;
//const int mod = 1000000007;
const int N = 500009;

ll exgcd(ll a, ll b, ll &x, ll &y){
	if(b == 0){x = 1, y = 0; return a;}
	ll d = exgcd(b, a % b, x, y);
	ll z = x;
	x = y, y = z - y * (a / b);
	return d;
}

ll reduce(ll num, ll md){
	md = abs(md);
	return ((num % md) + md) % md;
}
void solve(){
	ll n = read(), M = read(), sum = 0, m = (n * (n + 1) / 2) % M, S, D, k, K;
	irep(i, 0, n - 1)sum += read(), sum %= M;
	n %= M;
	sum = M - sum;
	ll d = exgcd(n, m, S, D);
	ll d0 = (exgcd(d, - M, K, k)), c = reduce(- sum, d0);
	LL tim = (c + sum) / d0;
	k *= tim, K *= tim;
	tim = (k * M + c + sum) / d;
	S *= tim ,D *= tim;
	cout << c << endl << reduce(S, M) << ' ' << reduce(D, M);
}
int main(){
	solve();
	/*
	16
	*/
	// d0 | c - sum
	/*
	we have n * S + m * D = k * M + c - sum
	need to find the minvalue of c
	
	gcd(n, m) | k * M + c - sum
	d * K = k * M + c - sum
	d * K - M * k = c - sum
	*/
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3580kb

input:

6 24
1 1 4 5 1 4

output:

1
15 3

result:

ok ok

Test #2:

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

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: