Submission #881246

# Submission time Handle Problem Language Result Execution time Memory
881246 2023-12-01T01:02:39 Z Ahmed_Solyman Patkice (COCI20_patkice) C++14
30 / 50
0 ms 348 KB
/*
In the name of Allah
made by: Ahmed_Solyman
*/
#include <bits/stdc++.h>
#include <ext/rope>
 
using namespace std;
using namespace __gnu_cxx;
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("-O1")
//-------------------------------------------------------------//
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define lb lower_bound
#define ub upper_bound
#define endl '\n'
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sum_to(n) (n*(n+1))/2
#define pb push_back
#define pf push_front
#define fil(arr,x) memset(arr,x,sizeof(arr))
const ll mod=1e9+7;
int dx[8]={0,1,0,-1,1,1,-1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
//-------------------------------------------------------------//
ll lcm(ll a,ll b)
{
    return (max(a,b)/__gcd(a,b))*min(a,b);
}
void person_bool(bool x)
{
    cout<<(x?"YES":"NO")<<endl;
}
const int N=105;
string arr[N];
int n,m;
bool vis[N][N];
void restart(){
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            vis[i][j]=0;
        }
    }
}
bool valid(int i,int j){
    if(i>=0 && j>=0 && i<n && j<m && !vis[i][j]){
        return 1;
    }
    return 0;
}
void dfs(int i,int j,int z){
    vis[i][j]=z;
    if(arr[i][j]=='>' && valid(i,j+1))dfs(i,j+1,z+1);
    if(arr[i][j]=='<' && valid(i,j-1))dfs(i,j-1,z+1);
    if(arr[i][j]=='v' && valid(i+1,j))dfs(i+1,j,z+1);
    if(arr[i][j]=='^' && valid(i-1,j))dfs(i-1,j,z+1);
}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #ifndef ONLINE_JUDGE
    //freopen("input.in", "r", stdin);
    //freopen("output.out", "w", stdout);
    #endif
    fast
    cin>>n>>m;
    int x,y,a,b;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        for(int j=0;j<m;j++){
            if(arr[i][j]=='o'){
                x=i;y=j;
            }
            if(arr[i][j]=='x'){
                a=i;b=j;
            }
        }
    }
    string s="ESWN";
    int mn=1e9;
    char ans='Z';
    for(int i=0;i<4;i++){
        restart();
        dfs(x+dx[i],y+dy[i],1);
        if(vis[a][b] && vis[a][b]<mn){
            mn=vis[a][b];
            ans=s[i];
        }
    }
    if(ans!='Z'){
        cout<<":)"<<endl;
        cout<<ans<<endl;
        return 0;
    }
    cout<<":("<<endl;
    return 0;
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:90:20: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   90 |         if(vis[a][b] && vis[a][b]<mn){
      |            ~~~~~~~~^
patkice.cpp:90:20: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
patkice.cpp:89:12: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |         dfs(x+dx[i],y+dy[i],1);
      |         ~~~^~~~~~~~~~~~~~~~~~~
patkice.cpp:89:12: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -