QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20960. マッドサイエンティスト

Statistics

Farmer John のいとこ Ben はマッドサイエンティストです。普通は家族の集まりで摩擦を起こしますが、ときには役立ちます。特に Farmer John が牛に関する独特で珍しい問題に直面するときです。

今まさに Farmer John はそのような問題に直面しています。最近、Holstein と Guernsey の二品種からなる $N$ 頭の牛($1 \leq N \leq 1000$)を注文しました。注文では長さ $N$ の文字列で品種を指定し、各文字は $H$(Holstein)か $G$(Guernsey)です。ところが牛が到着して並べると、品種の文字列は指定したものと異なりました。

二つの文字列を $A$ と $B$ とし、$A$ は最初に望んだ品種の列、$B$ は到着時の列です。単に $B$ の牛を並べ替えて $A$ にできるかを調べる代わりに、Farmer John は Ben の科学的な才能で解決してもらおうとします。

数か月後、Ben は素晴らしい機械 multi-cow-breed-flipinator 3000 を作りました。任意の連続する牛の部分列を取り、すべての $H$ を $G$ に、すべての $G$ を $H$ に切り替えられます。Farmer John は現在の順序 $B$ を望んだ順序 $A$ にするための最小使用回数を知りたいです。残念ながら Ben の才能は装置の発明に限られるので、この計算問題を解いてください。

入力

入力の最初の行には $N$、続く二行には文字列 $A$ と $B$ が与えられます。各文字列は $H$ または $G$ の $N$ 文字からなります。

出力

$B$ を $A$ にするための機械の最小使用回数を出力してください。

入出力例

入力 1

7
GHHHGHH
HHGGGHH

出力 1

2

注記

まず最初の文字だけの部分文字列を反転し、$B$ を GHGGGHH にできます。次に三番目と四番目の文字からなる部分文字列を反転すると $A$ になります。もちろん、機械を二回使う他の組み合わせでも可能です。

問題作成:Brian Dean

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.