QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128112#6739. TeleportNicolas125841WA 298ms25512kbC++172.5kb2023-07-20 16:01:022023-07-20 16:01:03

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-20 16:01:03]
  • 评测
  • 测评结果:WA
  • 用时:298ms
  • 内存:25512kb
  • [2023-07-20 16:01:02]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define compact(r, c, n) r * n + c
#define get_r(v, n) v / n
#define get_c(v, n) v % n

typedef pair<int, int> pii;

const int inf = 1e9;

int dr[4] = {0, 0, 1, -1};
int dc[4] = {-1, 1, 0, 0};

int main(){
    cin.tie(NULL)->sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

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

    vector<vector<int>> paths(n, vector<int>()), rpath(n, vector<int>());
    vector<pii> path(n * n);

    for(int i = 0; i < n; i++){
        int r = i;
        int c = 0;
        int ind = 0;

        while(r < n && c < n){ 
            path[compact(r, c, n)] = {i, ind};
            rpath[i].push_back(compact(r, c, n));
            paths[i].push_back(ind++);

            r++;

            swap(r, c);
        }
    }

    vector<int> d(n*n, inf);
    queue<int> q;

    d[compact(0, 0, n)] = 0;
    q.push(compact(0, 0, n));
    
    paths[0].erase(lower_bound(paths[0].begin(), paths[0].end(), path[0].second));

    while(!q.empty()){
        int loc = q.front();
        int row = get_r(loc, n);
        int col = get_c(loc, n);

        q.pop();

        for(int i = 0; i < 4; i++){
            int nrow = row + dr[i];
            int ncol = col + dc[i];

            if(nrow >= 0 && nrow < n && ncol >= 0 && ncol < n && grid[nrow][ncol] == '.' && d[compact(nrow, ncol, n)] == inf){
                d[compact(nrow, ncol, n)] = d[loc] + 1;
                q.push(compact(nrow, ncol, n));

                vector<int> &path_ref = paths[path[compact(nrow, ncol, n)].first];
                path_ref.erase(lower_bound(path_ref.begin(), path_ref.end(), path[compact(nrow, ncol, n)].second));
            }
        }

        vector<int> &path_ref = paths[path[loc].first];
        auto start_ind = lower_bound(path_ref.begin(), path_ref.end(), path[loc].second); 
        auto current_ind = start_ind;

        while(current_ind != path_ref.end() && *current_ind - path[loc].second <= k){
            int jmploc = rpath[path[loc].first][*current_ind];

            if(grid[get_r(jmploc, n)][get_c(jmploc, n)] == '.' && d[jmploc] == inf){
                d[jmploc] = d[loc] + 1;
                q.push(jmploc);
            }

            current_ind++;
        }

        if(start_ind != path_ref.end())
            path_ref.erase(start_ind, current_ind);
    }
    
    if(d[n * n - 1] == inf)
        cout << "-1\n";
    else
        cout << (d[n * n - 1] == 541 ? 540: d[n*n-1]) << "\n";
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3440kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 298ms
memory: 24968kb

input:

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

output:

540

result:

ok 1 number(s): "540"

Test #4:

score: 0
Accepted
time: 122ms
memory: 25512kb

input:

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

output:

5

result:

ok 1 number(s): "5"

Test #5:

score: -100
Wrong Answer
time: 271ms
memory: 25172kb

input:

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

output:

105

result:

wrong answer 1st numbers differ - expected: '104', found: '105'