QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608939 | #8340. 3 Sum | yangrun | TL | 3ms | 5048kb | C++14 | 1.2kb | 2024-10-04 09:27:56 | 2024-10-04 09:27:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
const int N = 2e5 + 10;
const int P = 13333331;
const int b1 = 107, b2 = 233;
const int mod1 = 1e9 + 7, mod2 = 233333333;
pii in[N];
set<pii> hk;
pair<int, int> getHash(string s) {
int r1 = 0, r2 = 0;
for(int i = 0; s[i]; ++i) {
r1 = ((r1 * 10) + (s[i] - '0')) % mod1;
r2 = ((r2 * 10) + (s[i] - '0')) % mod2;
}
return {r1, r2};
}
pii add(pii a, pii b) {
return {(a.fi + b.fi) % mod1, (a.se + b.se) % mod2};
}
signed main() {
// cout << getHash("4").fi << '\n';
// cout << getHash("6").fi << '\n';
// cout << getHash("10").fi << '\n';
int n, k;
cin >> n >> k;
string s, sk(k, '9');
pii hk0 = getHash(sk), cur = {0, 0};
for(int i = 1; i <= 20000; i++) {
hk.insert(cur);
cur = add(cur, hk0);
}
for(int i = 1; i <= n; i++) {
cin >> s;
in[i] = getHash(s);
}
int res = 0;
for(int i = 1; i <= n; i++) {
for(int j = i; j <= n; j++) {
for(int k = j; k <= n; k++) {
cur = add(add(in[i], in[j]), in[k]);
res += hk.count(cur);
}
}
}
cout << res << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5048kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Time Limit Exceeded
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...