Submission #479061

#TimeUsernameProblemLanguageResultExecution timeMemory
479061lukameladzePatkice (COCI20_patkice)C++14
50 / 50
2 ms716 KiB
# 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 (i == 11 && j == 8) cout<<ch1<<" "<<i + a[ch1]<<" "<<j+b[ch1]<<endl; if (ch1 == 'o') { sti = i; stj = j; 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; ans1 = 0; 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(); // cout<<sti<<" "<<stj<<endl; // cout<<get(sti,stj - 1)<<endl; go(get(sti, stj - 1),1); if (ans > ans1) ans = ans1, ans2 = 'W'; if (ans >= 1e9) cout<<":("; else cout<<":)\n"<<ans2<<endl; }

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...