QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#643025#5301. Modulo Ruins the LegendtravelWA 0ms3672kbC++141.8kb2024-10-15 18:04:082024-10-15 18:04:08

Judging History

你现在查看的是最新测评结果

  • [2024-10-15 18:04:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3672kb
  • [2024-10-15 18:04:08]
  • 提交

answer

//
// Created by travel on 2024/10/15.
//
#include <bits/stdc++.h>

using namespace std;

using LL = long long;

using vec = array<LL, 2>;

constexpr LL M1 = 1145140019, M2 = 1145140033, pw = 23333;

// a * x % b == gcd(a, b)
void exgcd(LL a, LL b, LL &x, LL &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return;
    }
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}
int gcd(int a,int b)
{
    if(!b) return a;
    else return gcd(b,a % b);
}
LL arr[100020];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    LL n, m;
    cin >> n >> m;

    LL n2 = n, m2 = m;

    LL s = 0;

    for (int i = 1; i <= n; ++i)
    {
        cin >> arr[i];
        s += arr[i];
        s %= m;
    }

    LL ss, dd;

    if (n % 2)
    {
        LL g = gcd(n, m);

        LL ans = s % g;

        n /= g;
        m /= g;
        s /= g;

        LL x, y;

        exgcd(n, m, x, y);

        // n * x % m == 1

        ss = (x * (m - s) % m + m) % m;
        ss = 0;
        cout << ans << "\n";

        dd = 0;
    }
    else
    {
        LL nn = n;

        n /= 2;

        LL g = gcd(n, m);

        LL ans = s % g;

        n /= g;
        m /= g;
        s /= g;

        LL x, y;

        exgcd(n, m, x, y);

        ss = x * (m - s);

        cout << ans << "\n";

        if (ss % 2)
        {
            ss = ((ss - (nn + 1)) / 2 % m + m) % m;
            dd = 1;
        }
        else
        {
            ss = (ss / 2 % m + m) % m;
            dd = 0;
        }
    }

    cout << ss << " " << dd;

    /*LL jxy = 0;

    for (int i = 1; i <= n2; ++i)
    {
        jxy += arr[i] + ss + dd * i;
        jxy %= m2;
    }

    cout << '\n' << jxy;*/
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

6 24
1 1 4 5 1 4

output:

1
6 1

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3672kb

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: 3648kb

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3640kb

input:

1 1000000000
963837005

output:

0
0 0

result:

wrong answer Result not equal to solution.