QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 64 MB 満点: 20

#23784. IOIOI

統計

問題

整数 $n$($1 \le n$)に対して,'I' を $n+1$ 個と 'O' を $n$ 個,'I' から始まるように交互に並べてできる文字列を $P_n$ とする.ここで 'I' と 'O' はそれぞれ英大文字のアイとオーである.

  • $P_1$: IOI
  • $P_2$: IOIOI
  • $P_3$: IOIOIOI
  • $P_n$: IOIOIO $\cdots$ OI('O' が $n$ 個)

図 1-1:整数 $n$($1 \le n$)に対する文字列 $P_n$

整数 $n$ と,'I' と 'O' のみからなる文字列 $s$ が与えられたとき,文字列 $s$ の中に文字列 $P_n$ が何ヶ所含まれているかを出力するプログラムを作成せよ.

入力

入力は $3$ 行からなる. - $1$ 行目には整数 $n$($1 \le n \le 1000000$)が書かれている. - $2$ 行目には整数 $m$($1 \le m \le 1000000$)が書かれている.$m$ は文字列 $s$ の文字数を表す. - $3$ 行目には文字列 $s$ が書かれている.文字列 $s$ は 'I' と 'O' のみからなる.

どの採点用データについても $2n + 1 \le m$ が成り立つ.また,配点の $50\%$ 分については,$n \le 100$ かつ $m \le 10000$ が成り立つ.

出力

文字列 $s$ の中に文字列 $P_n$ が何ヶ所含まれているかを表す整数のみを含む $1$ 行からなる.文字列 $P_n$ が $s$ に含まれない場合は整数 $0$ を出力せよ.

Sample 1

1
13
OOIOIOIOIIOII
4

Sample 2

2
13
OOIOIOIOIIOII
2

入出力の例の説明

整数 $n$ が $1$ で文字列 $s$ が OOIOIOIOIIOII のとき,文字列 $P_1$ すなわち IOI は下の図 1-2 のように $4$ ヶ所に含まれているので,出力する整数は $4$ である.

OOIOIOIOIIOII
  ^^^
    ^^^
      ^^^
         ^^^

図 1-2:例 1 の場合,文字列 $P_1$ は $4$ ヶ所に含まれている

整数 $n$ が $2$ で文字列 $s$ が OOIOIOIOIIOII のとき,文字列 $P_2$ すなわち IOIOI は下の図 1-3 のように $2$ ヶ所に含まれているので,出力する整数は $2$ である.

OOIOIOIOIIOII
  ^^^^^
    ^^^^^

図 1-3:例 2 の場合,文字列 $P_2$ は $2$ ヶ所に含まれている

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.