QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#507778#8340. 3 Sumucup-team2307#TL 0ms0kbC++202.8kb2024-08-06 20:51:282024-08-06 20:51:28

Judging History

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

  • [2024-09-20 10:20:30]
  • hack成功,自动添加数据
  • (/hack/848)
  • [2024-08-06 20:51:28]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-08-06 20:51:28]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
using ll = __int128;
const int num_mods = 47;
array<int, num_mods> mods;

array<int, num_mods> transform(vector<int> digits) {
    array<int, num_mods> res;
    for(int M = 0; M < num_mods; M++) {
        ll cur = 1, ans = 0;
        for(auto i : digits) {
            ans = (ans + cur * 1ll * i) % mods[M];
            cur = cur*10ll % mods[M];
        }
        res[M] = ans;
    }
    return res;
}

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

    for (int i=0; i<num_mods; i++)
        mods[i] = (4.7e17+i+1);

    int n, k;

    n = 500;
    k = 19000;
//    cin >> n >> k;
    vector<string> s(n);
    vector<vector<int>> nums;
    for(auto &x : s) {
//        cin >> x;
        x = string(20000, '7');

        reverse(x.begin(), x.end());
        vector<int> digits(k);
        for(int i = 0; i < x.size(); i++) {
            digits[i % k] += x[i] - '0';
        }
        auto carry = [&]() {
            for(int i = 0; i < digits.size(); i++) {
                if(digits[i] >= 10) {
                    if(i + 1 == digits.size()) digits.push_back(0);
                    digits[i + 1] += digits[i] / 10;
                }
                digits[i] %= 10;
            }
        };carry();
        while(digits.size() > k) {
            if(digits.back() == 0) digits.pop_back();
            else for(int i = k; i < digits.size(); i++) {
                digits[i % k] += digits[i];
                digits[i] = 0;
            }
            carry();
        }
        digits.resize(k);
        nums.push_back(digits);
    }
    vector<array<int, num_mods>> T(n);
    for(int i = 0; i < n; i++) T[i] = transform(nums[i]);

    vector<int> MD(k, 9);
    auto M = transform(MD);

    auto solve = [&](array<int, num_mods> X) {
        // map<array<int,
        // for(auto i : X) cout << i << " "; cout << endl;
        int ans = 0;
        for(int i = 0; i < n; i++) {
            // cout << T[i][0] << endl;
            map<array<int, num_mods>, int> cnt;
            for(int j = 0; j <= i; j++) {
                cnt[T[j]]++;
                array<int, num_mods> need;
                for(int t = 0; t < num_mods; t++)
                    need[t] = (X[t] - T[i][t] - T[j][t] + 3ll * mods[t]) % mods[t];
                ans += cnt[need];
                // cout << i << " " << j << " "; for(auto x : need) cout << x << " "; cout << endl;
            }
        }
        // cout << ans << endl << endl;
        return ans;
    };
    ll ans = 0;
    for(int i = 0; i < 3; i++) {
        auto X = M;
        for(int t = 0; t < num_mods; t++) X[t] = X[t] * 1ll * i % mods[t];
        ans += solve(X);
    }
    cout << int(ans) << '\n';
}

詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

4 1
0
1
10
17

output:


result: