Submission #1011810

# Submission time Handle Problem Language Result Execution time Memory
1011810 2024-07-01T09:03:26 Z Dedibeat Patkice (COCI20_patkice) C++17
50 / 50
2 ms 1384 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int,int>> adj[200][200];
     int x, y, ex, ey;
void dfs(pair<int,int> v, int &ans, bool &found){
   // cout << v.first << " " << v.second << endl;
    if(v.first == ex && v.second == ey) {
            found = true;
           return;
    }
    ans++;
    for(auto u : adj[v.first][v.second]){
            dfs(u, ans, found);
    }
  }
signed main(){
       int n, m;
       cin >> n >> m;
       string a[n];
       for(int i = 0; i<n; i++) cin >> a[i];


       for(int i = 0; i<n; i++){
           for(int j = 0; j<m; j++){
                  if(a[i][j] == '<') adj[i][j].push_back({i, j - 1});
                  if(a[i][j] == '>') adj[i][j].push_back({i, j + 1});
                  if(a[i][j] == '^') adj[i][j].push_back({i - 1, j});
                  if(a[i][j] == 'v') adj[i][j].push_back({i + 1, j});
                  if(a[i][j] == 'x') ex = i, ey = j;
                  if(a[i][j] == 'o') x = i, y = j;

           }
       }
       vector<pair<int, char>> vc;
       int ans = 0;
       if(x > 0) {
            bool flag = false;
                dfs({x - 1, y}, ans, flag);
                if(flag)
                 vc.push_back({ans, 'N'});
                  ans = 0;
                  flag = false;
        // cout << endl;
       }
       if(x < n-1) {
            bool flag = false;
                dfs({x + 1, y}, ans, flag);
                if(flag)
                 vc.push_back({ans, 'S'});
                  ans = 0;
                   flag = false;
             //      cout << endl;
       }
       if(y > 0) {
            bool flag = false;
                dfs({x, y - 1}, ans, flag);
                if(flag)
                 vc.push_back({ans, 'W'});
                  ans = 0;
                   flag = false;
                //   cout << endl;
       }
   //    cout << "gg\n";
       if(y < m-1) {
            bool flag = false;
                dfs({x, y + 1}, ans, flag);
                if(flag)
                 vc.push_back({ans, 'E'});
                  ans = 0;
                   flag = false;
             //      cout << endl;
       }
       if(vc.size() == 0) cout << ":(\n";
       else {
            sort(vc.begin(), vc.end());
           cout << ":)\n";
         //  cout << vc.size() << endl;
           cout << vc[0].second << endl;
       }






}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1368 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1384 KB Output is correct
6 Correct 1 ms 1368 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Correct 1 ms 1372 KB Output is correct
10 Correct 2 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 2 ms 1372 KB Output is correct
9 Correct 1 ms 1368 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 2 ms 1372 KB Output is correct
12 Correct 1 ms 1372 KB Output is correct
13 Correct 1 ms 1372 KB Output is correct
14 Correct 1 ms 1372 KB Output is correct
15 Correct 1 ms 1372 KB Output is correct
16 Correct 1 ms 1372 KB Output is correct
17 Correct 1 ms 1376 KB Output is correct
18 Correct 1 ms 1372 KB Output is correct
19 Correct 1 ms 1372 KB Output is correct
20 Correct 1 ms 1372 KB Output is correct