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 ...
随机推荐
- cin 与 getline
cin空格截断 getline(cin,s) 换行结束 ....太愚蠢了
- 基础命令使用[win篇]
基础命令使用 [ win篇 ] 2017-11-05 WIN CMD 0x01 基础命令使用: 演示环境: 1 2 win2008R2cn ip: 192.168.3.23 假设为入侵者机器 ...
- style element & web components
style element & web components style.textContent style.setContent bug style.textContent const st ...
- Flutter 在同一页面显示List和Grid
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends State ...
- .NET 6 Preview 1 发布
前言 2021 年 2 月 17 日微软发布了 .NET 6 的 Preview 1 版本,那么来看看都有什么新特性和改进吧,由于内容太多了因此只介绍一些较为重点的项目. 统一和扩展 .NET 6 在 ...
- [转]c++使用thread类时编译出错,对‘pthread_create’未定义的引用
转载地址:https://blog.csdn.net/wuhui20091515/article/details/52531202 例子1 #include <iostream> #inc ...
- C#如何防止程序多次运行的技巧(精典)
一.引言最近发现很多人在论坛中问到如何防止程序被多次运行的问题的,所以这里就记录下来,希望给遇到同样问题的朋友有所参考的,同时也是对自己的一个积累.在介绍具体实现代码之前,我们必须明确解决这个问题的思 ...
- 【翻译】Python PEP8编码规范(中文版)
原文链接:http://legacy.python.org/dev/peps/pep-0008/ item detail PEP 8 Title Style Guide for Python Code ...
- Prometheus+Grafana+Alertmanager搭建全方位的监控告警系统
prometheus安装和配置 prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据. 2.Client Library: 客户端库,检测应用程序代码,当 ...
- 硬件交互 snmp 使用
# *********************************snmp使用******************************************** # coding=utf-8 ...