QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#218065#5301. Modulo Ruins the LegendhazeWA 3ms3652kbC++201.9kb2023-10-17 17:58:392023-10-17 17:58:40

Judging History

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

  • [2023-10-17 17:58:40]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3652kb
  • [2023-10-17 17:58:39]
  • 提交

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), 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));
	//cout << d << ' ' << d0 << endl;
	/*
	d1 : K
	s1 : k
	*/
	ll 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: 0ms
memory: 3624kb

input:

6 24
1 1 4 5 1 4

output:

1
15 3

result:

ok ok

Test #2:

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

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

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

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

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

input:

1 1000000000
963837005

output:

0
0 36162995

result:

ok ok

Test #5:

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

input:

2 1
0 0

output:

0
0 0

result:

ok ok

Test #6:

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

input:

2 1000000000
948507269 461613424

output:

0
410120693 589879307

result:

ok ok

Test #7:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

100000 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
0 0

result:

ok ok

Test #8:

score: 0
Accepted
time: 3ms
memory: 3560kb

input:

100000 1000000000
253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...

output:

46613
535950000 9281

result:

ok ok

Test #9:

score: -100
Wrong Answer
time: 3ms
memory: 3572kb

input:

100000 998244353
561002596 498658036 721339539 63377827 532179242 934651519 234198881 490149304 2056307 499913682 427679408 694677560 516580968 300129454 816286800 688594301 183049581 456627420 495848352 273497462 953217060 796225499 207179832 728054671 409492082 25003432 810431468 206421553 5569626...

output:

0
860465250 184657996

result:

wrong answer Result not equal to solution.