QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218066 | #5301. Modulo Ruins the Legend | haze | WA | 0ms | 3620kb | C++20 | 2.0kb | 2023-10-17 17:59:25 | 2023-10-17 17:59:25 |
Judging History
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 - m) / 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: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
6 24 1 1 4 5 1 4
output:
1 12 20
result:
wrong answer Result not equal to solution.