QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#468660 | #8340. 3 Sum | real_sigma_team# | WA | 341ms | 43908kb | C++23 | 3.3kb | 2024-07-08 22:19:33 | 2024-07-08 22:19:34 |
Judging History
answer
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
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;
}
int mod = 1e9+ 321;
int base = 11;
int add(int a, int b) {
return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a, int b) {
return a >= b ? a - b : a + mod - b;
}
int mul(int a, int b) {
return (__int128)a * b % mod;
}
bool lss(vector<int> a, vector<int> b) {
for (int i = (int)a.size() - 1; i >= 0; --i) {
if (a[i] != b[i]) return a[i] < b[i];
}
return false;
}
int nhash(vector<int> a) {
int pw = 1;
int 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 += 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';
while (a.size() > K) {
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];
}
}
int d = 0;
for (int j = 0; j < K; ++j) {
b[j] += d;
d = b[j] / 10;
b[j] %= 10;
}
if (d) b.push_back(d);
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<int, 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) {
int hh = add(ha[i], ha[j]);
if (j > k) hh = sub(hh, hmod);
ret += cnt[hh];
}
}
cout << ret;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
4 1 0 1 10 17
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 48ms
memory: 11096kb
input:
500 859 7118711592236878297922359501613604144948355616986970837340677671376753603836852811886591300370143151943368529129749813118476151865844255212534355441611481420938483178075143062691345257288242460282715389758789648541099090735875617822348551942134616963557723055980260082230902505269975518146286...
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 341ms
memory: 43908kb
input:
500 17336 11871159223687829792235950161360414494835561698697083734067767137675360383685281188659130037014315194336852912974981311847615186584425521253435544161148142093848317807514306269134525728824246028271538975878964854109909073587561782234855194213461696355772305598026008223090250526997551814628...
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 39ms
memory: 3736kb
input:
500 1 751324443898124078584847834484321089092662321556147445230263526014359393841194947303407593948729802551881289193716611867931891257925091769456350249725997883453296895094445731130479434019358742162771547784250401546380268386074363779242500860317042151185119666027858022664683818314351285215150806...
output:
1722634
result:
wrong answer 1st numbers differ - expected: '2327631', found: '1722634'