Submission #39248932
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct xy {
int x;
int y;
} xy;
int x_cmp (void *n1, void *n2) {
xy a = *(xy *)n1;
xy b = *(xy *)n2;
if (a.x > b.x) {
return 1;
} else if (a.x < b.x) {
return -1;
} else {
return 0;
}
}
int y_cmp (void *n1, void *n2) {
xy a = *(xy *)n1;
xy b = *(xy *)n2;
if (a.y > b.y) {
return 1;
} else if (a.y < b.y) {
return -1;
} else {
return 0;
}
}
void swap_all (void *n1, void *n2, size_t size) {
char tmp[size];
memcpy(tmp, n1, size);
memcpy(n1, n2, size);
memcpy(n2, tmp, size);
}
void heapsort (void *base, size_t num, size_t size, int (* cmpfunc)(void *, void *), int type) {
for (int i = 1; num > i; i++) {
for (int j = i; j > 0;) {
if (type == 1) {
if (cmpfunc((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2))) == 1) {
swap_all((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2)), size);
j = (j - 1) / 2;
} else {
break;
}
} else {
if (cmpfunc((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2))) == -1) {
swap_all((char *)(base + size * j), (char *)(base + size * ((j - 1) / 2)), size);
j = (j - 1) / 2;
} else {
break;
}
}
}
}
for (int i = num - 1; i > 0; i--) {
swap_all((char *)base, (char *)(base + size * i), size);
for (int j = 0; ;) {
int lch = 2 * j + 1, rch = 2 * j + 2, rep;
if (i > rch) {
if (type == 1) {
rep = (cmpfunc((char *)(base + size * lch), (char *)(base + size * rch)) == 1 ? lch : rch);
} else {
rep = (cmpfunc((char *)(base + size * lch), (char *)(base + size * rch)) == -1 ? lch : rch);
}
} else if (rch == i) {
rep = lch;
} else {
break;
}
if (type == 1) {
if (cmpfunc((char *)(base + size * j), (char *)(base + size * rep)) == -1) {
swap_all((char *)(base + size * j), (char *)(base + size * rep), size);
j = rep;
} else {
break;
}
} else {
if (cmpfunc((char *)(base + size * j), (char *)(base + size * rep)) == 1) {
swap_all((char *)(base + size * j), (char *)(base + size * rep), size);
j = rep;
} else {
break;
}
}
}
}
}
int IsSame (xy a, xy b) {
if (a.x == b.x && a.y == b.y) {
return 0;
}
return 1;
}
int main (void) {
int n;
scanf("%i", &n);
char s[n + 1];
scanf("%s", s);
xy list[n + 1];
list[0].x = 0;
list[0].y = 0;
for (int i = 0; n > i; i++) {
if (s[i] == 'R') {
list[i + 1].x = list[i].x + 1;
list[i + 1].y = list[i].y;
} else if (s[i] == 'L') {
list[i + 1].x = list[i].x - 1;
list[i + 1].y = list[i].y;
} else if (s[i] == 'U') {
list[i + 1].y = list[i].y + 1;
list[i + 1].x = list[i].x;
} else {
list[i + 1].y = list[i].y - 1;
list[i + 1].x = list[i].x;
}
}
heapsort(list, n + 1, sizeof(xy), x_cmp, 1);
int S = 0, E;
for (; S <= n + 1;) {
for (E = S + 1; ; E++) {
if (E == n + 1) {
break;
}
if (list[S].x != list[E].x) {
break;
}
}
heapsort(&list[S], E - S, sizeof(xy), y_cmp, 1);
S = E;
}
/*
for (int i = 0; n + 1 > i; i++) {
printf("%i %i\n", list[i].x, list[i].y);
}
printf("\n");
// */
for (int i = 0; n > i; i++) {
if (IsSame(list[i], list[i + 1]) == 0) {
printf("Yes\n");
return 0;
}
}
printf("No\n");
return 0;
}
Submission Info
Submission Time |
|
Task |
C - LRUD Instructions 2 |
User |
InTheBloom |
Language |
C (Clang 10.0.0) |
Score |
300 |
Code Size |
3464 Byte |
Status |
AC |
Exec Time |
46 ms |
Memory |
3788 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt |
All |
hand.txt, hand_01.txt, hand_02.txt, min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt |
Case Name |
Status |
Exec Time |
Memory |
hand.txt |
AC |
35 ms |
3776 KB |
hand_01.txt |
AC |
29 ms |
3720 KB |
hand_02.txt |
AC |
30 ms |
3740 KB |
min.txt |
AC |
1 ms |
1860 KB |
random_01.txt |
AC |
46 ms |
3776 KB |
random_02.txt |
AC |
34 ms |
3416 KB |
random_03.txt |
AC |
41 ms |
3744 KB |
random_04.txt |
AC |
13 ms |
2456 KB |
random_05.txt |
AC |
43 ms |
3712 KB |
random_06.txt |
AC |
23 ms |
2852 KB |
random_07.txt |
AC |
32 ms |
3776 KB |
random_08.txt |
AC |
11 ms |
2500 KB |
random_09.txt |
AC |
29 ms |
3720 KB |
random_10.txt |
AC |
10 ms |
2460 KB |
random_11.txt |
AC |
33 ms |
3788 KB |
random_12.txt |
AC |
5 ms |
2276 KB |
random_13.txt |
AC |
28 ms |
3624 KB |
random_14.txt |
AC |
4 ms |
2084 KB |
random_15.txt |
AC |
32 ms |
3624 KB |
random_16.txt |
AC |
28 ms |
3484 KB |
random_17.txt |
AC |
27 ms |
3728 KB |
random_18.txt |
AC |
16 ms |
2728 KB |
random_19.txt |
AC |
34 ms |
3788 KB |
random_20.txt |
AC |
19 ms |
3148 KB |
random_21.txt |
AC |
27 ms |
3772 KB |
random_22.txt |
AC |
23 ms |
3448 KB |
random_23.txt |
AC |
35 ms |
3724 KB |
random_24.txt |
AC |
32 ms |
3780 KB |
random_25.txt |
AC |
24 ms |
3620 KB |
random_26.txt |
AC |
26 ms |
3776 KB |
random_27.txt |
AC |
27 ms |
3760 KB |
random_28.txt |
AC |
32 ms |
3780 KB |
random_29.txt |
AC |
23 ms |
3760 KB |
random_30.txt |
AC |
26 ms |
3712 KB |
random_31.txt |
AC |
30 ms |
3624 KB |
random_32.txt |
AC |
35 ms |
3780 KB |
sample_01.txt |
AC |
1 ms |
2048 KB |
sample_02.txt |
AC |
1 ms |
1972 KB |