QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168899 | #6567. Repetitive String Invention | ucup-team134# | WA | 54ms | 10568kb | C++14 | 4.9kb | 2023-09-09 02:09:41 | 2023-09-09 02:09:41 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}
const ll mod=218047311615681871; //998244353
ll add(ll a,ll b){
a+=b;
if(a>=mod)
a-=mod;
return a;
}
ll sub(ll a,ll b){
a-=b;
if(a<0)
a+=mod;
return a;
}
ll mul(ll a,ll b){
return a*b%mod;
}
const int D=29;
const int N=805;
vector<ll> st;
vector<vector<ll>> st2;
int main()
{
st.pb(1);
for(int i=0;i<N;i++){
st.pb(mul(st.back(),D));
}
for(int i=0;i<N;i++){
st2.pb({});
for(int j=0;j<D;j++){
st2.back().pb(mul(st[i],j));
}
}
string s;
cin >> s;
int n=sz(s);
vector<gp_hash_table<ll,int>> cnt(n+1);
vector<vector<ll>> hsh(n,vector<ll>(n));
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(i==j){
hsh[i][j]=s[j]-'a';
}
else{
hsh[i][j]=add(mul(hsh[i][j-1],D),s[j]-'a');
}
}
}
ll total=0;
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
int mxLen=(j-i+1);
int st=(mxLen&1)?1:2;
for(int x=st;x<mxLen;x+=2){
int a=(mxLen-x)/2;
int l=i+a;
int r=j-a;
assert(r-l+1==x);
if(hsh[i][l-1]==hsh[r+1][j]){
total+=cnt[x][hsh[l][r]];
}
}
total+=cnt[mxLen][hsh[i][j]];
}
for(int j=i;j>=0;j--){
cnt[i-j+1][hsh[j][i]]++;
}
}
for(int i=0;i<=n;i++){
cnt[i].clear();
}
reverse(all(s));
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
int mxLen=(j-i+1);
int st=(mxLen&1)?1:2;
for(int x=st;x<mxLen;x+=2){
int a=(mxLen-x)/2;
int l=i+a;
int r=j-a;
assert(r-l+1==x);
if(hsh[i][l-1]==hsh[r+1][j]){
total+=cnt[x][hsh[l][r]];
}
}
//total+=cnt[mxLen][hsh[i][j]];
}
for(int j=i;j>=0;j--){
cnt[i-j+1][hsh[j][i]]++;
}
}
printf("%lld\n",total);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4268kb
input:
aaaa
output:
9
result:
ok single line: '9'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4088kb
input:
axabxbcxcdxd
output:
22
result:
ok single line: '22'
Test #3:
score: 0
Accepted
time: 54ms
memory: 5688kb
input:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
output:
536006700
result:
ok single line: '536006700'
Test #4:
score: 0
Accepted
time: 41ms
memory: 5408kb
input:
abababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababababab...
output:
136016600
result:
ok single line: '136016600'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4268kb
input:
a
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4016kb
input:
ab
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4080kb
input:
aa
output:
1
result:
ok single line: '1'
Test #8:
score: -100
Wrong Answer
time: 38ms
memory: 10568kb
input:
bbbbbrrrrbrbrrbrbrbrbbrrbbbbrrbrrbrbrbrrrrrbbbrrbrrbbrrrbbbbbrrrrbbrbbrrrrrbbrrrbbbbbrbbrbbbrbrrbrrrrrrrrbbrbrbbrrrrrrbbbbbrbrrrrbrrbbrbrrrrrbrbrbbrbrrbrrrrbrbbrbrrbrrbbbbrrrrrbrbbrbbrrrrrbrbrbrbbbrrrrrrrbbbbbbrrbrbrrrrrbbbrbrrrrbbbbrrbrrbbbbbbbrbbbbrrrbrbbbrrrrrrbbbbbrbrrbbbbrbrbrrbbrrrbbbrbbbrbbrr...
output:
213174
result:
wrong answer 1st lines differ - expected: '209015', found: '213174'