QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107043 | #5301. Modulo Ruins the Legend | shiyihangxs | WA | 2ms | 3548kb | C++14 | 1.6kb | 2023-05-20 09:33:58 | 2023-05-20 09:34:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define l(x) (x<<1)
#define r(x) (x<<1|1)
#define mpr make_pair
//mt19937_64 ra(time(0) ^ (*new char));
//ios::sync_with_stdio(false);
//cin.tie(0); cout.tie(0);
const ll SIZE = 200005;
const ll mod = 998244353;
ll n, m;
ll a[SIZE];
ll sum;
inline ll rd(){
ll x = 0, f = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9'){
x = (x<<1) + (x<<3) + (ch^48);
ch = getchar();
}
return x*f;
}
ll power(ll x, ll y){
ll jl = 1;
while(y){
if(y & 1) jl = (jl * x) % mod;
x = (x * x) % mod;
y >>= 1;
}
return jl;
}
ll exgcd(ll a, ll b, ll &x, ll &y){
if(!b){
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;
}
int main(){
n = rd(), m = rd();
for(ll i = 1; i <= n; i++) a[i] = rd(), sum = (sum + a[i]) % m;
ll a = n, b = (n+1)*n/2, x, y;
ll gg = exgcd(a, b, x, y);
ll c = (m-sum)%m, ggg = __gcd(m, gg);
ll ans = (c/ggg+(c%ggg==0?0:1)) * ggg;
c = ans; ll xx, yy;
ll gg1 = exgcd(m, gg, xx, yy);
xx = xx*(c/gg1);
ll kkxx = gg/gg1;
c = c+(xx+((((a+b)*(m/2)-a)/m-xx)/kkxx)*abs(kkxx))*m;
// cout << c << endl;
ans = (sum+ans) % m;
x = x*(c/gg), y = y*(c/gg);
// cout << x << " " << y << endl;
ll kkx = b/gg, kky = a/gg;
ll aa = ceil(-((double)x/(double)kkx)), bb = floor((double)y/(double)kky);
printf("%lld\n%lld %lld", ans, x+((aa+bb)/2)*kkx, y-((aa+bb)/2)*kky);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
6 24 1 1 4 5 1 4
output:
1 22 9
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3536kb
input:
7 29 1 9 1 9 8 1 0
output:
0 30 7
result:
wrong answer Integer parameter [name=s] equals to 30, violates the range [0, 28]