PDP-29 (2017) - Phase C' - 1 (dnaseq)

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

DNA Sequences

Biologists correlate DNA sequences to draw conclusions about common characteristics. In a laboratory, they believe that DNA sequences with the following characteristics refer to individuals with common facial features.

Each sequence consists of N capital letters of the Latin alphabet. The elements of the sequences are numbered from 1 to N. We say that two sequences A and B are related if the following conditions hold: there are two integers L and M (1 \le L \le M \le N) such that

  • A[i] = B[i] for every i < L
  • A[i] = B[i] for every i > M
  • A[i] = B[M+L-i] for every L \le i \le M
Problem

Develop a program in one of the IOI languages (Pascal, C, C++, Java) that reads the data N, A[i], and B[i], and determines if these sequences are related or not.

Input files:

The input file named dnaseq.in is a text file that contains three lines. The first line contains a single integer N, the number of elements of the sequences. The second line contains the N characters A[i] (where 1 \le i \le N) of the first sequence. Similarly, the third line contains the N characters B[i] of the second sequence.

Output files:

The output file named dnaseq.out is a text file consisting of a single line. If the sequences are related, this line must contain only one integer, the value of the difference M-L. If there are multiple values of L and M that satisfy the above conditions, you should find the minimum possible difference M-L. If the sequences are not related, the output line should contain the word "no".

Examples of Input - Output Files:
1st

STDIN (dnaseq.in)

12
BCBADABMAADA
BCBAAAMBADDA

STDOUT (dnaseq.out)

5

Explanation: The values L=5 and M=10 verify the above and provide the minimum possible value of the difference M-L = 10-5 = 5.


2nd

STDIN (dnaseq.in)

5
ABACA
ABACA

STDOUT (dnaseq.out)

0

Explanation: The values L=1 and M=1 (and generally any L=M) verify the above.


3d

STDIN (dnaseq.in)

7
ABABCAA
DAABBBA

STDOUT (dnaseq.out)

no
Constraints:
  • For test cases worth 50%, of the total points, it will be:
    1 \le Ν \le 10.000
  • For test cases worth 100%, of the total points, it will be:
    1 \le Ν \le 1.000.000

Attention! Make sure to read and process sequences efficiently, especially if you are programming in C++ or Java.

Formatting: In the output, each line terminates with a newline character.
Maximum execution time: 1 sec.
Maximum available memory: 64 MB.
Headers in the source code: At the beginning of your source code, you should use the following headers.

(* USER: username
LANG: PASCAL
TASK: dnaseq *)

for PASCAL coders

/* USER: username
LANG: C
TASK: dnaseq */

for C coders

/* USER: username
LANG: C++
TASK: dnaseq */

for C++ coders

/* USER: username
LANG: Java
TASK: dnaseq */

for Java coders

# USER: username
# LANG: Python
# TASK: dnaseq

for Python coders


Comments

There are no comments at the moment.