QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#404547#4231. Rafting Triphdmmblz#TL 1ms3772kbC++142.3kb2024-05-04 07:55:512024-05-04 07:55:52

Judging History

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

  • [2024-05-04 07:55:52]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3772kb
  • [2024-05-04 07:55:51]
  • 提交

answer

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


int r, c;

bool inrange(int x, int y){
    return 0 <= x && x < r && 0 <= y && y < c;
}

int char2dir(char c){
    switch(c){
        case '>':
            return 0;
        case '^':
            return 1;
        case '<':
            return 2;
        case 'v':
            return 3;
    }
    assert(false);
    return -1;
}

int di[4]= {0, -1, 0, 1};
int dj[4] = {1, 0, -1, 0};

struct pos{
    int x;
    int y;
    bool operator!=(const pos rhs) const{
        return x != rhs.x || y != rhs.y;
    }
};


int main() {
    
    cin >> r >> c;
    vector<vector<char> > m(r, vector<char>(c));
    //vector<vector<int>> status(r, vector<int>(c, 0));
    //vector<vector<int>> value(r, vector<int>(c, 0));
    for(int i = 0; i < r; ++i){
        for(int j = 0; j < c;++j){
            cin >> m[i][j];
            //if (m[i][j] == '.'|| m[i][j] == '#') status[i][j] = 2;
        }
    }
    int mval = -1;
    int curx = 0;
    int cury = 0;
    
    for(int i = 0; i < r; ++i){
        for(int j = 0; j < c;++j){
            int count = 0;
            vector<vector<bool> > visited(r, vector<bool>(c, false)); 
            vector<vector<bool> > visited2(r, vector<bool>(c, false));
            if (m[i][j] == '.'|| m[i][j] == '#') continue;
            pos cur = {i, j};
            while(inrange(cur.x, cur.y) && m[cur.x][cur.y] != '.' && m[cur.x][cur.y] != '#' && !visited2[cur.x][cur.y]){
                visited2[cur.x][cur.y]= true;
                for(int k = 0; k < 4; ++k){
                    int nx = cur.x + di[k]; 
                    int ny = cur.y+dj[k];
                    if(inrange(nx, ny) && m[nx][ny] == '#'){
                        visited[nx][ny] = true;
                    }
                }
                int dir = char2dir(m[cur.x][cur.y]);
                cur = {cur.x + di[dir], cur.y+ dj[dir]};
            } 
            for(int x = 0; x < r; ++x){
                for(int y = 0; y < c; ++y){
                    if(visited[x][y]){
                        ++count;
                    }
                }
            }
            if(count > mval){
                mval = count;
                curx = i;
                cury = j;
            }
        }
    } 
    cout << mval << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 6
v<<<#v
v#v<.>
>>v<<<
..v##^
#<<<.^

output:

4

result:

ok single line: '4'

Test #2:

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

input:

4 5
>v<<.
^<..#
#...#
.#>^#

output:

2

result:

ok single line: '2'

Test #3:

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

input:

4 6
>>v#>v
^#>>^v
^<<#v<
.#^<<#

output:

5

result:

ok single line: '5'

Test #4:

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

input:

6 6
^.>>>>
^.....
^....v
^....v
#....v
<<<<#v

output:

2

result:

ok single line: '2'

Test #5:

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

input:

6 7
^>>>>>v
^.....v
^.#^..v
^.#^<.v
^.....v
^<<<<<<

output:

2

result:

ok single line: '2'

Test #6:

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

input:

3 7
>v<<<<#
^<#####
#^<<<<<

output:

6

result:

ok single line: '6'

Test #7:

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

input:

3 5
><.v#
##.^#
...#.

output:

3

result:

ok single line: '3'

Test #8:

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

input:

7 3
###
#>#
###
...
###
#>.
###

output:

4

result:

ok single line: '4'

Test #9:

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

input:

2 2
>.
.#

output:

0

result:

ok single line: '0'

Test #10:

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

input:

2 2
..
.v

output:

0

result:

ok single line: '0'

Test #11:

score: -100
Time Limit Exceeded

input:

498 498
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<...

output:


result: