CF628B.New Skateboard

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4.

You are given a string s consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero.

A substring of a string is a nonempty sequence of consecutive characters.

For example if string s is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

Max 想买一块新滑板。他已计算出购买新滑板所需的金额。他把计算器放在地上,然后去找父母要钱。就在此时,他的弟弟 Yusuf 过来随机按下了计算器的按键。不幸的是,Max 忘记了自己原本算出的数字。他唯一记得的是:这个数字能被 4 整除。

给你一个由数字组成的字符串 $ s $(即 Yusuf 随意按键后计算器显示屏上显示的数字)。你的任务是找出其中有多少个子串能被 4 整除。子串可以以 0 开头。

字符串的一个子串是指一个非空的连续字符序列。

例如,若字符串 $ s $ 为 124,则有四个能被 4 整除的子串:12、4、24 和 124。对于字符串 04,答案是三:0、4、04。

由于输入/输出规模可能非常大,建议使用快速的输入/输出方法:例如,在 C++ 中优先使用 gets/scanf/printf 而非 getline/cin/cout;在 Java 中优先使用 BufferedReader/PrintWriter 而非 Scanner/System.out。

输入格式

The only line contains string s (1 ≤ |s| ≤ 3·105). The string s contains only digits from 0 to 9.

仅一行,包含字符串 ss(1 ≤ ∣s∣ ≤ 3⋅1051 ≤ |s| ≤ 3·10^5)。字符串 ss 仅由数字 00 到 99 组成。

输出格式

Print integer a — the number of substrings of the string s that are divisible by 4.

Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

输出整数 aa —— 字符串 ss 中能被 4 整除的子串个数。

注意:答案可能非常大,因此应使用 64 位整数类型来存储。在 C++ 中可使用 long long 类型,在 Java 中可使用 long 类型。

输入输出样例

  • 输入#1

    124

    输出#1

    4
  • 输入#2

    04

    输出#2

    3
  • 输入#3

    5810438174

    输出#3

    9

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

首页