QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107052 | #5301. Modulo Ruins the Legend | shiyihangxs | WA | 4ms | 4360kb | C++14 | 1.6kb | 2023-05-20 10:01:24 | 2023-05-20 10:01:26 |
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)%m+m)%m, ((y-((aa+bb)/2)*kky)%m+m)%m);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3540kb
input:
6 24 1 1 4 5 1 4
output:
1 22 9
result:
ok ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3540kb
input:
7 29 1 9 1 9 8 1 0
output:
0 1 7
result:
ok ok
Test #3:
score: 0
Accepted
time: 2ms
memory: 3468kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 1000000000 963837005
output:
0 18081497 18081498
result:
ok ok
Test #5:
score: 0
Accepted
time: 2ms
memory: 3468kb
input:
2 1 0 0
output:
0 0 0
result:
ok ok
Test #6:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
2 1000000000 948507269 461613424
output:
0 647469827 431646551
result:
ok ok
Test #7:
score: 0
Accepted
time: 4ms
memory: 4360kb
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: 0ms
memory: 4320kb
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 374942140 250005001
result:
ok ok
Test #9:
score: -100
Wrong Answer
time: 3ms
memory: 4252kb
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 289135077 249564376
result:
wrong answer Result not equal to solution.