当前位置:网站首页>ARC110E Shorten ABC
ARC110E Shorten ABC
2022-07-22 16:46:00 【Have a cold moon in your heart】
ARC110E Shorten ABC
Consider the nature of the operation , take A A A、 B B B、 C C C Respectively as 1 1 1、 2 2 2、 3 3 3.
operation s i s_i si and s i + 1 s_{i+1} si+1 That is, merge into s i ⊕ s i + 1 s_i \oplus s_{i+1} si⊕si+1.
Then the XOR and sum of intervals do not change , For XOR and is 0 0 0 The range of , In the end, it will all be the same ; Otherwise, there must be one character left ( Except for odd numbers and all the same ).
inference , For XOR and is 0 0 0 The range of , If you add one more character to its left or right , It must be merged into one character .
For a string obtained by an operation t t t, It is equivalent to making the whole front part of the original string exclusive or and not 0 0 0 Section of , And satisfy the XOR and sum of the last paragraph as 0 0 0( Empty string also counts ).
Ordinary DP
With repeatability , Repetition is because of XOR and for 0 0 0 There may be many possible schemes for the segment of .
So consider removing XOR and as 0 0 0 The contribution of the segment of does not enumerate its , Consider that the end of the current paragraph is i i i, Find the first one on the right j j j, Satisfaction interval [ 1 , j ] [1,j] [1,j] Prefix XOR and ≠ \ne = Section [ 1 , i ] [1,i] [1,i] Or and , It means interval [ i + 1 , j ] [i+1,j] [i+1,j] XOR and inaction of 0 0 0.
remember f i f_i fi Means to segment according to the above method , The last paragraph begins with i i i Number of schemes at the end .
Preprocess the recursive sequence of the above methods .
The answer is satisfaction [ i + 1 , n ] [i+1,n] [i+1,n] The exclusive or and are 0 0 0 All of the i i i Corresponding f i f_i fi The sum of the .
Time complexity O ( n ) \mathcal O(n) O(n).
Similar exercises :AT4379 [AGC027E] ABBreviate
.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ha putchar(' ')
#define he putchar('\n')
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return x * f;
}
inline void write(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9)
write(x / 10);
putchar(x % 10 + 48);
}
const int _ = 1e6 + 10, mod = 1e9 + 7;
int n, s[_], nxt[_][4], f[_];
char c[_];
signed main() {
n = read();
scanf("%s", c + 1);
bool flg = 0;
for (int i = 1; i < n; ++i)
if (c[i] != c[i + 1]) {
flg = 1;
break;
}
if (!flg) return puts("1"), 0;
for (int i = 1; i <= n; ++i) s[i] = s[i - 1] ^ (c[i] - 'A' + 1);
for(int i = 0; i < 4; ++i) nxt[n][i] = n + 1;
for (int i = n; i >= 1; --i) {
for (int j = 0; j < 4; ++j) nxt[i - 1][j] = nxt[i][j];
nxt[i - 1][s[i]] = i;
}
f[0] = 1;
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 4; ++j)
if(s[i] != j) f[nxt[i][j]] = (f[nxt[i][j]] + f[i]) % mod;
if(s[i + 1] == s[n]) ans = (ans + f[i + 1]) % mod;
// cout << f[i + 1] << "\n";
}
write(ans), he;
return 0;
}
边栏推荐
- UE4 修改默认缓存路径
- 【Leetcode数组--排序+辗转相除法最大公约数】6122.使数组可以被整除的最少删除次数
- Jincang database kmonitor user guide --3. deployment
- 信息学奥赛一本通 1974:【16NOIP普及组】回文日期 | 洛谷 P2010 [NOIP2016 普及组] 回文日期
- 像素和颜色
- 抖音Tiktok- 获取抖音视频详情接口
- High number_ Chapter 3 multiple integration
- Switch and router technology: static NAT, dynamic NAT, pat and port mirroring
- How to install a pagoda on IBM's free machine
- Understand recursion and iteration
猜你喜欢
随机推荐
AlterNet Studio 8.1 Crack
Switch and router technology: static NAT, dynamic NAT, pat and port mirroring
CF1635F Closest Pair
Repair the problem of adding device groups and editing exceptions on easycvr platform
Fastjson code execution cve-2022-25845
The Prospectus has written "yuancosmos" 318 times! Feitian Yundong fights Hong Kong stocks again "yuancosmos first share"“
Li Kou daily question - day 41 -125. Verify the palindrome string
Model compression, acceleration and mobile deployment
解析优化机器人课程体系与教学策略
层序遍历BFS(广度优先)
我,AI博士生,在线众筹研究主题
PHP QR code decoding qrreader class | QR code image to string
[leetcode array -- sorting + rolling division maximum common divisor] 6122. The minimum number of deletions that make the array divisible
立即执行函数 分号问题
UE4 设置碰撞体
QUuid
LeetCode 每日一题——814. 二叉树剪枝
IBM的免费机器怎么装宝塔
UE4 进入指定区域实现触发加速功能
洛谷_P1112 波浪数_思维_进制 / 构造 / 枚举