QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235656 | #3033. Harry Potter and the Palindromic Radius | piratZnachor# | 100 ✓ | 3821ms | 34336kb | C++14 | 3.8kb | 2023-11-02 23:32:28 | 2023-11-02 23:32:28 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define INF 1e9
#define INFl 1e18
#define all(x) x.begin(), x.end()
#define sajz(x) (int)x.size()
#define pb push_back
#define s second
#define f first
#define yes puts("YES")
#define no puts("NO")
#define erase_duplicates(x) {sort(all(x));(x).resize(distance((x).begin(), unique(all(x))));}
using namespace std;
//using namespace __gnu_pbds;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef set<int> si;
typedef multiset<int> msi;
typedef long double ld;
//typedef cc_hash_table<int, int, hash<int>> ht;
array<vi, 2> manacher(const string& s) {
int n = sajz(s);
array<vi,2> p = {vi(n+1), vi(n)};
for (int z = 0; z <= 1; z ++) for (int i=0,l=0,r=0; i < n; i++) {
int t = r-i+!z;
if (i<r) p[z][i] = min(t, p[z][l+t]);
int L = i-p[z][i], R = i+p[z][i]-!z;
while (L>=1 && R+1<n && s[L-1] == s[R+1])
p[z][i]++, L--, R++;
if (R>r) l=L, r=R;
}
return p;
}
bool check(string &s, vi &a) {
array<vi, 2> p = manacher(s);
for (int i = 0; i < sajz(a); i ++) {
if (p[1][i] != a[i]) return false;
}
return true;
}
void test_case() {
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; i ++) cin >> a[i];
string s1 = "00";
for (int i = 2; i < n; i ++) {
if (a[i-1] == 0) {
if (s1[i-2] == '0') s1 += "1";
else s1 += "0";
} else {
s1 += s1[i-2];
}
}
string s2 = "01";
for (int i = 2; i < n; i ++) {
if (a[i-1] == 0) {
if (s2[i-2] == '0') s2 += "1";
else s2 += "0";
} else {
s2 += s2[i-2];
}
}
string s3 = "10";
for (int i = 2; i < n; i ++) {
if (a[i-1] == 0) {
if (s3[i-2] == '0') s3 += "1";
else s3 += "0";
} else {
s3 += s3[i-2];
}
}
string s4 = "11";
for (int i = 2; i < n; i ++) {
if (a[i-1] == 0) {
if (s4[i-2] == '0') s4 += "1";
else s4 += "0";
} else {
s4 += s4[i-2];
}
}
vector<string> ans;
if (check(s1, a)) ans.pb(s1);
if (check(s2, a)) ans.pb(s2);
if (check(s3, a)) ans.pb(s3);
if (check(s4, a)) ans.pb(s4);
cout << sajz(ans) << '\n';
for (auto it : ans) cout << it << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
int t=1;
cin >> t;
while(t--)test_case();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3821ms
memory: 34336kb
input:
131112 2 0 0 2 0 1 2 0 0 2 1 0 2 0 0 2 0 1 2 0 0 2 0 1 3 0 1 0 3 0 1 1 3 0 0 0 3 0 1 0 3 0 1 0 3 0 2 0 3 0 0 0 3 1 0 0 3 0 0 0 3 1 0 0 3 0 1 0 3 0 2 0 3 0 0 0 3 0 0 1 3 0 1 0 3 0 2 0 4 0 1 1 0 4 0 1 2 0 4 0 0 1 0 4 0 0 1 1 4 0 1 0 0 4 0 1 0 1 4 0 0 0 0 4 0 0 1 0 4 0 0 1 0 4 1 0 1 0 4 0 1 1 0 4 0 1 2...
output:
4 00 01 10 11 0 4 00 01 10 11 0 4 00 01 10 11 0 4 00 01 10 11 0 4 000 010 101 111 0 4 001 011 100 110 4 000 010 101 111 4 000 010 101 111 0 4 001 011 100 110 0 4 001 011 100 110 0 4 000 010 101 111 0 4 001 011 100 110 0 4 000 010 101 111 0 4 0000 0101 1010 1111 0 4 0010 0111 1000 1101 0 4 0001 0100 ...
result:
ok 401208 lines