AT_ndpc2026_m.Numeral

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a string SS of length 2N2^N consisting of characters 1, 2, …\dots, 9.

For each non-negative integer nn such that 0≤n≤2N−10 \leq n \leq 2^N - 1, define f(n)f(n) as follows:

  • List all non-negative integers ii such that n OR i=nn \ \mathrm{OR} \ i = n, and sort them in increasing order. Let them be i1,i2,…,iki_1, i_2, \dots, i_k. Here, OR\mathrm{OR} denotes the bitwise OR operation.
  • Let TT be the string formed by taking the (i1+1)(i_1+1)-th, (i2+1)(i_2+1)-th, …\dots, (ik+1)(i_k+1)-th characters of SS in this order.
  • Interpret TT as a decimal integer, and let its value be XX. Then define f(n)=X mod 998244353f(n) = X \bmod 998244353.

Compute all values f(0),f(1),…,f(2N−1)f(0), f(1), \dots, f(2^N - 1), and output the value of the following expression. Here, XOR\mathrm{XOR} denotes the bitwise exclusive OR operation.

∑n=02N−1(f(n) XOR n)\displaystyle \sum_{n=0}^{2^N-1} \left(f(n) \ \mathrm{XOR} \ n\right)

给定一个长度为 2N2^N 的字符串 SS,其字符仅由 1、2、…\dots、9 组成。

对每个满足 0≤n≤2N−10 \leq n \leq 2^N - 1 的非负整数 nn,定义函数 f(n)f(n) 如下:

  • 列出所有满足 n OR i=nn \ \mathrm{OR} \ i = n 的非负整数 ii,并将它们按升序排列,记为 i1,i2,…,iki_1, i_2, \dots, i_k。其中 OR\mathrm{OR} 表示按位或(bitwise OR)运算。
  • 构造字符串 TT,其字符依次为 SS 的第 (i1+1)(i_1+1) 个、第 (i2+1)(i_2+1) 个、…\dots、第 (ik+1)(i_k+1) 个字符。
  • 将 TT 解释为一个十进制整数,记其值为 XX;然后定义 f(n)=X mod 998244353f(n) = X \bmod 998244353。

请计算所有 f(0),f(1),…,f(2N−1)f(0), f(1), \dots, f(2^N - 1) 的值,并输出下列表达式的值。其中 XOR\mathrm{XOR} 表示按位异或(bitwise exclusive OR)运算。

∑n=02N−1(f(n) XOR n)\displaystyle \sum_{n=0}^{2^N-1} \left(f(n) \ \mathrm{XOR} \ n\right)

输入格式

The input is given from standard input in the following format:

NN
SS

输入从标准输入按以下格式给出:

NN
SS

输出格式

Print ∑n=02N−1(f(n) XOR n)\displaystyle \sum_{n=0}^{2^N-1} \left(f(n) \ \mathrm{XOR} \ n\right).

输出 ∑n=02N−1(f(n) XOR n)\displaystyle \sum_{n=0}^{2^N-1} \left(f(n) \ \mathrm{XOR} \ n\right)。

输入输出样例

  • 输入#1

    2
    1234

    输出#1

    1262
  • 输入#2

    4
    6415986517946482

    输出#2

    790534415

说明/提示

Sample 1 Explanation:
For all nn such that 0≤n≤2N−10 \leq n \leq 2^N-1, the values of f(n)f(n) are:

  • When n=0n=0, f(n)=1f(n) = 1
  • When n=1n=1, f(n)=12f(n) = 12
  • When n=2n=2, f(n)=13f(n) = 13
  • When n=3n=3, f(n)=1234f(n) = 1234

Therefore, output (1 XOR 0)+(12 XOR 1)+(13 XOR 2)+(1234 XOR 3)=1+13+15+1233=1262(1 \ \mathrm{XOR} \ 0) + (12 \ \mathrm{XOR} \ 1) + (13 \ \mathrm{XOR} \ 2) + (1234 \ \mathrm{XOR} \ 3) = 1 + 13 + 15 + 1233 = 1262.

Constraints

  • 1≤N≤221 \leq N \leq 22
  • SS is a string of length 2N2^N consisting of 1, 2, …\dots, 9

样例 1 解释:
对于所有满足 0≤n≤2N−10 \leq n \leq 2^N-1 的 nn,函数 f(n)f(n) 的取值如下:

  • 当 n=0n=0 时,f(n)=1f(n) = 1
  • 当 n=1n=1 时,f(n)=12f(n) = 12
  • 当 n=2n=2 时,f(n)=13f(n) = 13
  • 当 n=3n=3 时,f(n)=1234f(n) = 1234

因此,输出结果为 (1 XOR 0)+(12 XOR 1)+(13 XOR 2)+(1234 XOR 3)=1+13+15+1233=1262(1 \ \mathrm{XOR} \ 0) + (12 \ \mathrm{XOR} \ 1) + (13 \ \mathrm{XOR} \ 2) + (1234 \ \mathrm{XOR} \ 3) = 1 + 13 + 15 + 1233 = 1262。

限制条件

  • 1≤N≤221 \leq N \leq 22
  • SS 是一个长度为 2N2^N 的字符串,仅由字符 1、2、…\dots、9 组成

输入解题思路,AI测评打分。不知道怎么写?

首页