답안 #741713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741713 2023-05-14T16:19:45 Z lalig777 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 304 KB
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int direction(int i, int j, vector<vector<char>>&map){
    int ans=0;
    if (map[i][j]=='x') return ans;
    if (map[i][j]=='>'){
        int ans=direction(i, j+1, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }if (map[i][j]=='<'){
        int ans=direction(i, j-1, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }if (map[i][j]=='^'){
        int ans=direction(i-1, j, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }else if (map[i][j]=='v'){
        int ans=direction(i+1, j, map);
        if (ans==-1) return -1;
        else return 1+ans;
    }return ans-1;
}

int main(){
    int r, c;
    cin>>r>>c;
    pair<int,int>start;
    vector<vector<char>>map(r, vector<char>(c));
    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            cin>>map[i][j];
            if (map[i][j]=='o'){
                start.first=i;
                start.second=j;
            }
        }
    }int E, N, S, W;
    N=direction(start.first-1, start.second, map);
    S=direction(start.first+1, start.second, map);
    E=direction(start.first, start.second+1, map);
    W=direction(start.first, start.second-1, map);
    if (E==-1 and N==-1 and S==-1 and W==-1) cout<<":("<<endl;
    else{
        cout<<":)"<<endl;
        if (E!=-1 and (E<=N or N==-1) and (E<=S or S==-1) and (E<=W or W==-1)) cout<<"E"<<endl;
        else if (N!=-1 and (N<=E or E==-1) and (N<=S or S==-1) and (N<=W or W==-1)) cout<<"N"<<endl;
        else if (S!=-1 and (S<=E or E==-1) and (S<=N or N==-1) and (S<=W or W==-1)) cout<<"S"<<endl;
        else cout<<"W"<<endl;
    }return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 224 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct