QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620302 | #5301. Modulo Ruins the Legend | Lynia | WA | 0ms | 3724kb | C++20 | 2.2kb | 2024-10-07 17:25:23 | 2024-10-07 17:25:33 |
Judging History
answer
#include<bits/stdc++.h>
#define fa(i,op,n) for(int i=op;i<=n;i++)
#define fb(i,op,n) for(int i=op;i>=n;i--)
#define endl '\n'
#define pb push_back
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 3e3 + 10;
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, y, x);
y -= a / b * x;
return d;
}
void solve()
{
ll n, m; cin >> n >> m;
ll sum = 0;
fa(i, 1, n) {
ll now; cin >> now;
sum += now;
}
sum %= m;
if (n & 1) {
fa(ans, 0, m) {
ll a = n;
ll b = m;
ll c = ans - sum;
ll x, y;
ll g = exgcd(a, b, x, y);
if (c % g != 0)continue;
else {
x = ((x * (c / g)) % (b / g) + (b / g)) % (b / g);
ll xx, yy;
ll aa = 1, bb = (n + 1) / 2;
ll gg = exgcd(aa, bb, yy, xx);
if (x % gg != 0)continue;
else {
cout << ans << endl;
if (x > 0) {
yy = ((yy * (x / gg)) % (x / gg) + (x / gg)) % (x / gg);
xx = ((xx * (x / gg)) % (x / gg) + (x / gg)) % (x / gg);
}
cout << -xx << ' ' << yy << endl;
return;
}
}
}
}
else {
ll res = 0;
ll r = 0;
fa(ans, 0, m) {
ll a = n * (n + 1) / 2;
ll b = m;
ll c = ans - sum;
ll x, y;
ll g = exgcd(a, b, x, y);
if (c % g != 0)continue;
else {
res = max(res, ans * 1ll);
r = ((x * (c / g)) % (b / g) + (b / g)) % (b / g);
//cout << ans << endl;
//cout << 0 << ' ' << ((x * (c / g)) % (b / g) + (b / g)) % (b / g) << endl;
break;
}
}
fa(ans, 0, m) {
ll a = n;
ll b = m;
ll c = ans - sum;
ll x, y;
ll g = exgcd(a, b, x, y);
if (c % g != 0)continue;
else {
if (ans < res) {
cout << ans << endl;
cout << ((x * (c / g)) % (b / g) + (b / g)) % (b / g) << ' ' << 0 << endl;
}
else {
cout << res << endl;
cout << 0 << ' ' << r << endl;
}
//cout << ans << endl;
//cout << 0 << ' ' << ((x * (c / g)) % (b / g) + (b / g)) % (b / g) << endl;
return;
}
}
}
return;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
//cin >> _;
while (_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3724kb
input:
6 24 1 1 4 5 1 4
output:
1 0 5
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 1
result:
wrong answer Result not equal to solution.