시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB89628220432.692%

문제

네트워크에 연결되어 있는 컴퓨터들은 각각 하나의 IP 주소를 갖게 된다. 그리고 이러한 IP 주소를 갖는 컴퓨터들이 여러 개 모여서 하나의 IP 네트워크를 구성하게 된다. IP 네트워크는 ‘네트워크 주소’와 ‘네트워크 마스크’라는 두 개의 정보로 표현된다.

IP 주소는 네 개의 바이트로 구성되어 있으며, 각각을 10진수로 나타내고(앞에 0을 붙이지 않은 형태로) 사이에 점을 찍어 주소를 표현한다. 바이트이기 때문에 각각의 수는 0부터 255까지의 값을 갖게 된다. 네트워크 주소와 네트워크 마스크 역시 같은 형식으로 나타낸다.

IP 네트워크에 대해 올바르게 이해하기 위해서는 위와 같은 주소를 2진수로 이해하면 된다. 즉, 각각의 바이트를 8자리의 이진수로 나타내고, 이를 네 개 붙여놓은(앞에서부터) 32자리의 이진수를 생각해 보자. IP 네트워크에는 기본적으로 2m 개의 컴퓨터(혹은 IP 주소)가 할당될 수 있다. 이 경우의 네트워크 주소는 앞의 32-m 자리가 임의의 수(0 또는 1)로 구성되어 있고, 뒤의 m자리는 0으로 채워지게 된다. 네트워크 마스크는 앞의 32-m 자리가 1로 채워져 있고, 뒤의 m자리는 0으로 채워지게 된다. 이와 같은 IP 네트워크에는 앞의 32-m 자리가 네트워크 주소와 일치하는 모든 IP들이 포함되게 된다.

예를 들어 네트워크 주소가 194.85.160.176이고, 네트워크 마스크가 255.255.255.248인 경우를 생각해 보자. 이 경우, 이 네트워크에는 194.85.160.176부터 194.85.160.183까지의 8개의 IP 주소가 포함된다.

어떤 네트워크에 속해있는 IP 주소들이 주어졌을 때, 네트워크 주소와 네트워크 마스크를 구해내는 프로그램을 작성하시오. 답이 여러 개인 경우에는 가장 크기가 작은(포함되는 IP 주소가 가장 적은, 즉 m이 최소인) 네트워크를 구하도록 한다.

입력

첫째 줄에 정수 n(1 ≤ n ≤ 1,000)이 주어진다. 다음 n개의 줄에는 각 컴퓨터의 IP 주소가 주어진다.

출력

첫째 줄에 네트워크 주소를, 둘째 줄에 네트워크 마스크를 출력한다.

예제 입력 1

3
194.85.160.177
194.85.160.183
194.85.160.178

예제 출력 1

194.85.160.176
255.255.255.248
W3sicHJvYmxlbV9pZCI6IjIwNjQiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJJUCBcdWM4ZmNcdWMxOGMiLCJkZXNjcmlwdGlvbiI6IjxwPlx1YjEyNFx1ZDJiOFx1YzZjY1x1ZDA2Y1x1YzVkMCBcdWM1ZjBcdWFjYjBcdWI0MThcdWM1YjQgXHVjNzg4XHViMjk0IFx1Y2VmNFx1ZDRlOFx1ZDEzMFx1YjRlNFx1Yzc0MCBcdWFjMDFcdWFjMDEgXHVkNTU4XHViMDk4XHVjNzU4IElQIFx1YzhmY1x1YzE4Y1x1Yjk3YyBcdWFjMTZcdWFjOGMgXHViNDFjXHViMmU0LiBcdWFkZjhcdWI5YWNcdWFjZTAgXHVjNzc0XHViN2VjXHVkNTVjIElQIFx1YzhmY1x1YzE4Y1x1Yjk3YyBcdWFjMTZcdWIyOTQgXHVjZWY0XHVkNGU4XHVkMTMwXHViNGU0XHVjNzc0IFx1YzVlY1x1YjdlYyBcdWFjMWMgXHViYWE4XHVjNWVjXHVjMTFjIFx1ZDU1OFx1YjA5OFx1Yzc1OCBJUCBcdWIxMjRcdWQyYjhcdWM2Y2NcdWQwNmNcdWI5N2MgXHVhZDZjXHVjMTMxXHVkNTU4XHVhYzhjIFx1YjQxY1x1YjJlNC4gSVAgXHViMTI0XHVkMmI4XHVjNmNjXHVkMDZjXHViMjk0ICZsc3F1bztcdWIxMjRcdWQyYjhcdWM2Y2NcdWQwNmMgXHVjOGZjXHVjMThjJnJzcXVvO1x1YzY0MCAmbHNxdW87XHViMTI0XHVkMmI4XHVjNmNjXHVkMDZjIFx1YjljOFx1YzJhNFx1ZDA2YyZyc3F1bztcdWI3N2NcdWIyOTQgXHViNDUwIFx1YWMxY1x1Yzc1O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hbXBsZSwgSVAgbmV0d29yayB3aXRoIG5ldHdvcmsgYWRkcmVzcyAxOTQuODUuMTYwLjE3NiBhbmQgbmV0d29yayBtYXNrIDI1NS4yNTUuMjU1LjI0OCBjb250YWlucyA4IElQIGFkZHJlc3NlcyBmcm9tIDE5NC44NS4xNjAuMTc2IHRvIDE5NC44NS4xNjAuMTgzIChpbmNsdXNpdmUpLjxcL3A+XHJcbiIsImlucHV0IjoiPHA+VGhlIGZpcnN0IGxpbmUgb2YgdGhlIGlucHV0IGZpbGUgY29udGFpbnMgYSBzaW5nbGUgaW50ZWdlciBudW1iZXIgbSAoMSAmbGU7IG0gJmxlOyAxMDAwKS4gVGhlIGZvbGxvd2luZyBtIGxpbmVzIGNvbnRhaW4gSVAgYWRkcmVzc2VzLCBvbmUgYWRkcmVzcyBvbiBhIGxpbmUuIEVhY2ggSVAgYWRkcmVzcyBtYXkgYXBwZWFyIG1vcmUgdGhhbiBvbmNlIGluIHRoZSBpbnB1dCBmaWxlLjxcL3A+XHJcbiIsIm91dHB1dCI6IjxwPldyaXRlIHRvIHRoZSBvdXRwdXQgZmlsZSB0d28gbGluZXMgdGhhdCBkZXNjcmliZSB0aGUgc21hbGxlc3QgcG9zc2libGUgSVAgbmV0d29yayB0aGF0IGNvbnRhaW5zIGFsbCBJUCBhZGRyZXNzZXMgZnJvbSB0aGUgaW5wdXQgZmlsZS4gV3JpdGUgbmV0d29yayBhZGRyZXNzIG9uIHRoZSBmaXJzdCBsaW5lIGFuZCBuZXR3b3JrIG1hc2sgb24gdGhlIHNlY29uZCBsaW5lLjxcL3A+XHJcbiIsImhpbnQiOiIiLCJvcmlnaW5hbCI6IjEiLCJodG1sX3RpdGxlIjoiMCIsInByb2JsZW1fbGFuZ190Y29kZSI6IkVuZ2xpc2gifV0=

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > NEERC 2005 I번

  • 데이터를 추가한 사람: sait2000