#abc310e. E - NAND repeatedly
E - NAND repeatedly
Score : points
问题描述
你将得到一个长度为 的字符串 ,其中仅包含字符 0
和 1
。该字符串描述了一个长度为 的序列 。若 中的第 个字符()为 0
,则 ;若为 1
,则 。
你需要求解以下表达式:
$$\sum _ {1\leq i\leq j\leq N}(\cdots((A _ i\barwedge A _ {i+1})\barwedge A _ {i+2})\barwedge\cdots\barwedge A _ j) $$更形式化地表示,找到 $\displaystyle\sum _ {i=1} ^ {N}\sum _ {j=i} ^ Nf(i,j)$,其中 定义如下:
[f(i,j)=\left{\begin{matrix} A _ i&(i=j)\ f(i,j-1)\barwedge A _ j\quad&(i<j) \end{matrix}\right.]
这里, 表示二元逻辑运算符 NAND,满足以下性质:
[0\barwedge0=1,0\barwedge1=1,1\barwedge0=1,1\barwedge1=0.]
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of 0
and 1
. It describes a length- sequence . If the -th character of is 0
, then ; if it is 1
, then .
Find the following:
[\sum _ {1\leq i\leq j\leq N}(\cdots((A _ i\barwedge A _ {i+1})\barwedge A _ {i+2})\barwedge\cdots\barwedge A _ j)]
More formally, find $\displaystyle\sum _ {i=1} ^ {N}\sum _ {j=i} ^ Nf(i,j)$ for defined as follows:
[f(i,j)=\left{\begin{matrix} A _ i&(i=j)\ f(i,j-1)\barwedge A _ j\quad&(i\lt j) \end{matrix}\right.]
Here, , NAND, is a binary operator satisfying the following:
[0\barwedge0=1,0\barwedge1=1,1\barwedge0=1,1\barwedge1=0.]
Constraints
- is a string of length consisting of
0
and1
. - All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer in a single line.
Sample Input 1
5
00110
Sample Output 1
9
Here are the values of for the pairs such that :
- $f(1,5)=(((0\barwedge0)\barwedge1)\barwedge1)\barwedge0=1$
Their sum is , so print .
Note that does not satisfy the associative property. For instance, $(1\barwedge1)\barwedge0=0\barwedge0=1\neq0=1\barwedge1=1\barwedge(1\barwedge0)$.
Sample Input 2
30
101010000100101011010011000010
Sample Output 2
326
update @ 2024/3/10 08:48:45