[SWEA] 8189 우편함

Time Lapse :1hour 15min 43sec

8189.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
43
44
45
46
47
48
49
#include <stdio.h>
#define pc(x) putchar(x)
#define gc() getchar()
int rev, N;
char buf[0x1011] = { ' ', };
int readINT() {
N = gc(), rev = 0x0;
do {
rev = (rev << 3) + (rev << 1) + (N & 0b1111); N = gc();
} while ('0' <= N && N <= '9');
return rev;
}
void writeInt(int n, int r) {
rev = 0x01;
do {buf[rev++] = n % 10 + 48; }while(n /= 10); //store reverse of N in rev
while (r--) {
N = rev;
while (N) pc(buf[--N]);
}
}
int main(int argc, char** argv) {
register int T, N, A, B, checked, time, tc, get = 0x0;
T = readINT();
int letter[101], letters[1001] = { 0x0, };
for (tc = 0x1; tc <= T; tc++) {
N = readINT(); A = readINT(); B = readINT();
pc('#'); writeInt(tc, checked = 0x1);
for (time = 0x1; time <= N; time++)
letters[letter[time] = readINT()] ^= 1;
for (time = 0x1; time <= letter[N]; time++) {
if (letters[time]) { get++; letters[time] ^= 1; }
if (!(get^A) || !((time - letter[checked]) ^ B)) {
writeInt(time, (get + 0x1) >> 1);
checked += ((get + 1) >> 1);
get >>= 1;
}
}
while (get) {
if (!(time - letter[checked] ^ B)) {
writeInt(time, (get + 0x1) >> 1);
checked += (get + 0x1) >> 1;
get >>= 1;
}
time++;
}
pc('\n');
}
return 0; //정상종료시 반드시 0을 리턴해야 합니다.
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/08/04/PS/SWEA/8189/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.