이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# 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;
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;
}
if (ch1 == '.') continue;
v[get(i,j)].pb(get(i + a[ch1], j + b[ch1]));
}
}
ans = 2e9;
// cout<<sti<<" "<<stj+1<<endl;
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;
}
컴파일 시 표준 에러 (stderr) 메시지
patkice.cpp: In function 'void go(int, int)':
patkice.cpp:23:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int j = 0; j < v[cur].size(); j++) {
| ~~^~~~~~~~~~~~~~~
patkice.cpp: At global scope:
patkice.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
35 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |