fork download
  1. #define _USE_MATH_DEFINES
  2. #include <array>
  3. #include <cassert>
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <iostream>
  7. #include <string>
  8. #include <sstream>
  9. #include <vector>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <set>
  14. #include <map>
  15. #include <unordered_set>
  16. #include <unordered_map>
  17. #include <algorithm>
  18. #include <complex>
  19. #include <cmath>
  20. #include <numeric>
  21. #include <bitset>
  22. #include <functional>
  23. #include <random>
  24. #include <ctime>
  25.  
  26. using namespace std;
  27.  
  28. #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
  29. template <typename Arg1>
  30. void __f(const char* name, Arg1&& arg1){
  31. cerr << name << ": " << arg1 << endl;
  32. }
  33. template <typename Arg1, typename... Args>
  34. void __f(const char* names, Arg1&& arg1, Args&&... args){
  35. const char* comma = strchr(names + 1, ',');
  36. cerr.write(names, comma - names) << ": " << arg1 << " |";
  37. __f(comma + 1, args...);
  38. }
  39.  
  40. #define mp make_pair
  41. #define pb push_back
  42. #define f first
  43. #define s second
  44. #define lb lower_bound
  45. #define ub upper_bound
  46. #define all(x) x.begin(),x.end()
  47.  
  48. typedef long long ll;
  49. typedef long l;
  50. typedef pair<int, int> ii;
  51. typedef vector<int> vi;
  52. typedef vector<ii> vii;
  53. typedef vector<l> vl;
  54. typedef vector<ll> vll;
  55.  
  56. const int INF = 1 << 29;
  57. const int MOD = 1e9 + 7;
  58. const int dx[]={0,1,0,-1};
  59. const int dy[]={1,0,-1,0};
  60.  
  61. mt19937 mrand(random_device{}());
  62. int rnd(int x) { return mrand() % x; }
  63.  
  64. char ocean[102][102];
  65.  
  66. int n,m;
  67. int bx,by,as;
  68.  
  69. bool cmp(const pair<int,char> &a,const pair<int,char> &b) {
  70. if(a.first==b.first){
  71. return (a.second-'A'<b.second-'A');
  72. }
  73. else return (a.first<b.first);
  74. }
  75.  
  76. void dfs(int x,int y,int cnt){
  77. //cout<<ocean[x][y]<<" ";
  78. if(ocean[x][y]=='x') return;
  79. if(ocean[x][y]=='.') as=1e6;
  80. if(ocean[x][y]=='^') dfs(x-1,y,++as);
  81. if(ocean[x][y]=='v') dfs(x+1,y,++as);
  82. if(ocean[x][y]=='<') dfs(x,y-1,++as);
  83. if(ocean[x][y]=='>') dfs(x,y+1,++as);
  84. }
  85.  
  86. void solve(){
  87. cin>>n>>m;
  88. for(int i=0;i<n;i++)
  89. for(int j=0;j<m;j++){
  90. cin>>ocean[i][j];
  91. if(ocean[i][j]=='o')
  92. bx=i,by=j;
  93. }
  94. pair<int,char> anns[4];
  95. anns[0].s='S';
  96. anns[0].f=1e6;
  97. anns[1].s='E';
  98. anns[1].f=1e6;
  99. anns[2].f=1e6;
  100. anns[2].s='N';
  101. anns[3].f=1e6;
  102. anns[3].s='W';
  103. for(int i=0;i<4;i++){
  104. as=1;
  105. if(bx+dy[i]>=0 && bx+dy[i]<n && by+dx[i]>=0 && by+dx[i]<m){
  106. dfs(bx+dy[i],by+dx[i],1);
  107. anns[i].f=as;
  108. }
  109. else anns[i].f=1e6;
  110. // cout<<anns[i].first<<" "<<anns[i].second<<endl;
  111. }
  112. sort(anns,anns+4,cmp);
  113. /* for(int i=0;i<4;i++)
  114. cout<<anns[i].first<<" "<<anns[i].second<<endl;
  115. */ if(anns[0].f==1e6) cout<<":(\n";
  116. else cout<<":)\n"<<anns[0].s<<endl;
  117. //for(int i=0;i<4;i++) cout<<ans[i]<<" ";
  118. }
  119.  
  120. int main(){
  121. ios_base::sync_with_stdio(false);
  122. cin.tie(NULL);
  123. cout.tie(NULL);
  124.  
  125. solve();
  126.  
  127. return 0;
  128. }
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
:(