[SWEA] 8934 팰린드롬 공포증

Time Lapse :NONE

8934.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <memory.h>
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#define ADD3(a, b) ((a<<3)+(a<<1)+(b))
#define MIN(a,b) ((a)>(b)) ? (b) : (a)
#define NO putchar_unlocked('N'),putchar_unlocked('O'),putchar_unlocked('\n');
#define YES putchar_unlocked('Y'),putchar_unlocked('E'),putchar_unlocked('S'),putchar_unlocked('\n');
#define IP(a,b,c,m) (((a)>=((m)+(2)))||((b)>=((m)+(2)))||((c)>=((m)+(2)))) ? (1) : (0)

int fRI() {
int N = gc(), r = 0;
for (; 0x30 > N || N > 0x3A; N = gc());
do {
r = ADD3(r, N & 0b1111); N = gc();
} while (0x30 <= N && N <= 0x3A);
return r;
}

void fWI(int tc) {
int r = 0, c = 0;
pc('#');
while (!(tc % 10)) { c++; tc /= 10; }
while (tc) {r = ADD3(r, tc % 10); tc /= 10; }
while (r) {pc(r % 10 +48); r /= 10;}
while (c--) pc(0x30); pc(' ');
return;
}

int main(void) {
register int tc = 1, T = fRI(), m;
int buf[3];
while (T--) {
memset(buf,0,sizeof(buf));
while(m=gc(),'a'<=m) buf[m-'a']++;
fWI(tc++);
m = MIN(MIN(buf[0],buf[1]),buf[2]);
if(IP(buf[0],buf[1],buf[2],m)) NO
else YES
}
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/8934/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.