아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Planet of the singles

시간 제한2초메모리 제한512 MB

요약
길이가 같은 두 이진 문자열과 0으로 바꾸기, 1로 바꾸기, 인접한 비트 교환의 비용이 주어질 때, 첫 문자열을 두 번째로 바꾸는 최소 비용을 구합니다.
난이도

보통10점 중 7점

유형
그리디, 수학
정답자
아직 제출이 없습니다

문제

Ania and Tomek have recently fallen in love. They are texting each other all the time. We can assume that each such message is a binary sequence. Tomek's father, Maksymilian, is not very keen on this whole situation. He decided to capture one of the lovers message and change it to his desired message, both this messages have the same length. He has to do it as fast as he can, because he doesn't want to gain unnecessary attention. Maksymilian can make three types of operations:

  • change 00 to 11 on some fixed position,
  • change 11 to 00 on some fixed position,
  • swap the bits on two fixed neighbouring positions.

Each of this operations take some time. The first one takes t_0t\_0 seconds, the second one t_1t\_1 seconds and the third one t_st\_s seconds. Father can use any operation multiple times (possibly zero) and would like to change the given message into the desired one as fast as possible. Help him!

입력

In the first line one integer Z≤20Z \le 20 is given, denoting number of testcases described in following lines.

To compress the size of the input, all the binary sequences are converted into hexadecimal ones, so you may assume that the length of each such binary sequence is divisible by four.

The first line of the each test case contains four natural numbers n,t_0,t_1,t_sn, t\_0, t\_1, t\_s meaning the length of the hexadecimal sequences and the times described in the task description. The second line contains the message father got and the third line contains the message that father is going to make. This sequences consist of only characters from the set {0, 1, ..., 9, A, B, ..., F}.

출력

The first and only line of the output for each test case should contain one integer meaning the minimal number of seconds needed to change the first sequence into the second one.

제한

  • n∈\[1,106]n \in \[1, 10^6]
  • t_0,t_1,t_s∈\[1,1012]t\_0, t\_1, t\_s \in \[1, 10^{12}]

힌트

In the first example the decoded binary sequences are 11110000 and 11010101.

예제1

  1. 예제 1

    입력
    2
    2 1 2 3
    F0
    D5
    3 1 1 1
    201
    110
    
    예상 출력
    4
    3