QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685729#8340. 3 SumUESTC_NLNS#WA 0ms3512kbC++202.5kb2024-10-28 21:01:012024-10-28 21:01:01

Judging History

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

  • [2024-10-28 21:01:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3512kb
  • [2024-10-28 21:01:01]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
using u64 = unsigned long long;
u64 base = 1331;
vector<u64> powb;

using ll = long long;
using i128 = ll;
const int mod = 1068299123;

ll qpow(ll x, ll y) {
    i128 ans = 1;
    for (; y; y >>= 1, x = (i128)x * x % mod) {
        if (y & 1) ans = ans * x % mod;
    }
    return ans;
}

int n, k;

bool check(const vector<int>& a) {
    for (int i = 0; i < k; ++i)
        if (a[i] != 9) return 0;
    return 1;
}
const int N = 2e5 + 10;
int main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
    cin >> n >> k;
    ll M = qpow(10, k) - 1;
    vector<ll> a(n);

    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        reverse(s.begin(), s.end());
        // while (s.size() % k != 0) s.push_back('0');
        vector<int> ans(k);
        for (int i = 0; i < s.size(); i += k) {
            int carry = 0;
            for (int j = i; j < i + k && (carry == 0 && j < s.size()); ++j) {
                int t1 = i == s.size() ? '0' : s[i];
                ans[i] = ans[i] + t1 - '0' + carry;
                if (ans[i] >= 10) {
                    carry = 1;
                    ans[i] -= 10;
                }
            }

            if (carry == 1) {
                for (int i = 0; i < k && carry; ++i) {
                    ans[i] = ans[i] + carry;
                    if (ans[i] >= 10) {
                        carry = 1;
                        ans[i] -= 10;
                    }
                }
            }
            if (check(ans)) ans.assign(k, 0);
        }
        i128 tmp = 0;
        i128 f = 1;

        for (int i = 0; i < k; ++i, f = f * 10 % mod) {
            tmp = (tmp + f * ans[i]) % mod;
        }
        a[i] = tmp;
    }

    auto query = [&](ll x) -> int {
        unordered_map<ll, int> mp;
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= i; ++j) {
                ll a2 = (a[i] + a[j]) % mod;
                if (mp.find(a2) == mp.end()) {
                    mp[a2] = 1;
                } else {
                    mp[a2]++;
                }
            }
            int t = (x - a[i] + mod) % mod;
            if (mp.find(t) != mp.end())
                ans += mp[(x - a[i] + mod) % mod];
        }
        return ans;
    };
    cout << query(0) + query(M) + query((i128)2 * M % mod) << '\n';
}
/*
4 1
0
1
10
17
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3512kb

input:

4 1
0
1
10
17

output:

5

result:

wrong answer 1st numbers differ - expected: '3', found: '5'