QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#115847 | #5301. Modulo Ruins the Legend | PetroTarnavskyi# | WA | 1ms | 3564kb | C++17 | 1.4kb | 2023-06-27 15:14:47 | 2023-06-27 15:14:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
int phi(int n)
{
int ans = n;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
ans -= ans / i;
while (n % i == 0) n /= i;
}
}
if (n > 1)
ans -= ans / n;
return ans;
}
int mult(int a, int b, int m)
{
return LL(a) * b % m;
}
int binpow(int a, int p, int m)
{
int ans = 1;
while (p)
{
if (p & 1) ans = mult(ans, a, m);
p /= 2;
a = mult(a, a, m);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
int s = 0;
FOR (i, 0, n)
{
int a;
cin >> a;
s += a;
if (s >= m) s -= m;
}
int ans = -1;
int anss = -1, ansd = -1;
FOR (d, 0, 2)
{
int D = __gcd(n, m);
int x = s % D;
int ph = phi(m / D);
LL inv = binpow(n / D, ph - 1, m / D);
LL S = (s - x) / D * inv % (m / D);
if (ans == -1 || ans > (s + S * n) % m)
{
ans = (s + S * n) % m;
anss = S;
ansd = d;
}
s += LL(n) * (n + 1) / 2 % m;
s %= m;
}
cout << ans << '\n' << anss << ' ' << ansd << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3408kb
input:
6 24 1 1 4 5 1 4
output:
1 2 1
result:
ok ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3340kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3400kb
input:
1 1000000000 963837005
output:
927674010 963837005 0
result:
wrong answer Participant answer greater than judge