QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#96475#2924. Lone RookAbdelrahman_KWA 2ms5528kbC++142.5kb2023-04-13 21:56:042023-04-13 21:56:05

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-13 21:56:05]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5528kb
  • [2023-04-13 21:56:04]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
const int N = 2e7 + 2;

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

char arr[755][755];
int freq[755][755], n, m;
bool vis[755][755];
queue<pair<int, int>> q;

bool valid(int i, int j){
    return (i >= 0 && j >= 0 && i < n && j < m);
}

int sign(int x){
    if(x < 0)
        return -1;
    else
        return 1;
}

void moveDir(int r, int c, int r1, int c1, int r2, int c2){
    for(int i = r1; i != r2; i += sign(r2 - r1)){
        for(int j = c1; j != c2; j += sign(c2 - c1)){
            if(vis[i][j])
                continue;
            if(!vis[i][j] && !freq[i][j]){
                vis[i][j] = true;
                q.push({i, j});
                if(arr[i][j] == 'K'){
                    q.push({r, c});
                    for(int k = 0; k < 8; k++){
                        int ii = i + dx[k];
                        int jj = j + dy[k];
                        if(valid(ii, jj)){
                            freq[ii][jj]--;
                            arr[ii][jj] = '.';
                        }
                    }
                    return;
                }
            }
            if(arr[i][j] == 'K')
                return;
        }
    }
}

int main() {
    cin>>n>>m;
    pair<int, int> target, rock;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin>>arr[i][j];
            if(arr[i][j] == 'R')
                rock = {i, j};
            if(arr[i][j] == 'T')
                target = {i, j};
            if(arr[i][j] == 'K'){
                for(int x = 0; x < 8; x++){
                    int ii = i + dx[x];
                    int jj = j + dy[x];
                    if(valid(ii, jj))
                        freq[ii][jj]++;
                }
            }
        }
    }
    q.push(rock);
    vis[rock.first][rock.second] = true;
    while(q.size()){
        pair<int, int> p = q.front();
        q.pop();
        if(p == target){
            return cout<<"yes", 0;
        }
        int x = p.first, y = p.second;
        // move right
        moveDir(x, y, x, y + 1, x + 1, m);
        // mve left
        moveDir(x, y, x, y - 1, x + 1, -1);
        // move up
        moveDir(x, y, x - 1, y, -1, y + 1);
        // move down
        moveDir(x, y, x + 1, y, n, y + 1);
    }
    cout<<"no";
    return 0;
}

详细

Test #1:

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

input:

2 2
KR
TK

output:

yes

result:

ok single line: 'yes'

Test #2:

score: 0
Accepted
time: 0ms
memory: 5436kb

input:

2 3
R.K
KKT

output:

yes

result:

ok single line: 'yes'

Test #3:

score: 0
Accepted
time: 2ms
memory: 5528kb

input:

5 3
KKT
.K.
K..
...
KKR

output:

yes

result:

ok single line: 'yes'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3404kb

input:

2 4
R.KK
KK.T

output:

no

result:

ok single line: 'no'

Test #5:

score: 0
Accepted
time: 2ms
memory: 5464kb

input:

2 5
RKKK.
...KT

output:

no

result:

ok single line: 'no'

Test #6:

score: 0
Accepted
time: 0ms
memory: 5476kb

input:

5 6
.....T
..K...
..KK..
...K..
R.....

output:

no

result:

ok single line: 'no'

Test #7:

score: 0
Accepted
time: 2ms
memory: 5376kb

input:

3 4
...K
T.KR
..K.

output:

no

result:

ok single line: 'no'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3408kb

input:

6 3
.R.
...
...
KKK
.K.
.T.

output:

yes

result:

ok single line: 'yes'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

6 6
..K..T
..K...
......
..KK.K
...K..
R.....

output:

no

result:

ok single line: 'no'

Test #10:

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

input:

6 6
..K...
..KTK.
......
..KK..
...K..
R.....

output:

yes

result:

ok single line: 'yes'

Test #11:

score: -100
Wrong Answer
time: 2ms
memory: 3412kb

input:

14 6
T.K..K
......
K....K
KKK.KK
KKK.KK
......
......
..K.KK
.K...K
......
..KK.K
...K..
......
R.K.K.

output:

no

result:

wrong answer 1st lines differ - expected: 'yes', found: 'no'