QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#191839 | #5014. 复读程度 | hos_lyric# | 40 | 2364ms | 698352kb | C++14 | 19.0kb | 2023-09-30 11:35:42 | 2024-07-04 02:12:25 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
template <class T> void bAdd(vector<T> &bit, int pos, const T &val) {
const int bitN = bit.size();
for (int x = pos; x < bitN; x |= x + 1) bit[x] += val;
}
template <class T> T bSum(const vector<T> &bit, int pos) {
T ret = 0;
for (int x = pos; x > 0; x &= x - 1) ret += bit[x - 1];
return ret;
}
template <class T> T bSum(const vector<T> &bit, int pos0, int pos1) {
return bSum(bit, pos1) - bSum(bit, pos0);
}
////////////////////////////////////////////////////////////////////////////////
// SA-IS
// String: string, vector<int>, vector<long long>
// if sigma <= n, O(n) time, O(n) space
// if sigma > n, O(n log n) time, O(n) space
template <class String> vector<int> suffixArrayRec(const String &as) {
const int n = as.size();
if (n == 0) return {};
const auto minmaxA = minmax_element(as.begin(), as.end());
const auto minA = *minmaxA.first, maxA = *minmaxA.second;
if (static_cast<unsigned long long>(maxA) - minA >=
static_cast<unsigned long long>(n)) {
vector<int> us(n);
for (int u = 0; u < n; ++u) us[u] = u;
std::sort(us.begin(), us.end(), [&](int u, int v) -> bool {
return (as[u] < as[v]);
});
int b = 0;
vector<int> bs(n, 0);
for (int i = 1; i < n; ++i) {
if (as[us[i - 1]] != as[us[i]]) ++b;
bs[us[i]] = b;
}
return suffixArrayRec(bs);
}
const int sigma = maxA - minA + 1;
vector<int> pt(sigma + 1, 0), poss(sigma);
for (int u = 0; u < n; ++u) ++pt[as[u] - minA + 1];
for (int a = 0; a < sigma; ++a) pt[a + 1] += pt[a];
// cmp[u] := (as[u, n) < as[u + 1, n))
vector<bool> cmp(n);
cmp[n - 1] = false;
for (int u = n - 1; --u >= 0; ) {
cmp[u] = (as[u] != as[u + 1]) ? (as[u] < as[u + 1]) : cmp[u + 1];
}
// ><, nn - id (0 <= id < n)
int nn = 0;
vector<int> ids(n, 0);
int last = n;
vector<int> nxt(n, 0);
// put ><, from the tail of each bucket
vector<int> us(n, 0);
memcpy(poss.data(), pt.data() + 1, sigma * sizeof(int));
for (int u = n - 1; --u >= 1; ) if (!cmp[u - 1] && cmp[u]) {
ids[u] = ++nn;
nxt[u] = last;
last = u;
us[--poss[as[u] - minA]] = u;
}
// follow > backwards, from the head of each bucket
memcpy(poss.data(), pt.data(), sigma * sizeof(int));
us[poss[as[n - 1] - minA]++] = n - 1;
for (int i = 0; i < n; ++i) {
const int u = us[i];
if (u && !cmp[u - 1]) us[poss[as[u - 1] - minA]++] = u - 1;
}
// follow < backwards, from the tail of each bucket
memcpy(poss.data(), pt.data() + 1, sigma * sizeof(int));
for (int i = n; --i >= 0; ) {
const int u = us[i];
if (u && cmp[u - 1]) us[--poss[as[u - 1] - minA]] = u - 1;
}
if (nn) {
int vsLen = 0;
vector<int> vs(nn);
for (const int u : us) if (ids[u]) vs[vsLen++] = u;
int b = 0;
vector<int> bs(nn, 0);
for (int j = 1; j < nn; ++j) {
// as[v1, w1] (< or =) as[v0, w0]
int v1 = vs[j - 1], v0 = vs[j];
const int w1 = nxt[v1], w0 = nxt[v0];
if (w1 - v1 != w0 - v0) {
++b;
} else {
for (; ; ++v1, ++v0) {
if (v1 == n) { ++b; break; }
if (as[v1] != as[v0]) { ++b; break; }
if (v1 == w1) break;
}
}
bs[nn - ids[vs[j]]] = b;
}
for (int u = 0; u < n; ++u) if (ids[u]) vs[nn - ids[u]] = u;
const auto sub = suffixArrayRec(bs);
// put ><, from the tail of each bucket
memset(us.data(), 0, n * sizeof(int));
memcpy(poss.data(), pt.data() + 1, sigma * sizeof(int));
for (int j = nn; --j >= 0; ) {
const int u = vs[sub[j]];
us[--poss[as[u] - minA]] = u;
}
// follow > backwards, from the head of each bucket
memcpy(poss.data(), pt.data(), sigma * sizeof(int));
us[poss[as[n - 1] - minA]++] = n - 1;
for (int i = 0; i < n; ++i) {
const int u = us[i];
if (u && !cmp[u - 1]) us[poss[as[u - 1] - minA]++] = u - 1;
}
// follow < backwards, from the tail of each bucket
memcpy(poss.data(), pt.data() + 1, sigma * sizeof(int));
for (int i = n; --i >= 0; ) {
const int u = us[i];
if (u && cmp[u - 1]) us[--poss[as[u - 1] - minA]] = u - 1;
}
}
return us;
}
// us[i]: i-th suffix
// su[u]: index of as[u, n)
// hs[i]: longest common prefix of as[us[i - 1], n) and as[us[i], n)
struct SuffixArray {
int n;
bool rmq;
vector<int> us, su, hs, bsr;
SuffixArray() : n(0), rmq(false) {}
SuffixArray(const string &as, bool rmq_) : rmq(rmq_) { build(as); }
SuffixArray(const vector<int> &as, bool rmq_) : rmq(rmq_) { build(as); }
SuffixArray(const vector<long long> &as, bool rmq_) : rmq(rmq_) { build(as); }
template <class String> void build(const String &as) {
n = as.size();
us = suffixArrayRec(as);
su.resize(n + 1);
for (int i = 0; i < n; ++i) su[us[i]] = i;
su[n] = -1;
hs.assign(n, 0);
for (int h = 0, u = 0; u < n; ++u) if (su[u]) {
for (int v = us[su[u] - 1]; v + h < n && as[v + h] == as[u + h]; ++h) {}
hs[su[u]] = h;
if (h) --h;
}
if (rmq) {
const int logN = n ? (31 - __builtin_clz(n)) : 0;
hs.resize((logN + 1) * n - (1 << logN) + 1);
for (int e = 0; e < logN; ++e) {
int *hes = hs.data() + e * n;
for (int i = 0; i <= n - (1 << (e + 1)); ++i) {
hes[n + i] = min(hes[i], hes[i + (1 << e)]);
}
}
bsr.resize(n + 1);
bsr[0] = -1;
for (int i = 1; i <= n; ++i) bsr[i] = bsr[i >> 1] + 1;
}
}
// Returns longest common prefix of as[u, n) and as[v, n).
// 0 <= u, v <= n
// Assumes rmq.
inline int lcp(int u, int v) const {
if (u == v) return n - u;
int i = su[u], j = su[v];
if (i > j) swap(i, j);
const int e = bsr[j - i];
return min(hs[e * n + i + 1], hs[e * n + j + 1 - (1 << e)]);
}
};
////////////////////////////////////////////////////////////////////////////////
/*
len: depth in uncompacted suffix tree of the reversed string
par: parent in compacted suffix tree of the reversed string
prev: node from which it is cloned
ll: whole length of the string when created
node u: length in (nodes[nodes[u].par].len, nodes[u].len]
*/
////////////////////////////////////////////////////////////////////////////////
template <class Char, class Map = map<Char, int>> struct SuffixAutomaton {
struct Node {
int len, par, prev;
Map next;
int ll;
};
int l, n, cur;
vector<Node> nodes;
SuffixAutomaton() : l(0), n(1), cur(0), nodes{Node{
/*len=*/0, /*par=*/-1, /*prev=*/-1, /*next=*/{},
/*ll=*/0,
}} {}
Node &operator[](int u) { return nodes[u]; }
void append(Char c) {
++l;
int u = cur;
cur = n++;
nodes.push_back(Node{
/*len=*/nodes[u].len + 1, /*par=*/0, /*prev=*/-1, /*next=*/{},
/*ll=*/l,
});
for (; ~u && !nodes[u].next.count(c); u = nodes[u].par) {
nodes[u].next[c] = cur;
}
if (~u) {
const int v = nodes[u].next[c];
if (nodes[u].len + 1 == nodes[v].len) {
nodes[cur].par = v;
} else {
const int w = n++;
nodes.push_back(Node{
/*len=*/nodes[u].len + 1, /*par=*/nodes[v].par, /*prev=*/v,
/*next=*/nodes[v].next,
/*ll=*/l,
});
nodes[v].par = nodes[cur].par = w;
for (; ~u && nodes[u].next[c] == v; u = nodes[u].par) {
nodes[u].next[c] = w;
}
}
}
}
};
////////////////////////////////////////////////////////////////////////////////
struct Map {
int as[26];
Map() { memset(as, ~0, sizeof(as)); }
int &operator[](char c) { return as[c - 'a']; }
int count(char c) { return (~as[c - 'a']) ? 1 : 0; }
};
using U = unsigned long long;
int N, Q;
char S[100'010];
vector<U> WL, WR;
vector<int> L1, R1, L2, R2;
namespace brute {
int dpL[5010][5010], dpR[5010][5010];
U W[5010][5010];
vector<U> run() {
cerr<<"[brute::run]"<<endl;
memset(dpL, 0, sizeof(dpL));
memset(dpR, 0, sizeof(dpR));
for (int i = N; --i >= 0; ) for (int j = N; --j >= 0; ) if (S[i] == S[j]) dpL[i][j] = 1 + dpL[i + 1][j + 1];
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (S[i] == S[j]) dpR[i + 1][j + 1] = dpR[i][j] + 1;
memset(W, 0, sizeof(W));
for (int l = 0; l <= N; ++l) for (int r = l + 1; r <= N; ++r) W[l][r] = 1;
for (int l = 0; l < N; ++l) {
vector<U> sums(N - l + 1, 0);
for (int i = 0; i < N; ++i) sums[dpL[l][i]] += WL[i];
for (int k = N - l; k >= 1; --k) sums[k - 1] += sums[k];
for (int r = l + 1; r <= N; ++r) W[l][r] *= sums[r - l];
}
for (int r = 1; r <= N; ++r) {
vector<U> sums(r + 1, 0);
for (int i = 1; i <= N; ++i) sums[dpR[r][i]] += WR[i];
for (int k = r; k >= 1; --k) sums[k - 1] += sums[k];
for (int l = 0; l < r; ++l) W[l][r] *= sums[r - l];
}
// for(int l=0;l<=N;++l){cerr<<"W["<<l<<"] = ";pv(W[l],W[l]+N+1);}
vector<U> ans(Q, 0);
for (int q = 0; q < Q; ++q) {
const int need = max(R1[q] - L1[q], R2[q] - L2[q]);
for (int l = 0; l <= N; ++l) for (int r = l + need; r <= N; ++r) {
if (dpL[L1[q]][l] >= R1[q] - L1[q] && dpR[R2[q]][r] >= R2[q] - L2[q]) {
ans[q] += W[l][r];
}
}
}
return ans;
}
} // brute
namespace slow {
int dpL[5010][5010], dpR[5010][5010];
U W[5010][5010];
vector<vector<int>> graph;
int zeit;
vector<int> dis, fin;
void dfs(int u) {
dis[u] = zeit++;
for (const int v : graph[u]) dfs(v);
fin[u] = zeit;
}
vector<U> run() {
cerr<<"[slow::run]"<<endl;
memset(dpL, 0, sizeof(dpL));
memset(dpR, 0, sizeof(dpR));
for (int i = N; --i >= 0; ) for (int j = N; --j >= 0; ) if (S[i] == S[j]) dpL[i][j] = 1 + dpL[i + 1][j + 1];
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (S[i] == S[j]) dpR[i + 1][j + 1] = dpR[i][j] + 1;
memset(W, 0, sizeof(W));
for (int l = 0; l <= N; ++l) for (int r = l + 1; r <= N; ++r) W[l][r] = 1;
for (int l = 0; l < N; ++l) {
vector<U> sums(N - l + 1, 0);
for (int i = 0; i < N; ++i) sums[dpL[l][i]] += WL[i];
for (int k = N - l; k >= 1; --k) sums[k - 1] += sums[k];
for (int r = l + 1; r <= N; ++r) W[l][r] *= sums[r - l];
}
for (int r = 1; r <= N; ++r) {
vector<U> sums(r + 1, 0);
for (int i = 1; i <= N; ++i) sums[dpR[r][i]] += WR[i];
for (int k = r; k >= 1; --k) sums[k - 1] += sums[k];
for (int l = 0; l < r; ++l) W[l][r] *= sums[r - l];
}
// for(int l=0;l<=N;++l){cerr<<"W["<<l<<"] = ";pv(W[l],W[l]+N+1);}
SuffixAutomaton<char, Map> sam;
for (int i = 0; i < N; ++i) {
sam.append(S[i]);
}
graph.assign(sam.n, {});
for (int u = 1; u < sam.n; ++u) {
graph[sam[u].par].push_back(u);
}
zeit = 0;
dis.assign(sam.n, -1);
fin.assign(sam.n, -1);
dfs(0);
vector<int> prefix(N + 1, 0);
for (int i = 0; i < N; ++i) {
prefix[i + 1] = sam[prefix[i]].next[S[i]];
}
vector<int> query(Q, 0);
for (int q = 0; q < Q; ++q) {
int &u = query[q];
for (int i = L2[q]; i < R2[q]; ++i) {
u = sam[u].next[S[i]];
}
}
vector<vector<int>> qss(N + 1);
for (int q = 0; q < Q; ++q) {
qss[max(R1[q] - L1[q], R2[q] - L2[q])].push_back(q);
}
vector<U> ans(Q, 0);
for (int l = 0; l < N; ++l) {
vector<U> bit(sam.n, 0);
for (int r = N; r > l; --r) {
bAdd(bit, dis[prefix[r]], W[l][r]);
for (const int q : qss[r - l]) {
if (dpL[L1[q]][l] >= R1[q] - L1[q]) {
ans[q] += bSum(bit, dis[query[q]], fin[query[q]]);
}
}
}
}
return ans;
}
} // slow
namespace slow2d {
int dpL[5010][5010], dpR[5010][5010];
U W[5010][5010];
int ids[5010][5010];
vector<vector<int>> graph;
int zeit;
vector<int> dis, fin;
void dfs(int u) {
dis[u] = zeit++;
for (const int v : graph[u]) dfs(v);
fin[u] = zeit;
}
U bit[5010][5010];
void add(int x0, int y0, U val) {
for (int x = x0; x < N; x |= x + 1) for (int y = y0; y < N; y |= y + 1) bit[x][y] += val;
}
U get(int x0, int y0) {
U ret = 0;
for (int x = x0; x; x &= x - 1) for (int y = y0; y; y &= y - 1) ret += bit[x - 1][y - 1];
return ret;
}
vector<U> run() {
cerr<<"[slow2d::run]"<<endl;
memset(dpL, 0, sizeof(dpL));
memset(dpR, 0, sizeof(dpR));
for (int i = N; --i >= 0; ) for (int j = N; --j >= 0; ) if (S[i] == S[j]) dpL[i][j] = 1 + dpL[i + 1][j + 1];
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (S[i] == S[j]) dpR[i + 1][j + 1] = dpR[i][j] + 1;
memset(W, 0, sizeof(W));
for (int l = 0; l <= N; ++l) for (int r = l + 1; r <= N; ++r) W[l][r] = 1;
for (int l = 0; l < N; ++l) {
vector<U> sums(N - l + 1, 0);
for (int i = 0; i < N; ++i) sums[dpL[l][i]] += WL[i];
for (int k = N - l; k >= 1; --k) sums[k - 1] += sums[k];
for (int r = l + 1; r <= N; ++r) W[l][r] *= sums[r - l];
}
for (int r = 1; r <= N; ++r) {
vector<U> sums(r + 1, 0);
for (int i = 1; i <= N; ++i) sums[dpR[r][i]] += WR[i];
for (int k = r; k >= 1; --k) sums[k - 1] += sums[k];
for (int l = 0; l < r; ++l) W[l][r] *= sums[r - l];
}
// for(int l=0;l<=N;++l){cerr<<"W["<<l<<"] = ";pv(W[l],W[l]+N+1);}
vector<int> xs(N + 1, -1), ys(N + 1, -1);
vector<int> x0s(Q), x1s(Q), y0s(Q), y1s(Q);
{
SuffixAutomaton<char, Map> sam;
for (int i = N; --i >= 0; ) sam.append(S[i]);
graph.assign(sam.n, {});
for (int u = 1; u < sam.n; ++u) graph[sam[u].par].push_back(u);
zeit = 0;
dis.assign(sam.n, -1);
fin.assign(sam.n, -1);
dfs(0);
vector<int> suffix(N + 1, 0);
for (int i = N; --i >= 0; ) suffix[i] = sam[suffix[i + 1]].next[S[i]];
vector<int> ds;
for (int l = 0; l < N; ++l) ds.push_back(dis[suffix[l]]);
sort(ds.begin(), ds.end());
for (int l = 0; l < N; ++l) xs[l] = lower_bound(ds.begin(), ds.end(), dis[suffix[l]]) - ds.begin();
for (int r = 0; r <= N; ++r) {
ids[r][r] = 0;
for (int i = r; --i >= 0; ) ids[r][i] = sam[ids[r][i + 1]].next[S[i]];
}
for (int q = 0; q < Q; ++q) {
const int u = ids[R1[q]][L1[q]];
x0s[q] = lower_bound(ds.begin(), ds.end(), dis[u]) - ds.begin();
x1s[q] = lower_bound(ds.begin(), ds.end(), fin[u]) - ds.begin();
}
}
{
SuffixAutomaton<char, Map> sam;
for (int i = 0; i < N; ++i) sam.append(S[i]);
graph.assign(sam.n, {});
for (int u = 1; u < sam.n; ++u) graph[sam[u].par].push_back(u);
zeit = 0;
dis.assign(sam.n, -1);
fin.assign(sam.n, -1);
dfs(0);
vector<int> prefix(N + 1, 0);
for (int i = 0; i < N; ++i) prefix[i + 1] = sam[prefix[i]].next[S[i]];
vector<int> ds;
for (int r = 1; r <= N; ++r) ds.push_back(dis[prefix[r]]);
sort(ds.begin(), ds.end());
for (int r = 1; r <= N; ++r) ys[r] = lower_bound(ds.begin(), ds.end(), dis[prefix[r]]) - ds.begin();
for (int l = 0; l <= N; ++l) {
ids[l][l] = 0;
for (int i = l; i < N; ++i) ids[l][i + 1] = sam[ids[l][i]].next[S[i]];
}
for (int q = 0; q < Q; ++q) {
const int u = ids[L2[q]][R2[q]];
y0s[q] = lower_bound(ds.begin(), ds.end(), dis[u]) - ds.begin();
y1s[q] = lower_bound(ds.begin(), ds.end(), fin[u]) - ds.begin();
}
}
vector<vector<int>> qss(N + 1);
for (int q = 0; q < Q; ++q) {
qss[max(R1[q] - L1[q], R2[q] - L2[q])].push_back(q);
}
vector<U> ans(Q, 0);
/*
for (int q = 0; q < Q; ++q) {
const int need = max(R1[q] - L1[q], R2[q] - L2[q]);
for (int l = 0; l < N; ++l) for (int r = l + need; r <= N; ++r) {
if (x0s[q] <= xs[l] && xs[l] < x1s[q] &&
y0s[q] <= ys[r] && ys[r] < y1s[q]) {
ans[q] += W[l][r];
}
}
}
*/
memset(bit, 0, sizeof(bit));
for (int k = N; k > 0; --k) {
for (int l = 0; l <= N - k; ++l) {
const int r = l + k;
add(xs[l], ys[r], W[l][r]);
}
for (const int q : qss[k]) {
ans[q] += get(x0s[q], y0s[q]);
ans[q] -= get(x0s[q], y1s[q]);
ans[q] -= get(x1s[q], y0s[q]);
ans[q] += get(x1s[q], y1s[q]);
}
}
return ans;
}
} // slow2d
namespace sub4 {
vector<U> run() {
cerr<<"[sub4::run]"<<endl;
string revS = S;
reverse(revS.begin(), revS.end());
const SuffixArray sa(revS, true);
vector<vector<int>> qss(N + 1);
for (int q = 0; q < Q; ++q) {
qss[max(R1[q] - L1[q], R2[q] - L2[q])].push_back(q);
}
vector<U> bit(N, 0);
vector<U> ans(Q, 0);
for (int r = N; r > 0; --r) {
bAdd(bit, sa.su[N - r], WL[0] * WR[r]);
for (const int q : qss[r]) {
int posL, posR;
{
int lo = -1, hi = sa.su[N - R2[q]];
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
((sa.lcp(sa.us[mid], N - R2[q]) >= R2[q] - L2[q]) ? hi : lo) = mid;
}
posL = hi;
}
{
int lo = sa.su[N - R2[q]], hi = N;
for (; lo + 1 < hi; ) {
const int mid = (lo + hi) / 2;
((sa.lcp(sa.us[mid], N - R2[q]) >= R2[q] - L2[q]) ? lo : hi) = mid;
}
posR = lo;
}
ans[q] += bSum(bit, posL, posR + 1);
}
}
return ans;
}
} // sub4
int main() {
for (; ~scanf("%d%d", &N, &Q); ) {
scanf("%s", S);
WL.assign(N + 1, 0);
for (int i = 0; i < N; ++i) {
scanf("%llu", &WL[i]);
}
WR.assign(N + 1, 0);
for (int i = 1; i <= N; ++i) {
scanf("%llu", &WR[i]);
}
L1.resize(Q);
R1.resize(Q);
L2.resize(Q);
R2.resize(Q);
for (int q = 0; q < Q; ++q) {
scanf("%d%d%d%d", &L1[q], &R1[q], &L2[q], &R2[q]);
--L1[q];
--L2[q];
}
bool spe4 = true;
spe4 = spe4 && (L1 == vector<int>(Q, 0));
// ?
// for (int i = 1; i < N; ++i) spe4 = spe4 && (S[0] != S[i]);
vector<U> ans;
if (N <= 5000) {
ans = slow2d::run();
} else if (spe4) {
ans = sub4::run();
} else {
assert(false);
}
for (int q = 0; q < Q; ++q) {
printf("%llu\n", ans[q]);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 24ms
memory: 606184kb
input:
500 500 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
15720454042420499810 4058077030882532408 14651762045124606089 4030024243931986061 18033423360813892607 9470601111824364484 3883374861354698625 16650831689368240202 8339028189650687576 2683289915379600554 13133811958066776394 14181220923901262251 18173739360450512256 13142314545999179754 148925491596...
result:
ok 500 lines
Test #2:
score: 0
Accepted
time: 39ms
memory: 605052kb
input:
500 500 zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszz...
output:
4843650749197240262 7777110205341291111 533576317536031175 16712994243500559204 9988085877723856684 9644193924482321332 3247342125341043527 18152622312040037224 13045121434804725850 10593529771756855740 13316626648976199221 6181092693273210423 9148547538129213975 9376364571107435561 2140403332478526...
result:
ok 500 lines
Test #3:
score: 0
Accepted
time: 36ms
memory: 606544kb
input:
500 500 aaaaabbaabbabbbaabaabbabbabbbaaabaaaabbbbbbaaabaabbbbbbaabbaaaaababbaaaaabbbbababbabaabbbbbbbbaaaaaaabaabbabbbbaabbaabaaabbbabbaabbbabaabaaaaababbaabbabbbabbababbbaabbabaaabbbbaaabbbabbabaabbabbaaabbaabbabbbbaaaaaababaaaabaababbaabbabbabbbabbaabbbaabbaaababaaabbababbbabaababaabbbbbabbababaab...
output:
841375054012212333 13406426787139944226 6541986259052503362 10583258635957015782 11582649090627508617 4747829250201069768 11571422754704651998 14603866222879735665 8438246043626601023 16155298152184479844 9052925087624568857 18388444310571976215 13304308468056840286 18125780089857220122 363421144082...
result:
ok 500 lines
Test #4:
score: 0
Accepted
time: 35ms
memory: 604700kb
input:
500 500 sulasusulasusulasulasulsulasusulasususulasulasulsulasulasulsulasulasulsulasususulasulasulsulasulasulsulasulasulsulasusulasulasulsulasulasulsulasulasulsulasusulasulasulsulasulasulsulasulasulsulasulasulsulasususulasulasulsulasulasulsulasulasulsulasusulasulasulsulasulasulsulasusulasusulasusulas...
output:
2320755102639148175 17108462705447992416 6030359132551843296 889683039894413148 10901851555398837076 1991544941914879425 9087724446342520941 5134546535199286414 12947484109492427089 5962550827492657739 4877066450610765849 6699323319072695780 11167645157062070624 13985172887966350800 8075429763917070...
result:
ok 500 lines
Test #5:
score: 0
Accepted
time: 27ms
memory: 604756kb
input:
500 500 bbbbbbqouvtudkzorrxinacvncytgmtbbbbbbfyfzxjdqlcaadccvsbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbfyfzxjdqlcaadccvsbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbfyfzxjdqlcaadccvsbbbbbbqouvtudkzorrxinacvncytgmtbbbbbbbbbbbbqouvtudkzorrx...
output:
18295637548117042088 6105463594888898313 15681140870484623884 17957090271580958329 11763132903578154240 17769627666201366836 16493946443969420940 12712093409624537595 2436698665645215125 8863273927617841787 5065586857868462806 8771649105206144878 6715985691821336097 8851433094837196039 7055234226266...
result:
ok 500 lines
Test #6:
score: 0
Accepted
time: 36ms
memory: 605824kb
input:
500 500 yyyayyayyyayyayyyayyayyyayyyayyyayyayyyyayyayyyayyyayyayyyayyyayyayyayyyyayyyayyyayyayyayyyayyayyayyyayyayyayyyayyyyyayyayyyyayyayyyayyayyyayyyayyyayyayyyayyayyyyayyyayyayyayyyayyayyyayyyyayyyyayyayyyayyayyayyyayyayyayyyyayyayyyayyayyayyyayyyyayyayyayyyayyayyayyyayyayyayyyyayyyayyyayyyyayyay...
output:
6159560444195180556 5294852391541430076 6195718271241091926 7959984071139675340 1598729415848168155 4879964117998052348 2279721248493220290 2026655128556749470 9803272548967597498 1028236064772678471 5410852487707111065 3600180224455323043 60239358603452318 2179897463397058094 16626503365867372202 3...
result:
ok 500 lines
Test #7:
score: 0
Accepted
time: 20ms
memory: 604720kb
input:
500 500 fffffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqiffffffxfqifffnmogfffxfqifffffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqifffffffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqifffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfffxfqiffffffffxfqifffnmogfff...
output:
6263422992304461664 10533199195660359295 11930245273187149005 380050211417129795 8399013088311259527 7005867409130681392 6872331929648615383 11661502418569897193 18027795221888639599 8932010711134684820 6331436398298306214 14599171184201697655 16632037523890780117 10373998601812781913 16089838760431...
result:
ok 500 lines
Subtask #2:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #8:
score: 15
Accepted
time: 1010ms
memory: 691544kb
input:
5000 5000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
12046186417900804485 3907200386448639860 16785470842023310270 13867397394972404837 17085398553187209926 11495532885795119226 12151570815045120790 4174337022608077877 6326694597133262496 5169007805286709535 14463367619086789683 627371028328452442 16378439470252322552 8286285259552634235 4646456254657...
result:
ok 5000 lines
Test #9:
score: 0
Accepted
time: 2010ms
memory: 692056kb
input:
5000 5000 zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzs...
output:
735272585091871492 2425556370857741242 8489901764977622765 9888756352722135114 3110111362923242403 9113727892967247055 13146817111311386931 5955980702194075793 11763307103994511020 11636340521260903139 13880517640770645879 18280247001976771986 9041182678245966519 902847942097731925 17037540142883387...
result:
ok 5000 lines
Test #10:
score: 0
Accepted
time: 2235ms
memory: 691676kb
input:
5000 5000 bababbaabbbbbabbabaababbbaabababbbbaaabbaabbbbaaabaaaaabbababaababbbabbabbaaabbaaaaaababbababbbbbabbbbbaaabbabababaaababbababaabaaaaaabaaabbabaaaabaabaaaaaabbaaaaaaabbbbbabbabababbbabababaabaabbbbbabaabbbaaabbaaababbabaabaabbababaaaaaaabaaaabaabbbabbaaaababbabbaaabbbbabbabbaabbabbbbabaabbb...
output:
14997976760389310587 15623438489514479805 3150343034406864174 3816221098639928267 9378704101760633024 7513129444188437491 13447233088170491140 9761793475353455477 14533020333667464089 3755460369265761557 1017346093533703703 13617526768501762999 3768834851789866303 6158131626925412903 362975187944345...
result:
ok 5000 lines
Test #11:
score: 0
Accepted
time: 2159ms
memory: 692660kb
input:
5000 5000 faffafimufxzbzetkfeqjfaffafxwgaqswmswhlkteloiarwwdafaffafimufxzbzetkfeqjfaffaffaffafimufxzbzetkfeqjfaffafxwgaqfaffafimufxzbzetkfeqjfaffafxwgaqswmswhlkteloiarwwdafaffafimufxzbzetkfeqjfaffaffaffafimufxzbzetkfeqjfaffafxwgaqswmswhlkteloiarwwdafaffafimufxzbzetkfeqjfaffaffaffafimufxzbzetkfeqjfaf...
output:
1845388242333177970 9831947454379400267 1031368185674017505 7263197708536716267 14239370791222150808 146482920919415220 17250529541921412624 16073012951843647214 14426094333257632462 9475986787147068259 17618123199330645299 7007181348027660953 7868744985222980634 24008326611725469 109704767314001231...
result:
ok 5000 lines
Test #12:
score: 0
Accepted
time: 2203ms
memory: 693996kb
input:
5000 5000 rreurrrrkodwxsvtckttkrreurrrrtvjqcbspphhcmqjjadnkvdhavzhasjorreurrrrkodwxsvtckttkrreurrrrdhzorreurrrrkodwxsvtckttkrreurrrrtvjqcbspphhcmqjjadnkvdhavzhasjorreurrrrkodwxsvtckttkrreurrrrxgpkocctymfhcjougjsvimxuwczjxyhasapncenwpvkvtrmcdhkfjmndumgccngxginwyjhwexjeujrnvfaznvonweytryeeoocesoxavgaw...
output:
11585208823777493396 6508373161762025375 8952030838195753202 1744593196955201879 7361869313836500243 4211703722346758091 11507326811546869387 12152026172660216436 6502452509264613488 16456537462830488502 7769483154726766332 5049920983662723085 6208254085958990276 1561961237223372279 2581189727041718...
result:
ok 5000 lines
Test #13:
score: 0
Accepted
time: 2266ms
memory: 694388kb
input:
5000 5000 bdybdbdybdbdybbdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdybdbdybdybdbdybdbdybbdybdbdybdybdbdybdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdbdybbdybdbdybdbdybbdybdbdybdybdbdybdbdybbdybdbdybdybdb...
output:
15484750028865001809 11154229346905269019 17415778058314228645 12967502341758445430 14197547387946783600 16593119823307221414 3430123628603013461 15944735630911629097 3372966924712269006 16370170534370111687 7776152546511005126 10081736260495879969 3361043444817366723 14159037165445633566 4790222378...
result:
ok 5000 lines
Test #14:
score: 0
Accepted
time: 2196ms
memory: 692656kb
input:
5000 5000 gskozovzgkcfxgrjipkmaurpgskozovzgkcfxuetjsdskistgkrkxbvpwljcjmnamkcdqmeteslgskozovzgkcfxgrjipkmaurpgskozovzgkcfxgskozovzgkcfxgrjipkmaurpgskozovzgkcfxuetjsdskistgkrkgskozovzgkcfxgrjipkmaurpgskozovzgkcfxuetjsdskistgkrkxbvpwljcjmnamkcdqmeteslgskozovzgkcfxgrjipkmaurpgskozovzgkcfxgskozovzgkcfxg...
output:
5804930040756324744 15650208817097681461 11355021187259627510 6741010156229702848 11225541410427015147 1272653894362217625 8025793205090026227 17985669688971641284 17805739950886098400 15447039299473890938 13822612697353510946 16409494890413019301 10397340813113479673 11748441386197961568 1796390231...
result:
ok 5000 lines
Subtask #3:
score: 12
Accepted
Dependency #2:
100%
Accepted
Test #15:
score: 12
Accepted
time: 1084ms
memory: 696604kb
input:
5000 100000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
5845120425902525283 8990351971173725430 14941690660751686216 784971306663465014 14729108738538674226 9552307739797797498 3551599368844499432 3212787150504387790 8594382131237834529 16887368685328314652 5586192237324217034 12381470524748547090 1961055982585971300 13257376816999825159 3385756250295802...
result:
ok 100000 lines
Test #16:
score: 0
Accepted
time: 2198ms
memory: 695524kb
input:
5000 100000 zszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszszzszzszszzszzszszzszszzszzszszzszsz...
output:
6562601476817760642 14709581653641444765 9409514199652887849 1924538160632758838 17897337138111675903 1975397273527783519 13274213676273801656 8009127032396458673 9591302157173387437 18119146874472923823 15782499870277277289 11636466062577654014 546407330026126536 10909019039006063801 93801623445947...
result:
ok 100000 lines
Test #17:
score: 0
Accepted
time: 2308ms
memory: 698352kb
input:
5000 100000 aaabaababbaabbabbbbbaaaabbbaabbbabbbabbbaabbbaabaabaaaabaabaabbaaababbbaaabbbabaaaaaabbaabbaaaaabbabbbabbbbbabbbababbaaabaaaaaaabaabaababbbbbabbaaabaabbaaabbabaaabbbaababaabaaabbaaaabbaaaababbbabbbbbbbaabaaaaaababbabbaaaaabaabbabbbbabbaabaabbaababababaaababbabababaababaabbbbaabbabbbbbbab...
output:
11369154519759229860 4816215756710773384 3084732770343768553 10732762141345713077 14000239080983316632 16200318140719862417 18415957533979700960 11666828489766775249 7557237538164660145 12066865066865017056 4022628382393625882 6542768028027630058 7453110102118375125 6215432807518544623 1341251603998...
result:
ok 100000 lines
Test #18:
score: 0
Accepted
time: 1047ms
memory: 696680kb
input:
5000 100000 ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
12902464409189323146 2112106874663835270 17874290669032515261 17889078556270410717 1153359439408633103 17496184927378147549 4218582814297155576 12182030755254116397 2311499738865929178 12069095198538404628 11646473706806926093 13424856046086967932 13546170125890126237 9125301078493922531 68650470543...
result:
ok 100000 lines
Test #19:
score: 0
Accepted
time: 2242ms
memory: 697108kb
input:
5000 100000 dsdsuhzydsdsdsdsuhzydsdsdsdsuhzfazkbverpxygzgkcipdngvfodgbvdwvdcnagozflmjmjxnrfkztjxydrvwnohnammcifwrzihsjrfqloicsbyoucgodrlhkfdcmewnvyknniwanjorbalalfnxcwpdgnjvckpfwiquowfbwyubiphcgdoeugnkgboxjghwnywvtoagnpcayzktfwjfkyoyugsixnzqxbdewksqlptdtccjcylijygcqpijlyzpdwgogimckuiwpblahhdwdvcolat...
output:
17973645912833898991 7920996292859300124 5299634393547051688 10638989442697924380 13765138548894885884 14315544494079078106 16026493056526540469 3470444440646718742 10617228587373799972 15918849430547099913 5762853815067753616 2006844376064461744 17275381263004882135 13029693802685627826 17254948448...
result:
ok 100000 lines
Test #20:
score: 0
Accepted
time: 2364ms
memory: 696848kb
input:
5000 100000 juptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjuptjujuptjujuptjujuptjjuptjujuptjujuptjujuptjjuptjup...
output:
18267505777322887551 6333102135713239606 16183163337491726230 12497707919138107517 10288177664292055269 2374663421415104796 8447031726445859124 729526387853373214 10656604364796015293 18372151029886143661 7570280658130472160 13718608135347138899 3232065209582597207 6232281250704478408 20251182204435...
result:
ok 100000 lines
Test #21:
score: 0
Accepted
time: 2286ms
memory: 698184kb
input:
5000 100000 mkubtkmkubmkubtkmkubmmkubtkmkubmkubtkmkubmmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubtkmkubmkubtkmkubmkubtkmkumkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubmkubtkmkubtkmkubmkubtkmkubmmkubtkmkubmkubtkmkubmmkubtkm...
output:
3030152804383651335 10499427113700581790 6859389313460158725 14628078058009393408 10634510135060870544 10010679243232673967 3099979833209629692 17573249651863059678 6127876367842094402 18346012870020826699 3929455974939673152 11565336593151678792 1047943649566503057 12198912032089561963 708160318405...
result:
ok 100000 lines
Subtask #4:
score: 6
Accepted
Test #22:
score: 6
Accepted
time: 125ms
memory: 24304kb
input:
100000 100000 zbbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaabab...
output:
16102224067619618967 2409962914769200003 427496158535942638 17668679206267169316 9612725428377010375 16283030984784184667 14966758574838045581 8108029333542434517 5821899279772898061 7354415533246368927 15016230232022193055 9072126619623269970 5490256818353051548 432088324301719512 13681741566473101...
result:
ok 100000 lines
Test #23:
score: 0
Accepted
time: 136ms
memory: 24076kb
input:
100000 100000 zsyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysysyysyysysyysyysysyysysyysyysysyysy...
output:
4559870725517531243 7294838067589907718 11611591353940805930 6570123277626119382 7422995984298182834 5907659314847245750 16910510485299347733 4264602948914788684 13190214217087942183 6600183534290302450 18342681242733610030 11565497126186922166 17128453730139037795 1670830382187028213 18164994643596...
result:
ok 100000 lines
Test #24:
score: 0
Accepted
time: 126ms
memory: 24076kb
input:
100000 100000 zoooooooollexlwockjmmpcsmrmxbcsxiopbhrsgmuffubpextcneqsmtouhuovwmosufyvtciwaiqfgxdjgebcnwbeyyyascjixpskyeyoecigpydkqrssvcwcuirkwyxxbcfgjdorrrgdghdooooooooofnkxriqwewxjgitnhfrykdhcrpbgmcnqujvlugcougvywjyjknbcfqdohyxidpswedsqodaqavibkmrykeiqfmoyavdcctpjvqomwmhjysbynqskjvprebydvglxmnqsvxy...
output:
812998614822431625 1250302312590066903 0 17068288240276554944 8822011249064016718 5154878686056167322 16634251694703169315 7627132526351165031 17489820411768677459 1612901206518396247 9557606214238964493 8125053178366415794 6923591044772654970 16010694286126551160 0 11810757301219826743 180907391938...
result:
ok 100000 lines
Subtask #5:
score: 0
Runtime Error
Dependency #4:
100%
Accepted
Test #25:
score: 0
Runtime Error
input:
100000 100000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
result:
Subtask #6:
score: 0
Runtime Error
Dependency #2:
100%
Accepted
Test #32:
score: 0
Runtime Error
input:
50000 50000 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #3:
100%
Accepted
Dependency #5:
0%