QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#349382#8340. 3 Sumucup-team133#TL 74ms4228kbC++234.3kb2024-03-10 01:29:282024-03-10 01:29:28

Judging History

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

  • [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:29:28]
  • 评测
  • 测评结果:TL
  • 用时:74ms
  • 内存:4228kb
  • [2024-03-10 01:29:28]
  • 提交

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
    ranges::reverse(s);
    while (int(s.size()) % K != 0) s += '0';
    vector<string> v;
    for (int i = 0; i < int(s.size()); i += K) v.emplace_back(s.substr(i, K));
    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++) {
                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 = 7;
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;
}

详细

Test #1:

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

input:

4 1
0
1
10
17

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 74ms
memory: 4228kb

input:

500 859
7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Time Limit Exceeded

input:

500 17336
11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...

output:


result: