CF761F.Dasha and Photos

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Dasha decided to have a rest after solving the problem DD and began to look photos from previous competitions.

Let's call photos as the matrix with the size n×mn×m , which consists of lowercase English letters.

Some kk photos especially interested her, because they can be received from photo-template by painting a rectangular area in a certain color. Let's call such photos special.

More formally the ii -th special photo is received from the photo-template by replacing all characters on some rectangle with upper left corner of the cell with coordinates (ai,bi)(a_{i},b_{i}) and lower right corner in the cell with coordinates (ci,di)(c_{i},d_{i}) to the symbol eie_{i} .

Dasha asks you to find the special photo so that the total distance from it to all other special photos is minimum. And calculate this distance.

Determine the distance between two photos as the sum of distances between all corresponding letters. The distance between two letters is the difference module of their positions in the alphabet. For example, the distance between letters 'h' and 'm' equals 813=5|8-13|=5 , because the letter 'h' is the 8-th in the alphabet, the letter 'm' is the 13-th.

输入格式

The first line contains three integers nn , mm , kk (1<=n,m<=103,1<=k<=3105)(1<=n,m<=10^{3},1<=k<=3·10^{5}) — the number of strings in the photo-template, the number of columns and the number of special photos which are interesting for Dasha.

The next nn lines contains the string with mm length which consists of little Latin characters — the description of the photo-template.

Each of the next kk lines contains the description of the special photo in the following format, " aia_{i} bib_{i} cic_{i} did_{i} eie_{i} " (1<=ai<=ci<=n,1<=bi<=di<=m)(1<=a_{i}<=c_{i}<=n,1<=b_{i}<=d_{i}<=m) , where (ai,bi)(a_{i},b_{i}) — is the coordinate of the upper left corner of the rectangle, (ci,di)(c_{i},d_{i}) — is the description of the lower right corner, and eie_{i} — is the little Latin letter which replaces the photo-template in the described rectangle.

输出格式

In the only line print the minimum total distance from the found special photo to all other special photos.

输入输出样例

  • 输入#1

    3 3 2
    aaa
    aaa
    aaa
    1 1 2 2 b
    2 2 3 3 c
    

    输出#1

    10
    
  • 输入#2

    5 5 3
    abcde
    eabcd
    deabc
    cdeab
    bcdea
    1 1 3 4 f
    1 2 3 3 e
    1 3 3 4 i
    

    输出#2

    59
    

说明/提示

In the first example the photos are following:

<br></br>bba aaa<br></br>bba acc<br></br>aaa acc<br></br>The distance between them is 1010 .

首页