百度(1条未读通知)首页2019牛客暑期多校训练营(第三场)_ACM/noip/noil…B- Crazy Binary String_2019牛客暑期多校训练营(时间限制:CC++1秒,其他语言2秒

空间限制:CC++262144K,其他语言524288K

64bit lO Format: %lld

题目描述x

ZYB loves binary strings(strings that only contains 0'and 1). And he loves Itextit(equal binary strings) more, where the number of O' and the number of 1"in the string are equal

ZYB wants to choose a substring from an original string T so that it is an Itextitequal binary string with the longest length possible. He also wants to choose a subsequence of T which meets the

same requirements

A string v is a substring of a string w if v is empty, or there are two integers I andr(1<LSTslwl)such that v =w) wl+I. Wr. A string v is a subsequence of a string w if it can be derived from w

输入描述:

The first line of the input contains a single integer N(I<N<100000), the length of the original string T. The second line contains a binary

string with exactly N characters, the original string T

输出描述

Print two integers A and B, denoting the answer for substring and subsequence respectively

示例1

复制

For simplicity, you only need to output the maximum possible length. Note that the empty string is both a substring and a subsequence of any string

输入描述

The first line of the input contains a single integer N(1<N<100000), the length of the original string T. The second line contains a binary

string with exactly N characters, the original string T

输入

8

01001001

输出

4  6

#include <bits/stdc++.h>
using namespace std;struct node{int maxp,minp;
};
bool cmp(node a,node b){return a.maxp-a.minp>b.maxp-b.minp;
}int main() {int n,zero_c=0,one_c=0,dif;scanf("%d",&n);string s;cin>>s;vector<node>cc(3*n,{-1,-1});cc[n+0].minp=0;for(int i=0;i<n;i++){if(s[i]=='0')zero_c++;else if(s[i]=='1') one_c++;dif=zero_c-one_c;if(cc[n+dif].minp==-1)cc[n+dif].minp=i+1;if(cc[n+dif].maxp==-1)cc[n+dif].maxp=i+1;if(cc[n+dif].minp>i+1)cc[n+dif].minp=i+1;else if(cc[n+dif].maxp<i+1)cc[n+dif].maxp=i+1;}sort(cc.begin(), cc.end(), cmp);printf("%d %d",cc[0].maxp-cc[0].minp,2*min(zero_c,one_c));return 0;
}

Crazy Binary String相关推荐

  1. 【2019牛客暑期多校训练营(第三场)- B】Crazy Binary String(思维,01串,前缀和)

    题干: 链接:https://ac.nowcoder.com/acm/contest/883/B 来源:牛客网 ZYB loves binary strings (strings that only ...

  2. 2019 牛客多校第三场 B Crazy Binary String

    题目链接:https://ac.nowcoder.com/acm/contest/883/B 题目大意 给定一个长度为 N 的 01 字符串,输出最长子串和子序列的长度,满足其中 0 和 1 的个数相 ...

  3. Binary String Reconstruction CodeForces - 1352F(思维+构造)

    For some binary string s (i.e. each character si is either '0' or '1'), all pairs of consecutive (ad ...

  4. Binary String Minimizing CodeForces - 1256D(贪心)

    You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1'). I ...

  5. nyoj 题目5 Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alpha ...

  6. Binary String Matching

    Binary String Matching 描述 Given two strings A and B, whose alphabet consist only '0' and '1'. Your t ...

  7. Binary String Constructing(CF-1003B)

    Problem Description You are given three integers aa, bb and xx. Your task is to construct a binary s ...

  8. 2019牛客暑期多校训练营(第三场) B-Crazy Binary String

    题目描述 ZYB喜欢二进制字符串(只包含'0'和'1'的字符串).他喜欢equal binary string(其中字符串中的"0"数和"1"数相等) ZYB想 ...

  9. D1. Kirk and a Binary String (easy version)

    题目链接:http://codeforces.com/contest/1204/problem/D1 D1. Kirk and a Binary String (easy version) time ...

最新文章

  1. 没学过python、但是还是有公司要-转行Python开发自学还是报班?老男孩全日制学习...
  2. Android 的 SDK Manager 无法启动 闪退解决方法
  3. 《JavaScript数据可视化编程》——1.4 用离散图表绘制x/y值
  4. python收入波动告警分析_使用Python/Pandas分析告警日志数据
  5. leetcode343. 整数拆分(动态规划)
  6. dz论坛发html乱码,发帖时出现乱码 - Discuz!-安装使用 - Discuz! 官方站 - Powered by Discuz!...
  7. 基于递归的前序二叉树遍历实现
  8. JS基础入门篇(四)—this的使用,模拟单选框,选项卡和复选框
  9. 【Python学习之路】——Day7(面向对象)
  10. 工具----10、Backtrack的安装
  11. c语言单片机用法,单片机 C语音开发 sbit使用方法··
  12. ESP32-土壤湿度传感器
  13. 二维离散傅里叶变换最详手算
  14. 通过图书编号查询python_基于Python的图书ISBN查询接口调用代码实例
  15. python ocr 识别发票_在Python中使用Tesseract进行OCR识别
  16. 电信光纤猫虚拟服务器设置方法,电信光纤猫与无线路由器连接的设置方法
  17. java的像素与dpi_DPI与像素的关系
  18. 《Linux学习一》交叉编译工具链的构建工具Crosstool-ng
  19. Echarts清空图表:There is a chart instance already initialized on the dom.
  20. 安装centos7系统 服务器安装系统

热门文章

  1. 在HTML中 怎么一张图片上在放一张图片,css sprites把很多小图集成在一张图片上...
  2. 简单介绍Fastboot
  3. 软件工程基础课-个人项目-数独
  4. 极线几何(Epipolar Geometry)
  5. iOS模拟器运行报错Unable to install /xxx/build/ios/iphonesimulator/Runner.app
  6. python证件照_python实现证件照换底功能
  7. 职业生涯手记——序章
  8. C# 如何在Excel表格中插入、编辑和删除批注(三)删除Excel批注
  9. Mac下cmake使用
  10. 7z制作自解压安装包(转载)