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 ...
随机推荐
- python函数传参
之前一直没有注意过该问题,在leetcode144中写递归发现该问题,不知道递归函数传参是指针还是引用. 参考:http://c.biancheng.net/view/2258.html 如果是不可变 ...
- next v5升级到next v7需要注意的地方
title: next v5升级到next v7需要注意的地方 date: 2020-03-04 categories: web tags: [hexo,next] 大部分的设置都是一样的,但有一些细 ...
- 计算机网络基础篇-ppp协议
所谓的PPP协议是点对点协议,是目前使用最广泛的数据链路层的协议.大部分用户使用电话线拨号入网的,从用户计算机到ISP的链路所使用的数据链路层协议就是PPP协议. 首先介绍下拨号入网的过程.因特网服务 ...
- Spring Cloud Alibaba+Nacos搭建微服务架构
1. Spring Cloud Alibaba 简介 Spring Cloud Alibaba是阿里巴巴为分布式应用提供的一站式解决方案,能够更方便快捷地搭建分布式平台,nacos拥有着替换eu ...
- flutter practical
flutter practical https://flutterchina.club/ https://github.com/flutterchina/flutter-in-action https ...
- iOS remote debug & Android remote debug & Chrome & APP
iOS remote debug & Android remote debug & Chrome & APP iOS remote debugging 如何在 iOS 真机上调 ...
- js replace all & replaceAll
js replace all & replaceAll https://scotch.io/tutorials/javascript-replace-all-instances-of-a-st ...
- SVG 场馆图
SVG 场馆图 https://www.infoq.cn/article/1BVg9VDSmqyHv3W3TeNH https://mp.weixin.qq.com/s/aNPAfJIHL14NFtL ...
- input number step
input number step <!DOCTYPE html> <html> <body> <h1>The input step attribute ...
- c++ 设置桌面壁纸(win)
#include <iostream> #include <Windows.h> int main() { const char* path = "C:\\Users ...