cf 917A The Monster

Ansys口腔正畸有限元分析:从几何处理到接触设定的全流程解析 本文详细解析了Ansys在口腔正畸有限元分析中的全流程应用,从几何处理到接触设定,帮助医生精准预测牙齿移动趋势。通过有限元建模技术,可同时观察牙齿-牙周膜-牙槽骨的力学响应,显著提升矫治效果预测准确率。文章还分享了实用技巧和参数设置建议,适用于正畸医生和工程师。 阅读详情

一 原题

C. The Monster
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him.

Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem.

A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally:

  • Empty string is a correct bracket sequence.
  • if s is a correct bracket sequence, then (s) is also a correct bracket sequence.
  • if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence.

A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence.

Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s.

Joyce doesn't know anything about bracket sequences, so she asked for your help.

Input

The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000).

Output

Print the answer to Will's puzzle in the first and only line of output.

Examples
input
((?))
output
4
input
??()??
output
7
Note

For the first sample testcase, the pretty substrings of s are:

  1. "(?" which can be transformed to "()".
  2. "?)" which can be transformed to "()".
  3. "((?)" which can be transformed to "(())".
  4. "(?))" which can be transformed to "(())".

For the second sample testcase, the pretty substrings of s are:

  1. "??" which can be transformed to "()".
  2. "()".
  3. "??()" which can be transformed to "()()".
  4. "?()?" which can be transformed to "(())".
  5. "??" which can be transformed to "()".
  6. "()??" which can be transformed to "()()".
  7. "??()??" which can be transformed to "()()()".


二 分析

给定一个由'(', '?', ')'三种字符组成的字符串s,长度为n(2<=n<=5000),问有多少个合法的子串。一个字符串合法是说,把其中的'?'替换成'('或')',能够使得每一个左括号都找到唯一与之对应的右括号。


第一反应是可以动态规划判断一个子串[l, r]是否合法,合法的字符串满足以下两个条件之一:

1)s[l],s[r]组成一对括号,并且子串[l + 1, r - 1]合法;

2)存在某个l < k < r,使得子串[l, k]合法,子串[k + 1, r]也合法。

但条件2)的判断是O(n^3)的,输入串长度5000的话并不能过。


事实上,一个字符串s(长度为n)合法等价于如下三个条件:

1)2 | n;

2)对于所有1 <= i <= n:字串[1, i]中所有'('的数量 + 所有'?'的数量 >= 所有')'的数量;

3)对于所有1 <= i <= n:字串[i, n]中所有')'的数量 + 所有'?'的数量 >= 所有'('的数量; 


必要性显然,充分性的话如果没有'?'的话等于说只要把一个串任意分成左右两半,左边的'('数量不少于')'数量,右边的')'数量不少于'('数量,整个串里他们数量相等。那么这个串就是合法的(可以想象一个栈,左括号就把一个物品压栈,右括号就出栈,这样的条件保证任何时候不会让空栈做出栈操作,并且所有操作完毕后栈为空)。


三 代码

/*
PROB: cf 917A
LANG: c++
AUTHOR: maxkibble
*/

#include <iostream>

using namespace std;

const int maxn = 5005;

string s;
int n, ans;
bool ok[maxn][maxn];

int main() {
    cin >> s;
    int n = s.length();
    for(int i = 0; i < n; i++) {
        int l = 0, r = 0, q = 0;
        for(int j = 0; i + j < n; j++) {
            if(s[i + j] == '(') l++;
            else if(s[i + j] == '?') q++;
            else r++;
            if(l + q < r) break;
            ok[i][i + j] = true;
        }
    }
    for(int i = n - 1; i >= 0; i--) {
        int l = 0, r = 0, q = 0;
        for(int j = 0; i - j >= 0; j++) {
            if(s[i - j] == '(') l++;
            else if(s[i - j] == '?') q++;
            else r++;
            if(r + q < l) break;
            if(ok[i - j][i] && j % 2 == 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


从 Integrated Configuration 到 Integration Flow,SAP PI/PO 老配置迁移的一次温和重构 很多还在运行 SAP PI/PO 的系统,Integration Directory 里都积累了不少 Integrated Configuration,也就是日常项目里常说的 ICO。它们可能稳定运行了多年,负责把采购订单、物料主数据、客户主数据、发票、发货通知从一个系统送到另一个系统。问题在于,ICO 这种对象很实用,却不够直观。 阅读详情

相关推荐

内存|内存的概念、内存的作用、内存的物理结构及内存使用

内存是硬件,是用于存放数据的硬件。程序执行前需要先放到内存中才能被CPU处理。内存是与CPU沟通的桥梁,计算机中所有程序的运行都要依靠内存,内存对计算机的影响非常大。本文简单介绍了内存的概念、作用、物理结构以及使用,内存远不止如此,后续文章会逐步深入讲解。

qq_59938293的博客 2万+

CF917A: The Monster 题解

题目链接: http://codeforces.com/contest/918/problem/C 分析 一个长度为|s|的字符串是pretty的充要条件如下: 1. |s| is even. 2. 0 ≤ s[1..i].count(‘(‘) + s[1..i].count(‘?’) - s[1..i].count(‘)’) for each 1 ≤ i ≤ |s|. 3. 0 ≤

z's blog 511

大唐杯历届省赛押题训练(6)

考试-TD-LTE无线网络设备介绍-TD-LTE网络架构一、单选题1TD-LTE的接入网E-UTRAN由下列哪些网元组成( )。0分/1分A、RNCB、BTSC、eNode BD、Node B提交答案:B正确答案:C考点TD-LTE网络架构解析暂无试题解析二、多选题1关于LTE网络整体结构,哪些说法是正确的( )0分/2分A、E-UTRAN用E-NodeB替代原有的RNC-NodeB结构B、E-NodeB间的接口为S1接口C、各网络节点之间的接口使用IP传输。

nimo观察者 633

CF - div2 - 459 - C - The Monster

C. The Monster time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output As Will is stuck in the Upside Down, he can still communicate with his mom,

dreams___的博客 794

YOLOv11涨点改进 | 全网独家创新,注意力改进篇 | TGRS 2025 | 引入APCM自适应像素级协同机制,动态增强目标区域、抑制背景噪声,助力YOLOv11做红外小目标检测有效涨点

本文提出了一种基于APCM模块改进的YOLOv11网络模型,通过像素级局部-全局协同建模增强目标特征并抑制背景噪声。APCM模块采用轻量化设计,无需复杂参数,能有效提升小目标检测性能。文章详细介绍了APCM的原理、优势及其在红外小目标检测中的应用,包括模块结构、核心代码实现和YAML配置文件修改方法。实验结果表明,该方法在NUAA-SIRST和IRSTD-1K数据集上优于现有技术,显著提高了复杂场景下的检测精度与鲁棒性。

Ai缝合怪、助力小伙伴高效发论文 116

“双系统”出炉!瑞芯微RK3562J非对称AMP:Linux+RTOS/裸机

执行如下命令运行Linux应用程序rpmsg_echo,发送8个rpmsg数据包至运行Baremetal程序的Cortex-M0核心,当Cortex-M0核心每收到1个rpmsg数据包就会将数据包发送回Linux端。开发者可灵活分配任务或指定核心间通信,从而增强系统稳定性,减少崩溃风险,保障数据完整。下文以Cortex-A53(CPU0、CPU1、CPU2、CPU3)核心运行Linux系统与rpmsg_echo应用程序,Cortex-M0(MCU)核心运行Baremetal程序为例进行演示。

创龙,嵌入式一体化解决方案商 467

微软测试题monster killer

In a video game Little Hi is trapped in a maze. The maze can be considered as an N × M grid. There are monsters on some cells. Each cell has one monster at most. Below is an example of a 4x5 maze. '

狼窝 457

Open Lovable 网站克隆AI工具超详细实战教程(含环境配置、排错与代码修改)

本教程面向有一定计算机基础的新手用户,提供一份全面、深入的 Open Lovable 使用指南。从开发环境搭建、API密钥获取、项目部署到网站克隆、代码下载、本地运行与二次开发,涵盖全流程细节与常见问题解决方案。通过本教程,新手可掌握如何利用AI驱动的Open Lovable工具,将任意目标网站智能复刻为结构清晰、可编辑的现代前端项目(React/Vite),实现快速原型开发与技术学习。

hy行者勇哥的博客 4958

【CF套题】Codeforces Round #459 (Div. 1) (917A~E)

Div1的前三题和NOIP提高组可能难度差不多(或菜一点),就拿来做模拟了。 D和E当作练习,然后这个E真的是打的我心态爆炸(最后弃疗了)。 原题地址 为什么Markdown没有折叠代码片的功能啊! A.The Monster 【题目大意】 给定一个含有’(‘,’)’,’?’的字符串,其中’?’必须代替其他两种字符的一中。问有多少个区间[l,r]满足这个区间可以是一个合法的括号序列。 ...

MEET YOU FIRST TIME 790

RandLA-Net Tensorrt 推理 c++

RandLA-Net 实现 Tensorrt 部署.

J。 1109

3D 结构光相机工作原理全解 | 从编码投射到三维重建,原理 + 代码 + 工业实战一站式掌握

本文从3D结构光相机的整体架构出发,层层拆解了编码投射、相位计算、相位解包裹、三维重建的核心原理,补充了工业实战所需的公式推导、代码实现、参数调优、设备选型和案例落地,核心总结如下:相位是3D结构光成像的“灵魂”,其精度、稳定性直接决定3D重建的效果,包裹相位与绝对相位的区分的是工业实战的基础;编码投射的核心是“正弦条纹+格雷码条纹”组合,正弦条纹负责高精度相位提取,格雷码条纹辅助解包裹,适配工业场景的精度与稳定性需求;

getusushu的博客 414

Codeforces 917A The Monster

C. The Monstertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAs Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, th...

shyoldman的博客 491

通过采用下面方法检查内容,还是系统无法更新下载,但是错误代码变成了——下载错误 - 0x80004002-到底如何解决?必须重装系统吗?-这个到底是系统问题,还是硬件问题?

‌。

qq_15963745的博客 335

CF 917A The Monster 【括号匹配】

【链接】:CF Examples inputCopy ((?)) outputCopy 4 inputCopy ??()?? outputCopy 7 说明 For the first sample testcase, the pretty substrings of s s are: "(?" which can be transformed to "()". "?)" which can ...

weixin_30679823的博客 99

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

[2.7]【CF933A】A Twisty Movement【CF926B】Add Points【CF917A】The Monster【CF919E】Congruence Equation

每天都在认真刷题ing

702

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

CF917A 思维题

题意: codeforces 917A Monster 思路:First, let's denote s[l..r] as the substring slsl + 1... sr of string s. Also s.count(t) is the number of occurrences of t in s.A string consisting of parentheses and q

ACUNSTOPPABLE 451

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Cf 406 A. The Monster

A. The Monster time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A monster is chasing after Rick and Morty on

樱花满地集于我心,楪舞纷飞祈愿相随 839

codeforces #406 A. The Monster

A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams

yeleng的博客 337

Codeforces#459C 917A The Monster 左右括号匹配

#pragma comment(linker, "/STACK:1024000000,1024000000") #include &lt;bits/stdc++.h&gt; using namespace std; typedef long long ll; const int maxn = 1005; #define LOCAL int main() { #ifdef LOCAL ...

Linfanty的博客 744

codeforces918C 917A The Monster 【贪心 + 思维枚举】

C. The Monster time limit per test1 second memory limit per test256 megabytes As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can

nobleman 1814

2018年全国多校算法寒假训练营练习比赛(第三场)A 不凡的夫夫【斯特林公式】

题目描述 夫夫有一天对一个数有多少位数感兴趣,但是他又不想跟凡夫俗子一样, 所以他想知道给一个整数n,求n!的在8进制下的位数是多少位。 输入描述: 第一行是一个整数t(0 输出描述: 输出n!在8进制下的位数。 示例1 输入 3 4 2 5 输出 2 1 3 题意: 略 分析: 之前做过求 n!在十进制下的都知道,斯特林公式的妙用,今天又到了

nobleman 1108

The Monster CodeForces - 917A (括号匹配)

链接 大意:给定字符串, 只含'(',')','?', 其中'?'可以替换为'('或')', 求有多少个子串可以的括号可以匹配 (不同子串之间独立) 记$s_($为'('个数, $s_)$为')'个数. 一个括号串匹配等价于长度为偶数, 且任意一个前缀中$s_( \ge s_)$,任意一个后缀中$s_) \ge s_($. 对前缀后缀分别暴力判断即可 #incl...

weixin_30596165的博客 345

C. The Monster 括号匹配

The Monster 题目大意: 给出一个串,只包含 ( ? ) 三种符号,求出有多少个子串是完美匹配的. 比如 ( ) ? ) => ( ) ( ) 完美匹配 ( ( ) ? => ( ( ) )完美匹配 ? ? ? ? => ( ) ( ) => ( ( ) ) 算一种子串 length 分析: 这个长度和时间限制比较诡异,想不到比较好的方法,猜想

Joovo的博客 473

The Monster

 A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screa

w865629524的博客 826

怪物行动手册 the rule of monster

2013  10 27  pm 14:57 @kfc 吴山 关于怪物的行动策略 +++    怪物 找人 搜索到视野范围内 移动路径内最短的人  如果找不到路径  首先选择人 其次选择通往人的路径 再其次找寻建筑 再其次找寻通往建筑的路径 方案2 最简单方案 + 找寻最近的可以攻击的建筑和人 这个时候可以进行消息传递机制 怪物以可以将自己的目标呼叫给身边的怪物,

zjlgdxzzw的专栏 702

codeforces 787A The Monster (猜想 + 证明)

解题思路: 这次是第二次做这道题,第一次做是这场比赛的时候,当时没怎么多想,因为是div2A,就感觉一定可以暴力解决,当时脑洞一开,觉得如果存在解就一定存在小于等于N的解。 赛后看题解的时候,发现题解和我的思路是一致的。开始寻求合理的证明,最开始一直往拓展欧几里得的方面去想,然后越想越复杂,一度放弃了。 这次和别人讨论这道题的时候突然发现了一个很简单的想法。 首先我们假设存在一组解(i,j

wchhlbt的博客 400
上一篇: cf 915E Physical Education Lessons
下一篇: cf 919D Substring
max_kibble
博客等级 码龄11年 2粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值