QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#468684#8340. 3 Sumreal_sigma_team#WA 0ms3608kbC++233.5kb2024-07-08 22:49:062024-07-08 22:49:06

Judging History

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

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

answer

#include<bits/stdc++.h>

using namespace std;

using ll = long long;

vector<int> operator+(vector<int> a, vector<int> b) {
    int d = 0;
    int sz = max(a.size(), b.size());
    a.resize(sz, 0);
    b.resize(sz, 0);
    for (int i = 0; i < sz; ++i) {
        a[i] += b[i] + d;
        if (a[i] < 10) d = 0;
        else d = 1, a[i] -= 10;
    }
    if (d) a.push_back(d);
    while (a.size() && a.back() == 0) a.pop_back();
    return a;
}
uint64_t mod = (1ll << 61) - 1;
uint64_t base = 13;

uint64_t add(uint64_t a, uint64_t b) {
    return a + b >= mod ? a + b - mod : a + b;
}

uint64_t sub(uint64_t a, uint64_t b) {
    return a >= b ? a - b : a + mod - b;
}

uint64_t mul(uint64_t a, uint64_t b) {
    return (__int128)a * b % mod;
}

bool lss(vector<int> a, vector<int> b) {
    int sz = max(a.size(), b.size());
    a.resize(sz, 0);
    b.resize(sz, 0);
    for (int i = (int)a.size() - 1; i >= 0; --i) {
        if (a[i] != b[i]) return a[i] < b[i];
    }
    return false;
}

uint64_t nhash(vector<int> a) {
    uint64_t pw = 1;
    uint64_t hsh = 0;
    for (auto i : a) {
        hsh = add(hsh, mul(i, pw));
        pw = mul(pw, base);
    }
    return hsh;
}

int nxt() {
    int x = 0;
    while (true) {
        auto c = getchar();
        if ('0' <= c && c <= '9') {
            x *= 10;
            x += c - '0';
        } else {
            break;
        }
    }
    return x;
}

int main() {
    int n = nxt(), K = nxt();
    vector<vector<int>> num(n);
    for (int i = 0; i < n; ++i) {
        string s;
        while (true) {
            auto c = getchar();
            if ('0' <= c && c <= '9') s.push_back(c);
            else break;
        }
        reverse(s.begin(), s.end());
        vector<int> a(s.size());
        for (int j = 0; j < s.size(); ++j) a[j] = s[j] - '0';
        vector<int> b(K, 0);
        for (int j = 0; j < K; ++j) {
            for (int c = j; c < a.size(); c += K) {
                b[j] += a[c];
            }
        }
        for (auto x : b) cout << x;
        cout << endl;
        int d = 0;
        while (true) {
            for (int j = 0; j < K; ++j) {
                b[j] += d;
                d = b[j] / 10;
                b[j] %= 10;
            }
            if (d == 0) break;
        }
        swap(a, b);
        if (*min_element(a.begin(), a.end()) == 9) fill(a.begin(), a.end(), 0);
        a.resize(K, 0);
        num[i] = a;
    }
    vector<int> MOD(K, 9);
    auto hmod = nhash(MOD);
    vector<int> p(n);
    iota(p.begin(), p.end(), 0);
    for (int i = 0; i < K; ++i) {
        vector<int> cnt(10);
        for (auto j : p) {
            cnt[num[j][i]]++;
        }
        for (int j = 1; j < 10; ++j) cnt[j] += cnt[j - 1];
        vector<int> q(n);
        reverse(p.begin(), p.end());
        for (auto j : p) {
            q[--cnt[num[j][i]]] = j; 
        }
        p = q;
    }
    vector<int> ha(n);
    for (int i = 0; i < n; ++i) ha[i] = nhash(num[p[i]]);
    map<uint64_t, int> cnt;
    int ret = 0;
    for (int i = 0, k = n - 1; i < n; ++i) {
        auto hha = ha[i];
        if (*max_element(num[i].begin(), num[i].end()) != 0) hha = sub(hmod, hha);
        cnt[hha]++;
        while (k >= 0 && !lss(num[p[i]] + num[p[k]], MOD)) k--;
        for (int j = i; j < n; ++j) {
            uint64_t hh = add(ha[i], ha[j]);
            if (j > k) hh = sub(hh, hmod);
            ret += cnt[hh];
        }
    }
    cout << ret;
}

詳細信息

Test #1:

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

input:

4 1
0
1
10
17

output:

0
1
1
8
3

result:

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