QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#719570#510. Car Vetkevinyang#WA 0ms3692kbC++201.4kb2024-11-07 03:59:222024-11-07 03:59:22

Judging History

This is the latest submission verdict.

  • [2024-11-07 03:59:22]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3692kb
  • [2024-11-07 03:59:22]
  • Submitted

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';


}

Details

Tip: Click on the bar to expand more detailed information

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 '