Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】
一、题目
D2. RGB Substring (hard version)
二、分析
思路一开始就想的对的,但是,用memset给数组初始化为0超时了!超时了!
然后我按照题解改了个vector初始化,就过了!
以后得谨慎使用memset了。
三、AC代码
1 #include <bits/stdc++.h>
2
3 using namespace std;
4 #define ll long long
5 #define Min(a,b) (a)>(b)?(b):(a)
6 const int maxn = 2e5 + 13;
7 char S[maxn];
8 char Q[] = "GBR";
9 int n, k;
10
11 int main()
12 {
13 //freopen("input.txt", "r", stdin);
14 int q;
15 scanf("%d", &q);
16 while(q--)
17 {
18 int ans;
19 scanf("%d%d", &n, &k);
20 scanf("%s", S);
21 ans = k;
22 for(int i = 0; i < 3; i++)
23 {
24 vector<int> dp(n);
25 int p = i, j;
26 int res = 0;
27 for(j = 0; j < k; j++)
28 {
29 if(S[j] != Q[p%3])
30 {
31 res++;
32 dp[j] = 1;
33 }
34 p++;
35 }
36 ans = Min(ans, res);
37 for(j; j < n; j++)
38 {
39 if(S[j] != Q[p%3])
40 {
41 res = res - dp[j - k] + 1;
42 dp[j] = 1;
43 }
44 else
45 {
46 res = res - dp[j - k];
47 }
48 ans = Min(ans, res);
49 p++;
50 }
51 }
52 printf("%d\n", ans);
53 }
54 return 0;
55 }
Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 【递推】的更多相关文章
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题
D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...
- Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version)
传送门 题意: 给你一个长为n的仅由'R','G','B'构成的字符串s,你需要在其中找出来一个子串.使得这个子串在"RGBRGBRGBRGB........(以RGB为循环节,我们称这个串 ...
- Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...
- 双指针(最大删除子串)Codeforces Round #579 (Div. 3)--Remove the Substring (hard version)
题目链接:https://codeforces.com/contest/1203/problem/D2 题意: 给你S串.T串,问你最长删除多长的子串使得S串里仍然有T的子序列. 思路: 想了好久,先 ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #575 (Div. 3)
本蒟蒻已经掉到灰名了(菜到落泪),希望这次打完能重回绿名吧...... 这次赛中A了三题 下面是本蒟蒻的题解 A.Three Piles of Candies 这题没啥好说的,相加除2就完事了 #in ...
- Codeforces Round #575 (Div. 3) 题解
比赛链接:https://codeforc.es/contest/1196 A. Three Piles of Candies 题意:两个人分三堆糖果,两个人先各拿一堆,然后剩下一堆随意分配,使两个人 ...
- Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)
D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...
随机推荐
- docker的FAQ
1.Docker能在非Linux平台(Windows+MacOS)上运行吗? 答:可以 2 .如何将一台宿主机的docker环境迁移到另外一台宿主机? 答:停止Docker服务,将整个docker存储 ...
- 2019南昌网络赛H The Nth Item(二阶线性数列递推 + 广义斐波那契循环节 + 分段打表)题解
题意: 传送门 已知\(F(n)=3F(n-1)+2F(n-2) \mod 998244353,F(0)=0,F(1)=1\),给出初始的\(n_1\)和询问次数\(q\),设每一次的答案\(a_i= ...
- element-ui dialog loading
element-ui dialog loading 指令方式 服务方式 v-loading 当使用指令方式时,全屏遮罩需要添加fullscreen修饰符(遮罩会插入至 body 上),此时若需要锁定屏 ...
- php 安装 yii framework notice-error 的解决方案!
1 问题描述: 2 解决方案: error_reporting(0); //解决error_notice 的最简单最有效的方法在每一个php文件的头部都加上error_reporting(0); 3. ...
- JavaScript 高级程序设计 (第4版) 思维导图/脑图 All In One
JavaScript 高级程序设计 (第4版) 思维导图/脑图 All In One JavaScript 高级程序设计 (第4版) 思维导图下载 JavaScript 高级程序设计 (第4版) 脑图 ...
- 算法的时间复杂度 & 性能对比
算法的时间复杂度 & 性能对比 累加算法性能对比 // js 累加算法性能对比测试 const n = 10**6; (() => { console.time(`for`); let ...
- npm install 原理
npm install 原理 https://docs.npmjs.com/about-npm/ npm consists of three distinct components: the webs ...
- Flutter Navigator2.0
Example 1 import 'package:dart_printf/dart_printf.dart'; import 'package:flutter/material.dart'; cla ...
- Dart: List排序
var list = <Item>[ Item(title: "item 1", isTopping: true), Item(title: "item 2& ...
- 国际标准时间格式ISO8601
日期表示法 年由4位数字组成YYYY,或者带正负号的四或五位数字表示±YYYYY.以公历公元1年为0001年,以公元前1年为0000年,公元前2年为-0001年,其他以此类推.应用其他纪年法要换算成公 ...