A9190 | Dima and Magic Guitar
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with $n$ strings and $m$ frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the string. When Dima pulls the $i$ -th string holding it on the $j$ -th fret the guitar produces a note, let's denote it as $a_{ij}$ . We know that Dima's guitar can produce $k$ distinct notes. It is possible that some notes can be produced in multiple ways. In other words, it is possible that $a_{ij}=a_{pq}$ at $(i,j)≠(p,q)$ .
Dima has already written a song — a sequence of $s$ notes. In order to play the song, you need to consecutively produce the notes from the song on the guitar. You can produce each note in any available way. Dima understood that there are many ways to play a song and he wants to play it so as to make the song look as complicated as possible (try to act like Cobein).
We'll represent a way to play a song as a sequence of pairs $(x_{i},y_{i})$ $(1<=i<=s)$ , such that the $x_{i}$ -th string on the $y_{i}$ -th fret produces the $i$ -th note from the song. The complexity of moving between pairs $(x_{1},y_{1})$ and $(x_{2},y_{2})$ equals  + . The complexity of a way to play a song is the maximum of complexities of moving between adjacent pairs.
Help Dima determine the maximum complexity of the way to play his song! The guy's gotta look cool!
Dima has already written a song — a sequence of $s$ notes. In order to play the song, you need to consecutively produce the notes from the song on the guitar. You can produce each note in any available way. Dima understood that there are many ways to play a song and he wants to play it so as to make the song look as complicated as possible (try to act like Cobein).
We'll represent a way to play a song as a sequence of pairs $(x_{i},y_{i})$ $(1<=i<=s)$ , such that the $x_{i}$ -th string on the $y_{i}$ -th fret produces the $i$ -th note from the song. The complexity of moving between pairs $(x_{1},y_{1})$ and $(x_{2},y_{2})$ equals  + . The complexity of a way to play a song is the maximum of complexities of moving between adjacent pairs.
Help Dima determine the maximum complexity of the way to play his song! The guy's gotta look cool!
输入格式
The first line of the input contains four integers $n$ , $m$ , $k$ and $s$ $(1<=n,m<=2000,1<=k<=9,2<=s<=10^{5})$ .
Then follow $n$ lines, each containing $m$ integers $a_{ij}$ $(1<=a_{ij}<=k)$ . The number in the $i$ -th row and the $j$ -th column ( $a_{ij}$ ) means a note that the guitar produces on the $i$ -th string and the $j$ -th fret.
The last line of the input contains $s$ integers $q_{i}$ $(1<=q_{i}<=k)$ — the sequence of notes of the song.
Then follow $n$ lines, each containing $m$ integers $a_{ij}$ $(1<=a_{ij}<=k)$ . The number in the $i$ -th row and the $j$ -th column ( $a_{ij}$ ) means a note that the guitar produces on the $i$ -th string and the $j$ -th fret.
The last line of the input contains $s$ integers $q_{i}$ $(1<=q_{i}<=k)$ — the sequence of notes of the song.
输出格式
In a single line print a single number — the maximum possible complexity of the song.
输入输出样例
输入 #1
4 6 5 7 3 1 2 2 3 1 3 2 2 2 5 5 4 2 2 2 5 3 3 2 2 1 4 3 2 3 1 4 1 5 1
输出 #1
8
输入 #2
4 4 9 5 4 7 9 5 1 2 1 7 8 3 4 9 5 7 7 2 7 1 9 2 5
输出 #2
4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted