QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734674 | #8340. 3 Sum | Vegetable_Dog | TL | 377ms | 3900kb | C++23 | 2.5kb | 2024-11-11 14:02:02 | 2024-11-11 14:02:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define Rep(i, a, b) for (int i = a; i >= (b); i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define SZ(x) (int)(x.size())
#define lowbit(x) ((x) & -(x))
using db = double;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using i128 = __int128_t;
// Think twice, code once
using Hash = array<int, 5>;
const int N = 505, A = 1e9, M = 5, base = 131;
mt19937_64 rnd(14124152352365);
array<int, M> mod;
int n, k;
Hash hs[N];
Hash operator+(const Hash &a, const Hash &b) {
Hash c;
rep(i, 0, M) c[i] = (a[i] + b[i]) % mod[i];
return c;
}
Hash get_hash(vi a) {
Hash h{0, 0, 0, 0, 0};
reverse(all(a));
for (auto x : a) {
rep(i, 0, M) h[i] = (1ll * h[i] * base % mod[i] + x) % mod[i];
}
return h;
}
void get_mod(vi &a) {
while (SZ(a) > k) {
Rep(i, SZ(a) - 1, k) {
int t = a[i];
a[i - k] += t;
a.pop_back();
}
assert(SZ(a) == k);
int carry = 0;
rep(i, 0, k) {
int cur = a[i] + carry;
a[i] = cur % 10;
carry = cur / 10;
}
while (carry) {
a.pb(carry % 10);
carry /= 10;
}
}
if (a == vi(k, 9)) a = {0};
}
void trans(string s, int i) {
vi a;
for (auto c : s) a.pb(c - '0');
reverse(all(a));
get_mod(a);
hs[i] = get_hash(a);
}
void solve() {
uniform_int_distribution<int> dist(A / 2, A);
for (int i = 0; i < M; i++) {
mod[i] = dist(rnd);
}
cin >> n >> k;
Hash M0{0, 0, 0, 0, 0}, M1 = M0, M2 = M0;
rep(i, 0, k) {
rep(j, 0, M) M1[j] = (1ll * M1[j] * base % mod[j] + 9) % mod[j];
}
rep(i, 0, k + 1) {
rep(j, 0, M) M2[j] = (1ll * M2[j] * base % mod[j] + (!i ? 1 : i == k ? 8 : 9)) % mod[j];
}
rep(i, 0, n) {
string s; cin >> s;
trans(s, i);
}
int ans = 0;
rep(i, 0, n) rep(j, i, n) rep(k, j, n) {
Hash cur = hs[i] + hs[j] + hs[k];
if (cur == M0 || cur == M1 || cur == M2) ans++;
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3504kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 377ms
memory: 3900kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Time Limit Exceeded
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...