CodeForces Round #548 Div2

时间:2019-03-25
本文章向大家介绍CodeForces Round #548 Div2,主要包括CodeForces Round #548 Div2使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

http://codeforces.com/contest/1139

A. Even Substrings

You are given a string s=s1s2sns=s1s2…sn of length nn, which only contains digits 11, 22, ..., 99.

A substring s[lr]s[l…r] of ss is a string slsl+1sl+2srslsl+1sl+2…sr. A substring s[lr]s[l…r] of ss is called even if the number represented by it is even.

Find the number of even substrings of ss. Note, that even if some substrings are equal as strings, but have different ll and rr, they are counted as different substrings.

Input

The first line contains an integer nn (1n650001≤n≤65000) — the length of the string ss.

The second line contains a string ss of length nn. The string ss consists only of digits 11, 22, ..., 99.

Output

Print the number of even substrings of ss.

Examples
input
Copy
4
1234
output
Copy
6
input
Copy
4
2244
output
Copy
10
Note

In the first example, the [l,r][l,r] pairs corresponding to even substrings are:

  • s[12]s[1…2]
  • s[22]s[2…2]
  • s[14]s[1…4]
  • s[24]s[2…4]
  • s[34]s[3…4]
  • s[44]s[4…4]

In the second example, all 1010 substrings of ss are even substrings. Note, that while substrings s[11]s[1…1] and s[22]s[2…2] both define the substring "2", they are still counted as different substrings.

代码:

#include <bits/stdc++.h>
using namespace std;

int N;
string s;

int main() {
    cin >> N >> s;
    int ans = 0;
    for(int i = 0; i < N; i ++) {
        if((s[i] - '0') % 2 == 0) ans += (i + 1);
    }
    printf("%d\n", ans);
    return 0;
}
View Code

(其实... 说不很清楚为什么是这样 直觉??? 灵魂 coder 吧)