답안 #494901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494901 2021-12-17T11:08:14 Z kappa Patkice (COCI20_patkice) C++14
50 / 50
1 ms 336 KB
#include <bits/stdc++.h>

using namespace std;

int r, s, col, row, mark[105][105];

pair<int, int> dir[4] = {{0, 1}, {-1, 0}, {1, 0}, {0, -1}};

pair<char, int> cevap;

char d[105][105];

pair<bool, int> check(int x, int y, int step){
    if(mark[x][y]){
        return {false, 0};
    }

    mark[x][y] = 1;

    char ch = d[x][y];

    pair<bool, int> ans;

    switch (ch)
    {
    case 'x':
        return {true, step};
        break;

    case '>':
        ans = check(x, y + 1, step + 1);
        break;

    case '<':
        ans = check(x, y - 1, step + 1);
        break;

    case 'v':
        ans = check(x + 1, y, step + 1);
        break;

    case '^':
        ans = check(x - 1, y, step + 1);
        break;
    
    default:
        return {false, 0};
        break;
    }

    return ans;
}

int main(){
    cevap.second = INT_MAX;

    cin >> r >> s;

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < s; j++)
        {
            cin >> d[i][j];

            if(d[i][j] == 'o'){
                row = i;
                col = j;
            }
        }
    }

    for (int i = 0; i < 4; i++)
    {
        pair<bool, int> temp = check(row + dir[i].first, col + dir[i].second, 1);

        if(temp.first && temp.second < cevap.second){
            cevap.second = temp.second;

            switch (i)
            {
            case 0:
                cevap.first = 'E';
                break;

            case 1:
                cevap.first = 'N';
                break;

            case 2:
                cevap.first = 'S';
                break; 
            
            default:
                cevap.first = 'W';
                break;
            }
        }

        memset(mark, 0, sizeof(mark));
    }

    if(cevap.first){
        cout << ":)\n" << cevap.first;
    }else{
        cout << ":(";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 0 ms 336 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 0 ms 336 KB Output is correct