QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622581#5301. Modulo Ruins the LegendFoedere0WA 0ms3588kbC++201.7kb2024-10-08 23:02:042024-10-08 23:02:05

Judging History

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

  • [2024-10-08 23:02:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3588kb
  • [2024-10-08 23:02:04]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
unordered_map<int, int> mp;
int sum = 0;
int n, m;
int a[N];

int exgcd(int a, int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a; // 到达递归边界开始向上一层返回
    }
    int d = exgcd(b, a % b, x, y);
    int temp = y; // 推出这一层的x,y
    y = x - (a / b) * y;
    x = temp;
    return d;
}
void solve()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
        sum %= m;
    }
    // cout << sum << endl;
    // int t = m - (sum % m);
    int o = n, p = (n * (n + 1)) / 2;
    // cout << o * 15 + p * -5 + sum << endl;
    //  cout << o << " " << p << endl;
    //   cout << p * 5 % m << endl;
    int u = __gcd(o, p);
    // cout << u << endl;
    int x = __gcd(u, m);
    // cout << x << endl;
    int l = 0, r = 1e18;
    while (l < r)
    {
        int mid = (l + r + 1) / 2;
        if (mid * x <= sum)
        {
            l = mid;
        }
        else
            r = mid - 1;
    }
    // cout << l << endl;
    int ans = sum - (l * x);
    cout << ans << endl;
    int w, t;

    exgcd(u, m, w, t);
    w *= (-l);
    // cout << w << endl;
    //   cout << w*l*u << " " << t << endl;
    int xx, yy;
    exgcd(o, p, xx, yy);
    // cout << xx << " " << yy << endl;
    cout << xx * w << " " << yy * w << endl;
}
signed 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: 0
Wrong Answer
time: 0ms
memory: 3588kb

input:

6 24
1 1 4 5 1 4

output:

1
15 -5

result:

wrong answer Integer parameter [name=d] equals to -5, violates the range [0, 23]