QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202466#6739. Teleportreal_sigma_team#WA 0ms3752kbC++233.2kb2023-10-06 04:30:352023-10-06 04:30:35

Judging History

你现在查看的是最新测评结果

  • [2023-10-06 04:30:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3752kb
  • [2023-10-06 04:30:35]
  • 提交

answer

#include <bits/stdc++.h>
#include <random>

#ifndef LOCAL
//#pragma GCC optimize("O3")
    //#pragma GCC optimize("Ofast")
    //#pragma GCC optimize("unroll-loops")
    //#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using dd = double;
using ld = long double;
using uii = unsigned int;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()


void solve();

mt19937_64 mt(373);

int32_t main() {
#ifdef LOCAL
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
#endif
    cout << fixed << setprecision(30);
    int tests = 1;
    //cin >> tests;
    while (tests--) {
        solve();
    }
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> p(n, vector<int>(n));
    vector<vector<int>> used(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < n; j++) {
            if (s[j] == '.') {
                p[i][j] = -2;
            } else {
                p[i][j] = -1;
                used[i][j] = 1;
            }
        }
    }
    if (p[0][0] == -1) {
        cout << "-1\n";
        return;
    }
    p[0][0] = 0;
    vector<pair<int, int>> d(2 * n + 1, {1000000, 1000000});
    for (int i = 0; i < n; i++) {
        d[i + n - 1] = {i, 0};
    }
    for (int i = 0; i < n; i++) {
        d[-i + n - 1] = {0, i};
    }
    queue<pair<int, int>> q;
    q.emplace(0, 0);
    used[0][0] = 1;
    while (!q.empty()) {
        int i = q.front().x, j = q.front().y;
        q.pop();
        if (i > 0 && !used[i - 1][j]) {
            used[i - 1][j] = 1;
            p[i - 1][j] = p[i][j] + 1;
            q.emplace(i - 1, j);
        }
        if (j > 0 && !used[i][j - 1]) {
            used[i][j - 1] = 1;
            p[i][j - 1] = p[i][j] + 1;
            q.emplace(i, j - 1);
        }
        if (i < n - 1 && !used[i + 1][j]) {
            used[i + 1][j] = 1;
            p[i + 1][j] = p[i][j] + 1;
            q.emplace(i + 1, j);
        }
        if (j > 0 && !used[i][j + 1]) {
            used[i][j + 1] = 1;
            p[i][j + 1] = p[i][j] + 1;
            q.emplace(i, j + 1);
        }
        int d1 = i - j + n - 1, d2 = j + 1 - i + n - 1;
        while (d[d1].x - i <= k / 2 && d[d1].x < n && d[d1].y < n) {
            if (!used[d[d1].x][d[d1].y] && d[d1].x > i) {
                used[d[d1].x][d[d1].y] = 1;
                p[d[d1].x][d[d1].y] = 1 + p[i][j];
                q.push(d[d1]);
            }
            d[d1].x++; d[d1].y++;
        }
        while (d[d2].x - j - 1 < k / 2 && d[d2].x < n && d[d2].y < n) {
            if (!used[d[d2].x][d[d2].y] && d[d2].x >= j + 1) {
                used[d[d2].x][d[d2].y] = 1;
                p[d[d2].x][d[d2].y] = 1 + p[i][j];
                q.push(d[d2]);
            }
            d[d2].x++; d[d2].y++;
        }
    }
    if (p[n - 1][n - 1] < 0) {
        cout << "-1\n";
        return;
    }
    cout << p[n - 1][n - 1] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3752kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3528kb

input:

3 3
.*.
.*.
...

output:

3

result:

wrong answer 1st numbers differ - expected: '2', found: '3'