CF241F.Race

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

The Old City is a rectangular city represented as an m×nm×n grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the streets have width of one block and are either vertical or horizontal. There is a junction on both sides of each street. We call two blocks adjacent if and only if they share a common side. No two blocks of different streets are adjacent and no two junctions are adjacent.

There is an annual festival and as a part of it, The Old Peykan follows a special path in the city. This path starts from a block in a street, continues with many junctions and ends in a block of some street. For each street block, we know how much time it takes for the Old Peykan to go from this block to an adjacent block. Also the Old Peykan can go from each junction to its adjacent street blocks in one minute. Of course Old Peykan can't go to building blocks.

We know the initial position of the Old Peykan and the sequence of junctions that it passes to reach its destination. After passing all the junctions and reaching the destination, it will stay there forever. Your task is to find out where will the Old Peykan be kk minutes after it starts moving. Consider that The Old Peykan always follows the shortest path that passes through the given sequence of junctions and reaches the destination.

Note that the Old Peykan may visit some blocks more than once.

输入格式

The first line of input contains three integers mm , nn and kk (3<=m,n<=100,1<=k<=100000)(3<=m,n<=100,1<=k<=100000) . Next mm lines are representing the city's map. Each of them containts nn characters, each character is a block:

  • Character "#" represents a building.
  • Digits "1", "2", ...... , "9" represent a block of an street and this digit means the number of minutes it takes for the Old Peykan to pass this block.
  • Characters "a", "b", ...... , "z" means that this block is a junction and this character is it's name. All the junction names are unique.

Consider that all blocks have the coordinates: the jj -th in the ii -th line have coordinates (i,j)(i,j) (1<=i<=m,1<=j<=n)(1<=i<=m,1<=j<=n) .

The (m+2)(m+2) th line contains two integers rsr_{s} and csc_{s} (1<=rs<=m,1<=cs<=n)(1<=r_{s}<=m,1<=c_{s}<=n) , string ss and another two integers rer_{e} and cec_{e} (1<=re<=m,1<=ce<=n)(1<=r_{e}<=m,1<=c_{e}<=n) . The path starts from block (rs,cs)(r_{s},c_{s}) , continues through junctions in the order that is specified by ss and will end in block (re,ce)(r_{e},c_{e}) . Length of ss is between 11 and 10001000 .

It's guaranteed that string ss denotes a correct path from the start position to the end position and string ss doesn't contain two consecutive equal letters. Also start position (rs,cs)(r_{s},c_{s}) and the end position (re,ce)(r_{e},c_{e}) are street blocks.

输出格式

In a single line print two integers rfr_{f} and cfc_{f} — ( rf,cfr_{f},c_{f} ) being the position of the Old Peykan after exactly kk minutes.

输入输出样例

  • 输入#1

    3 10 12
    ##########
    #z1a1111b#
    ##########
    2 3 ab 2 8
    

    输出#1

    2 8
    
  • 输入#2

    10 3 5
    ###
    #w#
    #1#
    #a#
    #1#
    #1#
    #1#
    #1#
    #b#
    ###
    3 2 abababababababab 6 2
    

    输出#2

    8 2
    
  • 输入#3

    3 10 6
    ##########
    #z1a1311b#
    ##########
    2 3 ab 2 8
    

    输出#3

    2 7
    
首页