QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#658020 | #5301. Modulo Ruins the Legend | sunjq | TL | 0ms | 0kb | C++20 | 1.3kb | 2024-10-19 15:59:44 | 2024-10-19 15:59:45 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define pi pair<int, int>
#define yyy cout<<"Yes\n"
#define nnn cout<<"No\n"
#define int128 __int128_t
const int N = 2e6 + 5;
int m, n;
void solve()
{
cin >> n >> m;
int sum = 0;
int Nn = n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
sum += x;
}
sum %= m;
int ans = m, k = 0;
m *= 2;
int res = m - 2 * sum;
if(Nn % 2 == 1) {
for (int i = 0; i < 700000000 ; i += 2) {
int t = (n * i % (m) - (res));
if(t >= 0 && t % 2 == 0) {
if(ans > t / 2) {
ans = t / 2;
k = i;
}
}
}
}
else {
for (int i = (Nn + 1); i < 700000000 ; i += 2) {
int t = (n * i % (m) - (res));
if(t % 2 == 0 && t >= 0) {
if(ans > t / 2) {
ans = t / 2;
k = i;
}
}
}
}
cout << (ans == m / 2 ? 0 : ans) << '\n';
cout << k % (Nn + 1) / 2 << " " << k / (Nn + 1);
}
signed main()
{
ios;
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
6 24 1 1 4 5 1 4
output:
1 2 1