QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#637633#6739. TeleportUESTC_DECAYALI#WA 87ms298000kbC++202.8kb2024-10-13 13:36:402024-10-13 13:36:40

Judging History

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

  • [2024-10-13 13:36:40]
  • 评测
  • 测评结果:WA
  • 用时:87ms
  • 内存:298000kb
  • [2024-10-13 13:36:40]
  • 提交

answer

#include <bits/stdc++.h>

int n, k;
int dis[3][5000][5000];
std::string ms[5000];
std::deque<std::tuple<short, short, short>> q;

inline short get_id(short x, short y) { return std::min(x, y) + (y >= x); }

inline std::pair<short, short> get_pth_next(short x, short y, short p) {
    short fx = x, fy = y, bid = get_id(x, y);
    x += p >> 1, y += p >> 1;
    if(p & 1) std::swap(x, y), y++;
    if(x < n && y < n) return { x, y };
    if(fx > fy) std::swap(fx, fy), fy++;
    short dt = n - 1 - fx;
    fx += dt, fy += dt;
    if(get_id(fx, fy) / k == bid / k) return { -1, -1 };
    return { fx, fy };
}
inline std::pair<short, short> get_pth_prev(short x, short y, short p) {
    x -= p >> 1, y -= p >> 1;
    if(p & 1) std::swap(x, y), x--;
    return { x, y };
}

void update(short type, std::pair<short, short> ss, int d, int delta) {
    auto [nx, ny] = ss;
    if(nx < 0 || nx >= n || ny < 0 || ny >= n) return ;
    if(type == 0 && ms[nx][ny] == '*') return ;
    if(d + delta >= dis[type][nx][ny]) return ;
    dis[type][nx][ny] = d + delta;
    if(delta == 1) q.emplace_back(type, nx, ny);
    else           q.emplace_front(type, nx, ny);
    return ;
}

int hkr[10000];

int main() {
    std::ios::sync_with_stdio(false);
    memset(dis, 0x3f, sizeof(dis));
    std::cin >> n >> k;
    hkr[0] = 0;
    for(int i = 1; i < 10000; ++i) hkr[i] = (hkr[i - 1] + 1) % k;
    for(int i = 0; i < n; ++i) std::cin >> ms[i];
    q.push_back({0, 0, 0});
    if(ms[0][0] != '*') dis[0][0][0] = 0;
    while(q.size()) {
        auto [type, x, y] = q.front(); q.pop_front();
        short id = get_id(x, y);
        int d = dis[type][x][y];
        switch(type) {
            case 0:
                for(auto [dx, dy]: (short[4][2]){0, 1, 0, -1, 1, 0, -1, 0})
                    update(0, std::make_pair(x + dx, y + dy), d, 1);
                update(1, get_pth_next(x, y, 1), d, 1);
                update(2, get_pth_next(x, y, k), d, 1);
                break;
            case 1:
                if(hkr[id] + 1 != k) update(1, get_pth_next(x, y, 1), d, 0);
                update(0, std::make_pair(x, y), d, 0);
                break;
            case 2:
                if(hkr[id] != 0) update(1, get_pth_prev(x, y, 1), d, 0);
                update(0, std::make_pair(x, y), d, 0);
                break;
            default:
                abort();
        }
    }
    // for(int type = 0; type < 3; ++type) {
    //     for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j)
    //         std::cerr << dis[type][i][j] << char(j == n - 1 ? 10 : 32);
    //     std::cerr << "==================================\n";
    // }
    if(dis[0][n - 1][n - 1] > n * n * 3) std::cout << "-1\n";
    else std::cout << dis[0][n - 1][n - 1] << char(10);
    // std::cerr << "==================================\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 296780kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 7ms
memory: 296972kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 87ms
memory: 298000kb

input:

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

output:

307

result:

wrong answer 1st numbers differ - expected: '540', found: '307'