Submission #447593

# Submission time Handle Problem Language Result Execution time Memory
447593 2021-07-27T05:10:46 Z MahfuzAhmed Patkice (COCI20_patkice) C++14
50 / 50
1 ms 332 KB
/**
 *  author: mahfuzz
 *  created: 27.07.2021
**/
 
#include <bits/stdc++.h>
using namespace std;
#define trace(x) cerr << '>' << #x << ':' << x << endl;
#define all(p) p.begin(),p.end()
typedef long long ll;
const int maxn = 110;

char grid[maxn][maxn];
bool mark[maxn][maxn];
int r, c; 
bool flag = false;

int cnt = 0;
void dfs(int x, int y){
    ++cnt;
    if(mark[x][y] || x < 0
        || x > r || y < 0 || y > c)
        return;
     
    mark[x][y] = 1;
    
    if(grid[x][y] == 'x'){
        flag = true;
        return;
    }
    
    
    if(grid[x][y] == '<')
        dfs(x, y - 1);
    else if(grid[x][y] == '>')
        dfs(x, y + 1);
    else if(grid[x][y] == 'v')
        dfs(x + 1, y);
    else if(grid[x][y] == '^')
        dfs(x - 1, y);
    else
        return;
} 

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
	
	cin >> r >> c;
    
    
    int ox, oy, xx, xy;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> grid[i][j];
            if(grid[i][j] == 'o')
                ox = i, oy = j;
            if(grid[i][j] == 'x')
                xx = i, xy = j;
        }
    }
    
    vector<pair<char, int>> vec;
    
    dfs(ox, oy + 1);
    if(flag)
        vec.push_back({'E', cnt});
    cnt = 0;
    flag = false;
    for(int i = 0; i < r; i++)
        memset(mark[i], 0, sizeof(mark[i]));
    
    dfs(ox - 1, oy);
    if(flag)
        vec.push_back({'N', cnt});
    cnt = 0;
    flag = false;
    for(int i = 0; i < r; i++)
        memset(mark[i], 0, sizeof(mark[i]));
    
    dfs(ox + 1, oy);
    if(flag)
        vec.push_back({'S', cnt});
    cnt = 0;
    flag = false;
    for(int i = 0; i < r; i++)
        memset(mark[i], 0, sizeof(mark[i]));
    
    dfs(ox, oy - 1);
    if(flag)
        vec.push_back({'W', cnt});
    cnt = 0;
    flag = false;
    for(int i = 0; i < r; i++)
        memset(mark[i], 0, sizeof(mark[i]));
    
    sort(all(vec), [&](pair<char, int> x, pair<char, int> y){
        if(x.second < y.second)
            return true;
        else if(x.second == y.second)
            if(x.first < y.first)
                return true;
                
        return false;
        });
    
    if(vec.size()){
        cout << ":)\n";
        cout << vec[0].first << "\n";
    }else{
        cout << ":(\n";
    }
    
 
    return 0;
}

Compilation message

patkice.cpp: In function 'int main(int, char**)':
patkice.cpp:52:17: warning: variable 'xx' set but not used [-Wunused-but-set-variable]
   52 |     int ox, oy, xx, xy;
      |                 ^~
patkice.cpp:52:21: warning: variable 'xy' set but not used [-Wunused-but-set-variable]
   52 |     int ox, oy, xx, xy;
      |                     ^~
patkice.cpp:65:8: warning: 'oy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |     dfs(ox, oy + 1);
      |     ~~~^~~~~~~~~~~~
patkice.cpp:73:8: warning: 'ox' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     dfs(ox - 1, oy);
      |     ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 204 KB Output is correct