QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#349440#8340. 3 Sumucup-team133#AC ✓298ms15092kbC++234.6kb2024-03-10 01:58:432024-10-13 18:48:34

Judging History

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

  • [2024-10-13 18:48:34]
  • 管理员手动重测本题所有得分≥97分的提交记录
  • 测评结果:AC
  • 用时:298ms
  • 内存:15092kb
  • [2024-09-20 10:20:30]
  • hack成功,自动添加数据
  • (/hack/848)
  • [2024-03-18 21:48:05]
  • hack成功,自动添加数据
  • (/hack/579)
  • [2024-03-18 21:45:33]
  • hack成功,自动添加数据
  • (/hack/578)
  • [2024-03-10 01:58:44]
  • 评测
  • 测评结果:100
  • 用时:283ms
  • 内存:15296kb
  • [2024-03-10 01:58:43]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

struct RandomNumberGenerator {
    std::mt19937 mt;

    RandomNumberGenerator() : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {}

    uint32_t operator()(uint32_t a, uint32_t b) {
        std::uniform_int_distribution<uint32_t> dist(a, b - 1);
        return dist(mt);
    }

    uint32_t operator()(uint32_t b) { return (*this)(0, b); }

    template <typename T> void shuffle(std::vector<T>& v) {
        for (int i = 0; i < int(v.size()); i++) std::swap(v[i], v[(*this)(0, i + 1)]);
    }
};

struct RandomNumberGenerator64 {
    std::mt19937_64 mt;

    RandomNumberGenerator64() : mt(std::chrono::steady_clock::now().time_since_epoch().count()) {}

    uint64_t operator()(uint64_t a, uint64_t b) {
        std::uniform_int_distribution<uint64_t> dist(a, b - 1);
        return dist(mt);
    }

    uint64_t operator()(uint64_t b) { return (*this)(0, b); }

    template <typename T> void shuffle(std::vector<T>& v) {
        for (int i = 0; i < int(v.size()); i++) std::swap(v[i], v[(*this)(0, i + 1)]);
    }
};

using namespace std;

typedef long long ll;
#define all(x) begin(x), end(x)
constexpr int INF = (1 << 30) - 1;
constexpr long long IINF = (1LL << 60) - 1;
constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

template <class T> istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template <class T> ostream& operator<<(ostream& os, const vector<T>& v) {
    auto sep = "";
    for (const auto& x : v) os << exchange(sep, " ") << x;
    return os;
}

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); }

template <class T> void mkuni(vector<T>& v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); }

string f(string s, int K) {  // s mod 10^K - 1
    if (K < 15) {
        ll sum = 0, mod = 1;
        for (int i = 0; i < K; i++) mod *= 10;
        mod -= 1;
        for (const char& c : s) sum = (sum * 10 + (c - '0')) % mod;
        if (sum == 0) return "";
        return to_string(sum);
    }
    ranges::reverse(s);
    int len = s.size();
    vector<string> v;
    for (int i = 0; i < len; i += K) v.emplace_back(s.substr(i, min(i + K, len) - i));
    string ans = "";
    int cur = 0;
    for (int i = 0; i < K or cur > 0; i++) {
        if (i < K) {
            for (int j = 0; j < int(v.size()); j++) {
                if (i < int(v[j].size())) {
                    cur += v[j][i] - '0';
                }
            }
        }
        ans += char('0' + cur % 10);
        cur /= 10;
    }
    while (not ans.empty() and ans.back() == '0') ans.pop_back();
    ranges::reverse(ans);
    if (int(ans.size()) > K) return f(ans, K);
    if (int(ans.size()) == K) {
        bool nine = true;
        for (const char& c : ans) nine &= (c == '9');
        if (nine) return "";
    }
    return ans;
}

const int MAX = 2;
using ARR = array<ll, MAX>;

ARR g(const string& s, const ARR& mod) {
    ARR res;
    for (int i = 0; i < MAX; i++) {
        ll sum = 0;
        for (const char& c : s) sum = (sum * 10 + (c - '0')) % mod[i];
        res[i] = sum;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, K;
    cin >> n >> K;
    vector<string> a;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        a.emplace_back(f(s, K));
    }

    int zero = 0;
    for (int i = 0; i < n; i++) zero += (a[i].empty());
    int ans = zero * (zero - 1) * (zero - 2) / 6 + zero * (zero - 1) + zero;

    string M(K, '9'), M2 = "1";
    for (int i = 0; i < K - 1; i++) M2 += '9';
    M2 += '8';

    RandomNumberGenerator64 rng;
    auto calc = [&](const string& target) -> int {
        ARR mod;
        for (int i = 0; i < MAX; i++) mod[i] = rng(1LL << 50);
        ARR goal = g(target, mod);
        vector<ARR> b(n);
        for (int i = 0; i < n; i++) b[i] = g(a[i], mod);
        int res = 0;
        for (int i = 0; i < n; i++) {
            map<array<ll, MAX>, int> mp;
            for (int j = i; j < n; j++) {
                mp[b[j]]++;
                ARR r;
                for (int k = 0; k < MAX; k++) r[k] = (mod[k] * 2 + goal[k] - b[i][k] - b[j][k]) % mod[k];
                if (mp.count(r)) res += mp[r];
            }
        }
        return res;
    };
    ans += calc(M) + calc(M2);

    cout << ans << '\n';
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 44ms
memory: 4200kb

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 298ms
memory: 15092kb

input:

500 17336
11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 75ms
memory: 3984kb

input:

500 1
751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...

output:

2327631

result:

ok 1 number(s): "2327631"

Test #5:

score: 0
Accepted
time: 88ms
memory: 3952kb

input:

500 2
408542968136435277974575411503179002415404345446801430469044749372949272333801248935236224652806667129749035002588943020176263162139056819871274824302889304493205266143688886696157147111754418731401856424401766968832165255416237731963027205324149660112574729610391396555581935236134531799950318...

output:

212002

result:

ok 1 number(s): "212002"

Test #6:

score: 0
Accepted
time: 214ms
memory: 12856kb

input:

500 11500
75411775796562109942642493394321873284995260953010112281856775261847503626737348402159485133662757032091519863427156582689971229143089317472838196453888261138079171290535429921921548971897026706656838415620603757605079012541561774699628665865662183868374645956694140356716037674688084770628...

output:

7675

result:

ok 1 number(s): "7675"

Test #7:

score: 0
Accepted
time: 222ms
memory: 12764kb

input:

500 11500
85355036663164764459816544518601485185320972076300982726542821424439713703229669576802138231401047471351087455159512255765325323540671792953715169122669767368905391325060775725733157611188832204902997772518104188947349204726490597030311894441123834099315122116302203972018409854605418988681...

output:

1070

result:

ok 1 number(s): "1070"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3708kb

input:

1 11500
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...

output:

1

result:

ok 1 number(s): "1"

Extra Test:

score: 0
Extra Test Passed