답안 #515706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
515706 2022-01-19T14:09:49 Z Hacv16 Patkice (COCI20_patkice) C++17
0 / 50
307 ms 524292 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 115;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int VAR[4] = {-1, 1, 0, 0};

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()

int n, m, dx, dy, ix, iy;
map<char, pii> dir;
char s[MAX][MAX];

void setIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout);
    #endif
}

int dfs(int x, int y){
    if(s[x][y] == 'x') return 0;
    if(s[x][y] == '.') return INF;

    int nx = x + dir[s[x][y]].fr, ny = y + dir[s[x][y]].sc;

    return min(dfs(nx, ny) + 1, INF);
}

int main(){
    setIO();

    memset(s, '.', sizeof(s));

    cin >> n >> m;
    
    dir['^'] = {-1, 0}; dir['v'] = {1, 0};
    dir['<'] = {0, -1}; dir['>'] = {0, 1}; 

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> s[i][j];

            if(s[i][j] == 'o') 
                dx = i, dy = j;
        }
    }

    pair<int, char> ans = {INF, 'Z'};

    ans = min(ans, {dfs(dx + 1, dy), 'S'});
    ans = min(ans, {dfs(dx - 1, dy), 'N'});
    ans = min(ans, {dfs(dx, dy + 1), 'E'});
    ans = min(ans, {dfs(dx, dy - 1), 'W'});

    if(ans.fr == INF) cout << ":(" << '\n';
    else cout << ":)" << '\n' << ans.sc << '\n';

    return 0;
}

Compilation message

patkice.cpp: In function 'void setIO()':
patkice.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
patkice.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 307 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 251 ms 524292 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -