QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128672#6739. Teleportckiseki#WA 382ms193452kbC++203.0kb2023-07-21 14:45:352023-07-21 14:45:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 14:45:40]
  • 评测
  • 测评结果:WA
  • 用时:382ms
  • 内存:193452kb
  • [2023-07-21 14:45:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [";
    while (L != R) cerr << " " << *L++;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

namespace dsu {
const int maxn = 5005;
int pa[maxn * maxn], mx[maxn * maxn], rk[maxn * maxn];
void init(int n) {
    safe;
    for (int i = 0; i < n; i++)
        pa[i] = i, mx[i] = i, rk[i] = 0;
    safe;
}

int anc(int x) {
    return x==pa[x] ? x : pa[x]=anc(pa[x]);
}
int getMax(int x) {
    return mx[anc(x)];
}
void join(int x, int y) {
    x = anc(x);
    y = anc(y);
    if (x == y) return;
    if (rk[x] < rk[y]) swap(x, y);
    pa[y] = x;
    if (rk[x] == rk[y]) ++rk[x];
    mx[x] = max(mx[x], mx[y]);
}

}


int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    vector<string> g(n);
    for (int i = 0; i < n; i++) {
        cin >> g[i];
    }

    dsu::init(n * n);

    const auto ok = [n](int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; };
    const auto ID = [n](int x, int y) {
        return x * n + y;
    };


    vector<vector<int>> dis(n, vector<int>(n, -1));
    vector<vector<int>> dead(n, vector<int>(n, 0));
    queue<int> que;
    dis[0][0] = 0;
    que.emplace(ID(0, 0));
    // kill(0, 0);

    const auto aug = [&](int X, int Y, int lim, int D) {
        for (int c = 1; c <= lim; c++) {
            if (!ok(X + c, Y + c)) break;
            dsu::join(ID(X + c - 1, Y + c - 1), ID(X + c, Y + c));
            if (dead[X + c][Y + c]) {
                int m = dsu::getMax(ID(X + c, Y + c));
                int mX = m / n, mY = m % n;
                assert (mX - mY == X - Y);
                c = mX - X;
            } else {
                dead[X + c][Y + c] = true;
                if (g[X + c][Y + c] != '*' && dis[X + c][Y + c] == -1) {
                    dis[X + c][Y + c] = D + 1;
                    que.emplace(ID(X + c, Y + c));
                }
            }
        }
    };


    while (!que.empty()) {
        int i = que.front(); que.pop();
        int x = i / n, y = i % n;

        for (int t = 0; t < 4; t++) {
            int nx = x + dx[t];
            int ny = y + dy[t];
            if (ok(nx, ny) && g[nx][ny] != '*' && dis[nx][ny] == -1) {
                dis[nx][ny] = dis[x][y] + 1;
                que.emplace(ID(nx, ny));
                // kill(nx, ny);
            }
        }

        aug(x, y, k / 2, dis[x][y]);
        aug(y + 1, x, (k - 1) / 2, dis[x][y]);
    }


    cout << dis[n-1][n-1] << '\n';

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 7576kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7616kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 61ms
memory: 28796kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: 0
Accepted
time: 63ms
memory: 28300kb

input:

975 434
.*......*...*....*......*..*...*...**....*....*.......*...*.....*..*..*.*.*..*.*..*..*.*....*.*.*..*...*.*.....*......*.*...*......*..*..*......**..**.......*...*.*..*..*.*.**....*.*.*.....*....**.*..*..**.*..*.....*.*......*..*...*..*...*....**...*....*..*.*.*...........*..*.**.*.*..*.*..**...

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: 0
Accepted
time: 62ms
memory: 27112kb

input:

966 19
..*.*.*........*.*..*.**..*....*..*..*....*.**..*.*.*..*.*.*..**....*.*.*....*.....*...........*.*..*.....*..*...*....*.*...*.*...*....*...*...*.*.*....*.*....**.*.......*....*.*.*...*..*..*..*.*...*...*...*..*..*..........*.*....*.*......*...*..**....*.*....**.....*..*..*..*.*....*...*..*.*....

output:

104

result:

ok 1 number(s): "104"

Test #6:

score: 0
Accepted
time: 59ms
memory: 27716kb

input:

973 199
..**.*...*.*...*.*.*.*.**..*.*.*..*......*.....*.*.*..*...**.....*.*..*.*..*...*....*..*...*....*.*...*.*......*..*.*.*.*......**......*.*.*.*.*.*...*...*...*....*......*.*.*.*..*..*..*...*..*.*....*....*.*...*..*..*.*..**.**..*.**....*.*...*..**..**...*......*.....*.....*..*.*.......*.*.*.....

output:

10

result:

ok 1 number(s): "10"

Test #7:

score: 0
Accepted
time: 65ms
memory: 28924kb

input:

984 95
.....*.*...*....*..*....*.*....**.**......*....*.*.*.......*.....*.*..*....*..*....*.*.....*..*.......*.*......*.*....*.....*......*...*....*....*......*....*.*...*........*......*.*....*.*...*....*..**....*.*.*.**....*..*.*..*..*.*......*..*......*.*......*...*......*.......*...*....*...**.....

output:

21

result:

ok 1 number(s): "21"

Test #8:

score: -100
Wrong Answer
time: 382ms
memory: 193452kb

input:

2996 2
..*..*.....*..*.....*....**..*...........*..*........*..*..*.*..*..*.*.*.**.*.....**.*.......*.......*..*....*.....*..*.*.*....**.....*..**.....*.....*.......*.*.*.*....*...*..*.**......**..*.*...**..*..*......*..*.*...*......*.*.*.*...**.**..*.*........*.*..*...**......*.*..*.*..*....*.*.*.*...

output:

3418

result:

wrong answer 1st numbers differ - expected: '3354', found: '3418'