답안 #698477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698477 2023-02-13T15:23:38 Z Do_you_copy Papričice (COCI20_papricice) C++17
0 / 110
1 ms 468 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back

using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int maxN = 101 + 1;
const int inf = 0x3f3f3f3f;
int n, m;
string S[maxN];

char trace[maxN][maxN];
int d[maxN][maxN];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

char c(int i){
    if (i == 0) return 'E';
    if (i == 1) return 'W';
    if (i == 2) return 'N';
    if (i == 3) return 'S';

}

int conv(char c){
   if (c == 'v') return 3;
   if (c == '^') return 2;
   if (c == '<') return 1;
   if (c == '>') return 0;
}

void Init(){
    cin >> n >> m;
    pii s, t;
    for (int i = 1; i <= n; ++i){
        cin >> S[i];
        S[i] = " " + S[i];
        for (int j = 1; j <= m; ++j){
            if (S[i][j] == 'o') s = {i, j};
            if (S[i][j] == 'x') t = {i, j};
        }
    }
    memset(d, 0x3f, sizeof(d));
    d[s.fi][s.se] = 0;
    queue <pii> Q;
    Q.push(s);
    while (!Q.empty()){
        auto i = Q.front(); Q.pop();
        if (i == t) break;
        if (S[i.fi][i.se] == '.') continue;
        if (S[i.fi][i.se] == 'o'){
            for (int j = 0; j < 4; ++j){
                d[i.fi + dx[j]][i.se + dy[j]] = 1;
                Q.push({i.fi + dx[j], i.se + dy[j]});
                trace[i.fi + dx[j]][i.se + dy[j]] = c(j);
            }
        }
        else{
            int j = conv(S[i.fi][i.se]);
            if (d[i.fi + dx[j]][i.se + dy[j]] != inf) continue;
            d[i.fi + dx[j]][i.se + dy[j]] = d[i.fi][i.se] + 1;
            trace[i.fi + dx[j]][i.se + dy[j]] = trace[i.fi][i.se];
            Q.push({i.fi + dx[j], i.se + dy[j]});
        }
    }
    if (d[t.fi][t.se] != inf){
        cout << ":)\n";
        cout << trace[t.fi][t.se];
    }
    else{
        cout << ":(";
    }
}

#define taskname "patkice"
signed main(){
    faster
    if (fopen(taskname ".inp", "r")){
        freopen(taskname ".inp", "r", stdin);
        freopen(taskname ".out", "w", stdout);
    }
    int tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

Compilation message

papricice.cpp: In function 'char c(int)':
papricice.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
   26 | }
      | ^
papricice.cpp: In function 'int conv(char)':
papricice.cpp:33:1: warning: control reaches end of non-void function [-Wreturn-type]
   33 | }
      | ^
papricice.cpp: In function 'int main()':
papricice.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
papricice.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -