QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#656180 | #5301. Modulo Ruins the Legend | 666ldc | TL | 0ms | 3788kb | C++17 | 1.5kb | 2024-10-19 11:42:24 | 2024-10-19 11:42:26 |
Judging History
answer
#pragma GCC optimize(2)
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define int long long
#define endl '\n'
using i128 = __int128;
using i64 = long long;
using f128 = long double;
using u64 = unsigned long long;
using pii = pair<int, int>;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const i64 inf = 2e18;
//-------------------------------------------
void solve()
{
int n, m;
cin >> n >> m;
int C = 0;
for (int i = 1, a; i <= n; i++)
{
cin >> a;
C += a;
}
int A = n, B = n * (n + 1) / 2, ans = inf;
set<int> se1;
pii res;
for (int i = 0; i <= m; i++)
{
int w1 = (A * i + C) % m;
if (se1.count(w1))
break;
se1.insert(w1);
set<int> se2;
for (int j = 0; j <= m; j++)
{
int w2 = (A * i + B * j + C) % m;
if (se2.count(w2))
break;
se2.insert(w2);
if (ans > w2)
{
ans = w2;
res = {i, j};
}
ans = min(ans, w2);
// cerr << i << " " << j << " " << (A * i + B * j + C) % m << endl;
}
}
cout << ans << endl
<< res.x << " " << res.y << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
input:
6 24 1 1 4 5 1 4
output:
1 0 5
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
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: 3520kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: -100
Time Limit Exceeded
input:
1 1000000000 963837005