QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107062 | #5301. Modulo Ruins the Legend | shiyihangxs | WA | 9ms | 4508kb | C++14 | 1.5kb | 2023-05-20 10:24:17 | 2023-05-20 10:24:21 |
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);
c = c+(-xx)*m;
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
6 24 1 1 4 5 1 4
output:
1 5 23
result:
ok ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3540kb
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: 3776kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 2ms
memory: 3412kb
input:
1 1000000000 963837005
output:
0 0 36162995
result:
ok ok
Test #5:
score: 0
Accepted
time: 2ms
memory: 3704kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 2ms
memory: 3476kb
input:
2 1000000000 948507269 461613424
output:
0 1 196626435
result:
ok ok
Test #7:
score: 0
Accepted
time: 1ms
memory: 4352kb
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: 9ms
memory: 4488kb
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: 1ms
memory: 4508kb
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 83793 888664479
result:
wrong answer Result not equal to solution.