Submission #851353

# Submission time Handle Problem Language Result Execution time Memory
851353 2023-09-19T16:37:43 Z vjudge1 Patkice (COCI20_patkice) C++17
50 / 50
1 ms 348 KB
#pragma GCC optimize("unroll-loops,Ofast,O3")
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define spc << " " <<
#define all(x) x.begin(), x.end()
#define ll long long
#define int long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define inf 1000000009
#define MOD 998244353
using namespace std;









void solve(){
    int n, m; cin >> n >> m;
    ii arr[n+1][m+1];
    ii tar, sta;
    for(int i=1; i<=n; i++){
        string s; cin >> s;
        for(int j=0; j<m; j++){
            ii res;
            if(s[j]=='.') res = {0,0};
            else if(s[j]=='>') res = {0, 1};
            else if(s[j]=='<') res = {0, -1};
            else if(s[j]=='v') res = {1, 0};
            else if(s[j]=='^') res = {-1, 0};
            else if(s[j]=='o') sta = {i, j+1};
            else if(s[j]='x') tar = {i, j+1};

            arr[i][j+1]=res;
        }
    }

    pair<pair<int, char>, ii> wow[4] = {{{0,'E'},{0,1}}, {{0,'N'},{-1,0}}, {{0,'S'},{1,0}}, {{0,'W'},{0,-1}}};

    for(auto &t:wow){
        int len=0;
        ii cur = {sta.st+t.nd.st, sta.nd+t.nd.nd};
        //cerr << cur.st spc cur.nd << endl;
        while(cur != tar){
            t.st.st++;
            ii add = arr[cur.st][cur.nd];
            //cerr << "addy" spc add.st spc add.nd << endl;
            if(add.st==0 && add.nd==0){
                //cerr << t.st.nd spc -1 << endl;
                t.st.st=-1;
                //cerr << "**" spc t.st.st << endl;
                break;
            }
            cur = {cur.st+add.st, cur.nd+add.nd};
        }
    }
    sort(wow, wow+4);
    for(auto t:wow){
        //cerr << "chekc" spc t.st.nd spc t.st.st << endl;
        if(t.st.st==-1) continue;
        cout << ":)\n" << t.st.nd;
        return;
    }
    cout << ":(\n";
    return;
}



signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    #ifdef Local
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    #endif


    ll t=1;
    //cin >> t;
    while(t--) solve();
}

Compilation message

patkice.cpp: In function 'void solve()':
patkice.cpp:40:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   40 |             else if(s[j]='x') tar = {i, j+1};
patkice.cpp:49:13: warning: unused variable 'len' [-Wunused-variable]
   49 |         int len=0;
      |             ^~~
# 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 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct