# Demo entry 6776977

14503.cpp

Submitted by anonymous on Dec 06, 2018 at 13:42
Language: C++. Code size: 4.1 kB.

```#define max(a,b) (a) > (b) ? a : b
#define loop(i,s,t) for(register int i = s; i < t; i++)
#include <iostream>
#include <cstdio>
using namespace std;
int tc, n, m, r, c, d;

int map[55][55];
bool cleaned[55][55];

int main() {
//freopen("input.txt", "r", stdin);
//setbuf(stdout, NULL);
scanf("%d%d%d%d%d",&n, &m, &r,&c,&d);
loop(i,0,n) {
loop(j,0,m) {
scanf("%d", &map[i][j]);
}
}
int ret = 0;
int newDir, oppDir;
while(true) {
if(!cleaned[r][c]) {
cleaned[r][c] = true;
ret++;
}
newDir= (d+3) % 4;// 왼방향
oppDir =(d+2) % 4;// 반대방향

//전방향 체크, (화면밖 || 벽 || 청소완료)
if((r-1 < 0 || map[r-1][c] || cleaned[r-1][c]) && (c+1 >= m || map[r][c+1] || cleaned[r][c+1]) &&
(r+1 >= n || map[r+1][c] || cleaned[r+1][c]) && (c-1 < 0 || map[r][c-1] || cleaned[r][c-1])) {
switch(oppDir) {
case 0:
if(r-1 < 0 || (r-1>=0 && map[r-1][c])) { // 화면밖 || 벽
printf("%d\n", ret);
return 0;
}
else {
r--; //방향유지 후진
continue;
}
break;
case 1:
if(c+1 >= m || (c+1 < m && map[r][c+1])) {
printf("%d\n", ret);
return 0;
}
else {
c++;
continue;
}
break;
case 2:
if(r+1 >= n || (r+1 < n && map[r+1][c])) {
printf("%d\n", ret);
return 0;
}
else {
r++;
continue;
}
break;
case 3:
if(c-1 < 0 || (c-1 >= 0 && map[r][c-1])) {
printf("%d\n", ret);
return 0;
}
else {
c--;
continue;
}
break;
default:
break;
}
}

//청소 안한 방향까지 회전
switch(newDir) {
case 0:
if(r-1 >= 0 && !map[r-1][c] && !cleaned[r-1][c]) {
r--;
}
break;
case 1:
if(c+1 < m && !map[r][c+1] && !cleaned[r][c+1]) {
c++;
}
break;
case 2:
if(r+1 < n && !map[r+1][c] && !cleaned[r+1][c]) {
r++;
}
break;
case 3:
if(c-1 >= 0 && !map[r][c-1] && !cleaned[r][c-1]) {
c--;
}
break;
default:
break;
}
d = newDir;
}
}
```

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.