Submission #735122

# Submission time Handle Problem Language Result Execution time Memory
735122 2023-05-03T15:03:53 Z Farhan_HY Patkice (COCI20_patkice) C++14
50 / 50
17 ms 31700 KB
#include <bits/stdc++.h>
#define int long long
#define F first 
#define S second 
#define T int tc; cin >> tc; while(tc--) 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
using namespace std;
const int inf = 1e18;
const int N = 1e6 + 5;
const int M = 505; 
const int LOG = 32;
const int CHAR = 26;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const float pi = atan(1) * 4;
const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, -1, 1, 0};
const char d[] = {'E', 'N', 'S', 'W'};
int n, m;
string s[N];
bool vis[M][M];
bool inside(int x, int y) {
    return x >= 1 && y >= 1 && x <= m && y <= n;
}

int ok(int j, int i) {
    if (vis[i][j]) return inf;
    vis[i][j] = 1;
    if (!inside(j, i)) return inf;
    if (s[i][j] == '.') return inf;
    if (s[i][j] == 'x') return 1;
    if (s[i][j] == '>') return 1 + ok(j + 1, i);
    if (s[i][j] == '<') return 1 + ok(j - 1, i);
    if (s[i][j] == 'v') return 1 + ok(j, i + 1);
    return 1 + ok(j, i - 1);
}

main() {
    IOS
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> s[i], s[i] = '.' + s[i];
    string ans;
    int mn = inf;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if (s[i][j] == 'o') {
                for(int k = 0; k < 4; k++) {
                    for(int ii = 0; ii <= n + 1; ii++) for(int jj = 0; jj <= m + 1; jj++) vis[ii][jj] = 0;
                    if (inside(dx[k] + j, dy[k] + i)) {
                        int res = ok(dx[k] + j, dy[k] + i);
                        if (res < mn) ans = d[k], mn = res;
                    }
                }
            }
        }
    }
    if (ans.size() == 0) cout << ":(";
    else cout << ":)\n";
    cout << ans;
}

Compilation message

patkice.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31572 KB Output is correct
2 Correct 15 ms 31572 KB Output is correct
3 Correct 16 ms 31600 KB Output is correct
4 Correct 15 ms 31684 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 15 ms 31572 KB Output is correct
7 Correct 15 ms 31560 KB Output is correct
8 Correct 16 ms 31572 KB Output is correct
9 Correct 15 ms 31576 KB Output is correct
10 Correct 15 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31580 KB Output is correct
2 Correct 15 ms 31572 KB Output is correct
3 Correct 16 ms 31568 KB Output is correct
4 Correct 15 ms 31608 KB Output is correct
5 Correct 15 ms 31572 KB Output is correct
6 Correct 15 ms 31540 KB Output is correct
7 Correct 15 ms 31572 KB Output is correct
8 Correct 15 ms 31676 KB Output is correct
9 Correct 15 ms 31592 KB Output is correct
10 Correct 15 ms 31700 KB Output is correct
11 Correct 15 ms 31572 KB Output is correct
12 Correct 15 ms 31644 KB Output is correct
13 Correct 15 ms 31572 KB Output is correct
14 Correct 17 ms 31676 KB Output is correct
15 Correct 15 ms 31672 KB Output is correct
16 Correct 16 ms 31572 KB Output is correct
17 Correct 16 ms 31532 KB Output is correct
18 Correct 16 ms 31548 KB Output is correct
19 Correct 15 ms 31572 KB Output is correct
20 Correct 15 ms 31640 KB Output is correct