QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#811 | #545030 | #8340. 3 Sum | hzjoiineg | pengpeng_fudan | Failed. | 2024-09-09 17:11:28 | 2024-09-09 17:11:29 |
Details
Extra Test:
Accepted
time: 127ms
memory: 3772kb
input:
498 2 1390618583 2340956823 3499519439 166081583 1867907929 852954158 596806664 934558851 2499812379 881875002 1422628735 3143643721 1154584777 245065750 3095940670 2426840630 798569004 442228014 3594564114 2693412468 1607815004 2063200549 2541059525 1154189351 1681168255 361099534 794849290 2452746...
output:
209530
result:
ok 1 number(s): "209530"
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#545030 | #8340. 3 Sum | pengpeng_fudan# | AC ✓ | 330ms | 4748kb | C++23 | 2.8kb | 2024-09-02 21:57:59 | 2024-10-13 18:54:53 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 550;
const int mod1 = 998244353;
const int mod2 = 1e9 + 7;
const int mod3 = 1e9 + 9;
int num1, num2, num3;
int n, k;
int m1, m2, m3;
int a1[N], a2[N], a3[N];
int ans = 0;
char a[100010];
int add(int x, int y, int mod) {
return x + y >= mod ? x + y - mod : x + y;
}
void solve() {
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
for (int k = j; k <= n; ++k) {
int x1 = add(add(a1[i], a1[j], mod1), a1[k], mod1);
int x2 = add(add(a2[i], a2[j], mod2), a2[k], mod2);
int x3 = add(add(a3[i], a3[j], mod3), a3[k], mod3);
if (x1 == m1 && x2 == m2 && x3 == m3) {
++ans;
}
}
}
}
}
void divv(int l, int r) {
if (r - l + 1 == k) return;
divv(l, r - k);
int pl = r - 2 * k + 1, pr = r - k;
// cerr << pl << ' ' << pr << '\n';
for (int i = pr + 1; i <= r; i++) a[i] = a[i] + a[i - k];
for (int i = pl; i <= pr; i++) a[i] = 0;
for (int i = r; i > pr; i--)
if (a[i] > 9) a[i] -= 10, a[i - 1]++;
while (a[pr] == 1) {
a[pr] = 0;
a[r]++;
for (int i = r; a[i] > 9; i--) a[i] -= 10, a[i - 1]++;
}
return;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
// char ch
scanf("%s", a + 1);
int len = strlen(a + 1), tlen = (len / k + (len % k > 0)) * k;
for (int i = len; i; i--) a[tlen - (len - i)] = a[i];
for (int i = 1; i <= tlen - len; i++) a[i] = '0';
for (int i = 1; i <= tlen; ++i) a[i] -= '0';
// cerr << '#' << ' ' ;
// for (int i = 1; i <= tlen; ++i) {
// cerr << (int)a[i] << ' ';
// }
// cerr << '\n';
divv(1, tlen);
for (int j = tlen - k + 1; j <= tlen; ++j) {
// cerr << (int)a[j] << ' ';
a1[i] = (1ll * a1[i] * 10 + 1ll * a[j]) % mod1;
a2[i] = (1ll * a2[i] * 10 + 1ll * a[j]) % mod2;
a3[i] = (1ll * a3[i] * 10 + 1ll * a[j]) % mod3;
}
// cerr << a1[i] <<'\n';
}
num1 = num2 = num3 = 0;
for (int i = 1; i <= k; ++i) {
num1 = (1ll * num1 * 10 + 1ll * 9) % mod1;
num2 = (1ll * num2 * 10 + 1ll * 9) % mod2;
num3 = (1ll * num3 * 10 + 1ll * 9) % mod3;
}
solve();
m1 = add(m1, num1, mod1), m2 = add(m2, num2, mod2), m3 = add(m3, num3, mod3);
solve();
m1 = add(m1, num1, mod1), m2 = add(m2, num2, mod2), m3 = add(m3, num3, mod3);
solve();
m1 = add(m1, num1, mod1), m2 = add(m2, num2, mod2), m3 = add(m3, num3, mod3);
solve();
printf("%d\n", ans);
return 0;
}