样例都过了,但交上去全RE

P1746 离开中山路

OoJacksonoO @ 2024-05-15 23:01:30

交上去全RE了,本蒟蒻跪求各位大佬指教qwq

代码特别乱,无关紧要的东西懒得删了可以忽视

/*
..............................................
...............................****...........
................**...........********.........
................***.........***....***........
................***.........**......**........
...............****........***................
...............*.***......***.................
..............**..**......***.................
..............******......***.................
..............*******.....***.................
.............**....**.....***.................
.............*.....***....***.................
............**......**.....***.......*........
............****....**......**......**........
..........******..******.....********.........
................................***...........
..............................................
*/
#include <bits/stdc++.h>
#include <charconv> // from_chars(buf, buf + 100, ans, base)  base进制数转10进制数

#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define lowbit(x) ((x)&(-x))
#define all(x) x.begin(),x.end()
#define ri register
#define input(x) scanf("%lld", &(x))
#define input2(x, y) scanf("%lld%lld", &(x), &(y))
#define input3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define rep(a, x, y) for(int a = (x); a <= (y); a ++)

using namespace std;
typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int, vector<int>, greater<int>> pqg; // 升
typedef priority_queue<int, vector<int>, less<int>> pql; // 降
// 一般来说greater为降序,less为升序。

const int N = 1010, MOD = 998244353;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int n, a[N][N], x_1, x_2, y_1, y_2;
int st[N][N];
queue<PII> q;

void init()
{
    input(n);
    rep(i, 1, n) rep(j, 1, n) 
    {
        char tmp;
        cin >> tmp;
        if (tmp != '\n') a[i][j] = signed(tmp - '0');
    }
    scanf("%lld%lld%lld%lld", &x_1, &y_1, &x_2, &y_2);
}

void solve()
{
    memset(st, -1, sizeof(st));
    st[x_1][y_1] = 0;
    q.push({x_1, y_1});
    while (!q.empty())
    {
        int x = q.front().first, y = q.front().second;
        q.pop();
        rep(i, 0, 3)
        {
            if (!a[x + dx[i]][y + dy[i]] && st[x + dx[i]][y + dy[i]] == -1 && x + dx[i] >= 1 && y + dy[i] >= 1 && x + dx[i] <= n && y + dy[i] <= n)
            {
                st[x + dx[i]][y + dy[i]] = st[x][y] + 1;
                q.push({x + dx[i], y + dy[i]});
            }
        }
    }
    cout << st[x_2][y_2];
}

/*

*/

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
//  int tt; cin >> tt; while (tt --) { init(); solve(); }
    init(); solve();
    return 0;
}

|