QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816147 | #3033. Harry Potter and the Palindromic Radius | DeadlyCritic# | Compile Error | / | / | C++17 | 7.2kb | 2024-12-15 23:57:27 | 2024-12-15 23:57:27 |
Judging History
This is the latest submission verdict.
- [2024-12-15 23:57:27]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2024-12-15 23:57:27]
- Submitted
answer
// template.cpp
// add use inp.txt for file input
/*
Pragma:
If ever in doubt about whether your pragmas are correct,
turn on most compiler warnings with the command-line option -Wall(or the more specific -Wunknown-pragmas).
use assert(__builtin_cpu_supports("avx2")) to check if intruction set is available
*/
// #pragma GCC optimize("O3","unroll-loops")
#pragma GCC optimize ("Ofast")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
// #pragma GCC target("sse4") // instead of avx2
// __attribute__((target("avx2"), optimize("O3", "unroll-loops")))
#include <bits/stdc++.h>
#define oo (1000'000'000'000'000'000LL)
#define cif(i, n) for(int i = 0; i < n; i++)
#define ccif(i, l, r) for(int i = l; i < r; i++)
#define rif(i, n) for(int i = n-1; i >= 0; i--)
#define scan(a, __n) {for(int __ = 0; __ < __n; __++)cin >> a[__];}
#define print(a, __n) {for(int __ = 0; __ < __n; __++)cout << a[__] << ' '; cout << '\n';}
#define sz(s) ((int)s.size())
#define dbg(x) cerr << #x << " : " << x << endl;
// #define mset(a, chr) memset(a, chr, sizeof a)
#define mset(a) memset(a, 0, sizeof a)
// #define int ll
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define uni(v) sort(all(v)), v.resize(unique(all(v))-v.begin());
// #define c0 (v<<1)
// #define c1 (c0|1)
// #define md ((l+r)/2)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<ld> vd;
typedef pair<ld, ld> pt;
typedef vector<pt> vpt;
const int mod = 1e9+7;
// const string fileName = "";
// const int maxFac = 1e6+7;
// ll fac[maxFac], _fac[maxFac];
// ll po(ll b, ll p){
// b %= mod;
// p %= mod-1;
// ll r = 1;
// while(p){
// if(p&1)r = r*b%mod;
// p >>= 1;
// b = b*b%mod;
// }
// return r;
// }
// ll choose(ll k, ll n){
// return fac[n]*_fac[k]%mod*_fac[n-k]%mod;
// }
// ll factorial(ll n, ll k){
// ll ret = 1;
// for(ll i = n; i >= n-k+1; i--){
// ret = ret*i%mod;
// }
// return ret;
// }
const int maxN = 1e6+7;
int a[maxN];
int n;
class RollingHash{
public:
static ll po(ll b, ll p, ll mod){
b %= mod;
p %= mod-1;
ll r = 1;
while(p){
if(p&1)r = r*b%mod;
p >>= 1;
b = b*b%mod;
}
return r;
}
int n;
int mod;
int prm;
vector<int> w;
vector<int> _w;
vector<int> pef;
vector<int> suf;
RollingHash(){}
RollingHash(int _prm, int _mod, const string& s){
prm = _prm;
mod = _mod;
build(s);
}
void build(const string& s){
// initialize
n = s.size();
w.resize(n+2);
_w.resize(n+2);
pef.resize(n+2);
suf.resize(n+2);
// build w & _w
w[0] = 1;
for(int i = 1; i < w.size(); i++)w[i] = w[i-1]*1ll*prm%mod;
_w.back() = po(w.back(), mod-2, mod);
for(int i = w.size()-2; i >= 0; i--)_w[i] = _w[i+1]*1ll*prm%mod;
// build pef & suf
pef[0] = 0;
for(int i = 0; i < n; i++){
pef[i+1] = (pef[i] + w[i]*1ll*(s[i]-'a'+1))%mod;
}
suf[n] = 0;
for(int i = n-1; i >= 0; i--){
suf[i] = (suf[i+1] + w[n-i-1]*1ll*(s[i]-'a'+1))%mod;
}
}
inline int getHash(int l, int r){
return (pef[r+1] + 0ll + mod - pef[l]) %mod * _w[l] %mod;
}
inline int getRevHash(int l, int r){
return (suf[l] + 0ll + mod - suf[r+1]) %mod * _w[n-r-1] %mod;
}
inline bool isEqual(int l1, int r1, int l2, int r2){
return getHash(l1, r1) == getHash(l2, r2);
}
inline bool isRevEqual(int l1, int r1, int l2, int r2){
return getRevHash(l1, r1) == getRevHash(l2, r2);
}
inline bool isPal(int l, int r){
return getHash(l, r) == getRevHash(l, r);
}
};
class MultiRollingHash{
public:
static const int hashSize = 2;
int mod[hashSize] = {(int)1e9+7, (int)1e9+9};
int prm[hashSize] = {7, 13};
RollingHash hashers[hashSize];
MultiRollingHash(){}
MultiRollingHash(const string& s){
build(s);
}
void build(const string& s){
int n = s.size();
for(int ind = 0; ind < hashSize; ind++){
hashers[ind] = RollingHash(prm[ind], mod[ind], s);
}
}
vector<int> getHash(int l, int r){
vector<int> ret;
for(int ind = 0; ind < hashSize; ind++){
ret.push_back(hashers[ind].getHash(l, r));
}
return ret;
}
vector<int> getRevHash(int l, int r){
vector<int> ret;
for(int ind = 0; ind < hashSize; ind++){
ret.push_back(hashers[ind].getRevHash(l, r));
}
return ret;
}
bool isEqual(int l1, int r1, int l2, int r2){
bool ret = 1;
for(int ind = 0; ind < hashSize; ind++){
ret &= hashers[ind].isEqual(l1, r1, l2, r2);
}
return ret;
}
bool isRevEqual(int l1, int r1, int l2, int r2){
bool ret = 1;
for(int ind = 0; ind < hashSize; ind++){
ret &= hashers[ind].isRevEqual(l1, r1, l2, r2);
}
return ret;
}
bool isPal(int l, int r){
for(int ind = 0; ind < hashSize; ind++){
if(!hashers[ind].isPal(l, r))return 0;
}
return 1;
}
};
bool isok(const string& s){
MultiRollingHash rh(s);
for(int i = 0; i < n; i++){
if(!rh.isPal(i-a[i], i+a[i]))return 0;
if(i-a[i] > 0 && i+a[i] < n-1)if(s[i-a[i]-1] == s[i+a[i]+1])return 0;
}
return 1;
}
void slv(){
cin >> n;
scan(a, n);
vector<string> ans;
for(int xx = 0; xx < 4; xx++){
string b;
int x0 = xx>>1&1;
int x1 = xx&1;
b.push_back(x0+'0');
b.push_back(x1+'0');
for(int i = 2; i < n; i++){
b.push_back((a[i-1] == 0)^b[i-2]);
}
if(isok(b))ans.push_back(b);
}
cout << sz(ans) << '\n';
cif(i, sz(ans)){
cout << ans[i] << '\n';
}
}
void prep(){
// fac[0] = 1;
// for(int i = 1; i < maxFac; i++)fac[i] = fac[i-1]*i%mod;
// _fac[maxFac-1] = po(fac[maxFac-1], mod-2);
// for(int i = maxFac-2; i >= 0; i--)_fac[i] = _fac[i+1]*(i+1)%mod;
// w[0] = 1;
// for(int i = 1; i < maxN; i++)w[i] = w[i-1]*p%mod;
// _w[maxN-1] = po(w[maxN-1], mod-2);
// for(int i = maxN-2; i >= 0; i--)_w[i] = _w[i+1]*p%mod;
}
signed main(){
// if(fileName.size() > 0){
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// }
fastIO;
// cout << fixed << setprecision (15);
prep();
int t = 1;
cin >> t;
while(t--){
// cout << slv() << '\n';
slv();
// string s;
// cin >> s;
// bool x = slv();
// cout << (x?"YES":"NO") << '\n';
}
}
/*
*/
Details
In file included from /usr/include/c++/13/string:43, from /usr/include/c++/13/bitset:52, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52, from answer.code:16: /usr/include/c++/13/bits/allocator.h: In destructor ‘std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()’: /usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]’: target specific option mismatch 184 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/13/string:54: /usr/include/c++/13/bits/basic_string.h:181:14: note: called from here 181 | struct _Alloc_hider : allocator_type // TODO check __is_final | ^~~~~~~~~~~~