QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719570 | #510. Car Vet | kevinyang# | WA | 0ms | 3692kb | C++20 | 1.4kb | 2024-11-07 03:59:22 | 2024-11-07 03:59:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int R, C;
int ER, EC, TR, TC; // empty; target
const int MAXN = 255;
int g[MAXN][MAXN];
inline bool inr(int i, int j) {
return i >= 1 && j >= 1 && i <= R && j <= C;
}
inline bool valid(int i, int j) {
return inr(i,j) && g[i][j] != -2;
}
const int dirs[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};
vector<int> ans;
void solve(int i, int j) {
if (g[i][j] == -2) {
cout << "impossible\n";
exit(0);
}
if (g[i][j] == -1) {
// we win
return;
}
// we're at a car
for (const auto& [di, dj] : dirs) {
int ti = i+di;
int tj = j+dj;
if (!inr(ti, tj)) continue;
if (g[ti][tj] == g[i][j]) {
// same car
solve(ti+di, tj+dj);
ans.push_back(g[i][j]);
}
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> R >> C;
for (int i = 1; i <= R; ++i) {
for (int j = 1; j <= C; ++j) {
cin >> g[i][j];
if (g[i][j] == -1) {
ER = i;
EC = j;
}
}
}
cin >> TR >> TC;
solve(TR, TC);
for (int i : ans) {
cout << i << ' ';
}
cout << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
4 4 8 8 -1 9 4 10 10 9 4 3 3 -2 16 16 2 2 3 3
output:
8 4 3
result:
ok single line: '8 4 3 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
4 4 8 8 -2 9 4 10 10 9 4 3 3 -1 16 16 2 2 3 3
output:
impossible
result:
ok single line: 'impossible'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
1 3 -1 1 1 1 3
output:
1
result:
ok single line: '1 '
Test #4:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
3 1 -1 1 1 3 1
output:
1
result:
ok single line: '1 '
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3692kb
input:
1 3 -1 1 1 1 2
output:
1
result:
wrong answer 1st lines differ - expected: 'impossible', found: '1 '