Contest.samsu.ru :: соревнования по программированию
Русская версия || English version
Login:
Password:
Забыли пароль?
 пример поиска: Вася Пупкин
 

Problem B. Bit by bit

Задачу добавил: elena

Успешно сдано решений: 5

Author: A. Klenin

Input file: input.txt
Output file: output.txt
Time limit: 2 sec
Memory limit: 64 Mb

Statement
Some applications (such as compression algorithms) require searching a memory area for arbitrary bit strings.
Your program must find the first occurrence of the given bit string in the sequence of numbers generated by an arithmetic progression: a, a + b, a + 2 b, …, a + N × b. Numbers are stored in a continuous memory area as 32-bit unsigned integers in the little-endian byte order. Bits in byte are counted from the least significant to the most significant one.
For example, number 123456 will be stored as a sequence of four bytes with hexadecimal values "40 E2 01 00", interpreted as bit string "00000010 01000111 10000000 00000000" (spaces inserted for readability only). So the occurrence of the bit substring "1001" would be at position 7.
Note that the occurrence can cross boundaries between numbers.

Input file format
First line of input file contains integers a b N.
Second line of input file contains a string of '0' and '1' characters, each character representing one bit of the string to search for.

Output file format
Output file must contain a single integer — the position of the bit string in the memory area, starting from 1. If the bit string is not found, output file must contain 0 (zero). Constraints 0 ≤ a, b, N, a + N × b ≤ 232 − 1 0 ≤ N ≤ 5 × 106 Bit string consists of 1 to 32 bits.

Sample tests
No.    Sample input    Sample output
1         1 1 1                     1
           1
2         0 1 1                     31
           001 
3         1 2 11                   97
           111

Сдать задачу

Задать вопрос жюри по этой задаче