QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111091 | #6567. Repetitive String Invention | changtu | WA | 2ms | 3424kb | C++23 | 2.9kb | 2023-06-05 20:00:12 | 2023-06-05 20:00:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = LLONG_MAX / 4;
bool chmin(ll& a, ll b) { if(a <= b) return 0; a = b; return 1; }
bool chmax(ll& a, ll b) { if(a >= b) return 0; a = b; return 1; }
#define all(a) begin(a), end(a)
#define rep(i,a,b) for(ll i = a; i < b; i++)
template<typename I,typename L,I mod> struct Modint {
I v;
I pow(L b) const {
L res=1,a=v;
while(b) { if(b&1) res=res*a%mod; b>>=1; a=a*a%mod; }
return res;
}
I inv() const { return pow(mod-2); }
Modint &operator+=(const Modint &x) { v+=x.v; v-=v>=mod?mod:0; return *this; }
Modint &operator-=(const Modint &x) { v-=x.v; v+=v<0?mod:0; return *this; }
Modint &operator*=(const Modint &x) { v=L(1)*v*x.v%mod; return *this; }
Modint &operator/=(const Modint &x) { v=L(1)*v*x.inv()%mod; return *this; }
friend Modint operator+(Modint l,const Modint &r) { return l+=r; }
friend Modint operator-(Modint l,const Modint &r) { return l-=r; }
friend Modint operator*(Modint l,const Modint &r) { return l*=r; }
friend Modint operator/(Modint l,const Modint &r) { return l/=r; }
Modint operator++(int) { auto res=*this; *this+=1; return res; }
Modint operator--(int) { auto res=*this; *this-=1; return res; }
Modint operator- () { return *this*-1; }
Modint &operator++() { return *this+=1; }
Modint &operator--() { return *this-=1; }
bool operator< (const Modint &x) const { return v< x.v; }
bool operator> (const Modint &x) const { return v> x.v; }
bool operator<=(const Modint &x) const { return v<=x.v; }
bool operator>=(const Modint &x) const { return v>=x.v; }
bool operator==(const Modint &x) const { return v==x.v; }
bool operator!=(const Modint &x) const { return v!=x.v; }
friend istream &operator>>(istream &is,Modint &x) { is>>x.v; x=Modint(x.v); return is; }
friend ostream &operator<<(ostream &os,const Modint &x) { return os<<x.v; }
Modint(L x=0): v((x%=mod)<0?x+mod:x) {}
static_assert(0ULL+mod+mod-2<1ULL<<(sizeof(I)*8-1), "Modint overflow");
static_assert(1ULL*(mod-1)*(mod-1)<1ULL<<(sizeof(L)*8-1), "Modint overflow");
};
int main() {
cin.tie(0)->sync_with_stdio(0);
string S;
cin >> S;
const ll N = S.size();
ll ans = 0;
rep(i, 0, 2) {
reverse(S.begin(), S.end());
vector table1(N + 1, vector<ll>(N + 1));
vector table2(N + 1, vector<ll>(N + 1));
for (ll i = N; i--;) for (ll j = N; j--;) {
if (S[i] == S[j]) table1[i][j] = table1[i + 1][j + 1] + 1;
}
rep(i, 0, N) rep(j, 0, N) {
if (S[i] == S[j]) table2[i + 1][j + 1] = table2[i][j] + 1;
}
rep(L, 0, N) for (ll C = 1; L + C + C <= N; C++) rep(R, L + C + C, N + 1) {
const ll len_L = min(C - 1, table1[L][L + C]);
const ll len_R = min(C - 1, table2[L + C][R]);
if (len_L + len_R >= C) ans += len_L + len_R - C + 1;
}
}
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3424kb
input:
aaaa
output:
2
result:
wrong answer 1st lines differ - expected: '9', found: '2'