# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476120 | rainboy | Clickbait (COCI18_clickbait) | C11 | 5 ms | 2212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define N 1000
#define M 1000
char cc[N][M + 1]; int n, m;
void dfs(int i, int j, int dir) {
if (dir == -2) {
int i_, j1, j2, a, b;
j1 = j;
while (j1 > 0 && cc[i][j1 - 1] != '.')
j1--;
j2 = j;
while (j2 + 1 < m && cc[i][j2 + 1] != '.')
j2++;
i_ = i + 1;
while (i_ + 1 < n && cc[i_ + 1][j1] != '.')
i_++;
for (a = i_ - 1; a >= i + 1; a--) {
if (j1 > 0 && cc[a][j1 - 1] != '.')
dfs(a, j1 - 1, -1);
if (j2 + 1 < m && cc[a][j2 + 1] != '.')
dfs(a, j2 + 1, 1);
}
for (a = i + 1; a <= i_ - 1; a++)
for (b = j1 + 1; b <= j2 - 1; b++)
if (cc[a][b] != '.')
printf("%c", cc[a][b]);
printf("\n");
} else {
if (cc[i][j] == '-')
dfs(i, j + dir, dir ? dir : -2);
else if (cc[i][j] == '|' || dir)
dfs(i + 1, j, 0);
else {
dir = j > 0 && cc[i][j - 1] == '-' ? -1 : 1;
dfs(i, j + dir, dir);
}
}
}
int main() {
int i, j;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
if (cc[i][j] != '.') {
dfs(i, j, -2);
return 0;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |