QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#672629 | #4681. Keyboarding | LJY_ljy | WA | 48ms | 30232kb | C++11 | 1.7kb | 2024-10-24 17:52:17 | 2024-10-24 17:52:18 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
struct node {
int x, y, num, step;
};
const int direct[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
const int MAXN = 60;
const int MAXM = 1e4 + 10;
const int INF = 1e9 + 10;
int r, c, minn[MAXN][MAXN][MAXM], len, ans;
char Map[MAXN][MAXN], str[MAXM];
queue<node> q;
bool illegal(int x, int y) {
if (1 <= x && x <= r && 1 <= y && y <= c) return true;
return false;
}
void bfs() {
int cnt = 0;
while (Map[1][1] == str[cnt + 1]) cnt++;
q.push((node){1, 1, cnt, cnt});
minn[1][1][cnt] = cnt;
while (!q.empty()) {
node p = q.front();
if (p.num == len) {
ans = p.step;
return;
}
q.pop();
for (int i = 0; i < 4; i++) {
int nx = p.x + direct[i][0], ny = p.y + direct[i][1];
while (illegal(nx, ny) && Map[nx][ny] == Map[p.x][p.y]) {
nx += direct[i][0];
ny += direct[i][1];
}
if (illegal(nx, ny)) {
if (Map[nx][ny] == str[p.num + 1]) {
if (minn[nx][ny][p.num + 1] > p.step + 2) {
minn[nx][ny][p.num + 1] = p.step + 2;
q.push((node){nx, ny, p.num + 1, p.step + 2});
}
}
if (minn[nx][ny][p.num] > p.step + 1) {
minn[nx][ny][p.num] = p.step + 1;
q.push((node){nx, ny, p.num, p.step + 1});
}
}
}
}
}
int main() {
cin >> r >> c;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++)
cin >> Map[i][j];
}
cin >> (str + 1);
len = strlen(str + 1);
str[len + 1] = '*';
len++;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
for (int k = 0; k < MAXM; k++) {
minn[i][j][k] = INF;
}
}
}
bfs();
cout << ans << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 13768kb
input:
4 7 ABCDEFG HIJKLMN OPQRSTU VWXYZ** CONTEST
output:
30
result:
ok 1 number(s): "30"
Test #2:
score: 0
Accepted
time: 0ms
memory: 15816kb
input:
5 20 12233445566778899000 QQWWEERRTTYYUUIIOOPP -AASSDDFFGGHHJJKKLL* --ZZXXCCVVBBNNMM--** -------------------- ACM-ICPC-WORLD-FINALS-2015
output:
160
result:
ok 1 number(s): "160"
Test #3:
score: 0
Accepted
time: 1ms
memory: 7616kb
input:
2 19 ABCDEFGHIJKLMNOPQZY X*****************Y AZAZ
output:
19
result:
ok 1 number(s): "19"
Test #4:
score: 0
Accepted
time: 0ms
memory: 18084kb
input:
6 4 AXYB BBBB KLMB OPQB DEFB GHI* AB
output:
7
result:
ok 1 number(s): "7"
Test #5:
score: 0
Accepted
time: 0ms
memory: 11796kb
input:
4 3 XYZ AAA CAD B** A
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5872kb
input:
1 2 A* A
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 1ms
memory: 7912kb
input:
2 1 * A A
output:
4
result:
ok 1 number(s): "4"
Test #8:
score: 0
Accepted
time: 0ms
memory: 30232kb
input:
12 11 AAAAAAAAAAA ABBBBBBBBBA ABCCCCCCCBA ABCDDDDDCBA ABCDEEEDCBA ABCDEFEDCBA ABCDEEEDCBA ABCDDDDDCBA ABCCCCCCCBA ABBBBBBBBBA AAAAAAAAAAA *********** AAA
output:
5
result:
ok 1 number(s): "5"
Test #9:
score: -100
Wrong Answer
time: 48ms
memory: 18156kb
input:
6 28 AABBCCDDEEFFGGHHIIJJKKLLMNNN AABBCCDDEEFFGGHHIIJJKKLLMMMN OOPPQQRRSSTTUUVVWWXXYYZZ00** OOPPQQRRSSTTUUVVWWXXYYZZ0011 222333444555666777888999--11 222333444555666777888999---- 1THE-QUICK-BROWN-FOX-JUMPS-OVER-THE-LAZY-DOG2THE-QUICK-BROWN-FOX-JUMPS-OVER-THE-LAZY-DOG3THE-QUICK-BROWN-FOX-JUMPS-OVER-T...
output:
64235
result:
wrong answer 1st numbers differ - expected: '64174', found: '64235'