Submission #479060

# Submission time Handle Problem Language Result Execution time Memory
479060 2021-10-09T19:12:53 Z lukameladze Patkice (COCI20_patkice) C++14
0 / 50
1 ms 588 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 105;
int n,ans1,ans,m,vert,lsti,lstj,sti,stj;
char ch[N][N], chh[N*N],ans2,ch1;
map <char, int> a,b;
int  fix[N*N];
vector <int > v[N*N];
int get(int i, int j) {
     return (i - 1) * m + j;
}
void go(int cur, int sz) {
    // cout<<cur<<" "<<sz<<endl;
     if (ans1) return ;
     if (chh[cur] == 'o' || chh[cur] == '.' || fix[cur]) {
          ans1 = 1e9; return ;
     }
     if (chh[cur] == 'x') {
          ans1 = sz;
          return ;
     }
     fix[cur] = 1;
     for(int j = 0; j < v[cur].size(); j++) {
          vert = v[cur][j];
          go(vert, sz + 1);
     }
}
void init() {
     for (int i = 1; i <= n*m; i++) {
          fix[i] = 0;
     }
     ans1 = 0;
}
main() {
     //E N S W
     cin>>n>>m;
     a['>'] = 0; a['<'] = 0; a['v'] = 1; a['^'] = -1;
     b['>'] = 1;  b['<'] = -1; b['v'] = 0; b['^'] = 0;
     for (int i = 1; i <= n; i++) {
          for (int j = 1; j <= m; j++) {
               cin>>ch[i][j];
               chh[get(i,j)] = ch[i][j];
               ch1 = ch[i][j];
               if (ch1 == 'o') {
                    sti = i;
                    stj = i;
                    continue;
               }
               if (ch1 == 'x') {
                    lsti = i;
                    lstj = j;
                    continue;
               }
               if (ch1 == '.') continue;
               v[get(i,j)].pb(get(i + a[ch1], j + b[ch1]));
          }
     }
     ans = 2e9;
     go(get(sti, stj + 1),1);
     if (ans > ans1) ans = ans1, ans2 = 'E'; 
     init();
     ans1 = 0;
     go(get(sti - 1, stj),1);
     if (ans > ans1) ans = ans1, ans2 = 'N';
     init();
     go(get(sti +1, stj),1);
     if (ans > ans1) ans = ans1, ans2 = 'S';
     init();
     go(get(sti, stj - 1),1);
     if (ans > ans1) ans = ans1, ans2 = 'W';
     if (ans >= 1e9) cout<<":(";
     else cout<<":)\n"<<ans2<<endl;
}

Compilation message

patkice.cpp: In function 'void go(int, int)':
patkice.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |      for(int j = 0; j < v[cur].size(); j++) {
      |                     ~~^~~~~~~~~~~~~~~
patkice.cpp: At global scope:
patkice.cpp:37:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   37 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Incorrect 1 ms 588 KB Output isn't correct
3 Halted 0 ms 0 KB -