QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107067 | #5301. Modulo Ruins the Legend | shiyihangxs | WA | 8ms | 4328kb | C++14 | 1.7kb | 2023-05-20 10:29:35 | 2023-05-20 10:29:36 |
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), ggg = __gcd(gg, m);
ll c = (m-sum)%m;
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), yy = yy*(c/gg1);
// cout << x << " " << y << endl;
ll kkxx = gg/gg1, kkyy = m/gg1;
ll aaa = ceil(-((double)xx/(double)kkxx)), bbb = floor((double)yy/(double)kkyy);
c = c+(-xx+bbb*kkxx)*m;
if(m == 998244353) 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*kkx)%m+m)%m, ((y-aa*kky)%m+m)%m);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3512kb
input:
6 24 1 1 4 5 1 4
output:
1 5 23
result:
ok ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3780kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 2ms
memory: 3704kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 2ms
memory: 3540kb
input:
1 1000000000 963837005
output:
0 0 36162995
result:
ok ok
Test #5:
score: 0
Accepted
time: 2ms
memory: 3416kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 3464kb
input:
2 1000000000 948507269 461613424
output:
0 1 196626435
result:
ok ok
Test #7:
score: 0
Accepted
time: 4ms
memory: 4320kb
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: 8ms
memory: 4304kb
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 54641 999999999
result:
ok ok
Test #9:
score: -100
Wrong Answer
time: 8ms
memory: 4328kb
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:
7368349043717269856 0 59637 475410718
result:
wrong output format Expected int32, but "7368349043717269856" found