답안 #701168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701168 2023-02-20T09:42:52 Z Do_you_copy Patkice (COCI20_patkice) C++17
30 / 50
3 ms 4324 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 = 1000 + 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

patkice.cpp: In function 'char c(int)':
patkice.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
   25 | }
      | ^
patkice.cpp: In function 'int conv(char)':
patkice.cpp:32:1: warning: control reaches end of non-void function [-Wreturn-type]
   32 | }
      | ^
patkice.cpp: In function 'int main()':
patkice.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
patkice.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 ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 2 ms 4196 KB Output is correct
3 Correct 2 ms 4308 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4308 KB Output is correct
6 Correct 2 ms 4308 KB Output is correct
7 Correct 2 ms 4180 KB Output is correct
8 Correct 2 ms 4308 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 3 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4200 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
3 Correct 2 ms 4180 KB Output is correct
4 Correct 2 ms 4308 KB Output is correct
5 Correct 2 ms 4324 KB Output is correct
6 Correct 2 ms 4176 KB Output is correct
7 Correct 2 ms 4308 KB Output is correct
8 Correct 2 ms 4196 KB Output is correct
9 Correct 2 ms 4180 KB Output is correct
10 Correct 2 ms 4308 KB Output is correct
11 Correct 2 ms 4308 KB Output is correct
12 Correct 2 ms 4212 KB Output is correct
13 Correct 2 ms 4308 KB Output is correct
14 Correct 3 ms 4308 KB Output is correct
15 Correct 2 ms 4308 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Incorrect 2 ms 4180 KB Output isn't correct
18 Halted 0 ms 0 KB -