Last active
October 2, 2017 21:43
-
-
Save ria3100/de941b607fe4e59c3eac to your computer and use it in GitHub Desktop.
Paiza:長テーブルのうなぎ屋 (paizaランク B 相当)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# Paiza Lerning 長テーブルのうなぎ屋 (paizaランク B 相当) | |
# https://paiza.jp/learning/long-table | |
n, m = map(int, input().split()) | |
seat = 0 | |
for i in range(m): | |
a, b = map(int, input().split()) | |
guest = ['0']*(b-1) + ['1']*a + ['0']*(n-a-b+1) | |
guest = guest[n:] + guest[n*-1:n] | |
guest = int('0b' + ''.join(guest), 2) | |
if int(bin(seat & guest), 2) == 0: | |
seat = int(bin(seat | guest), 2) | |
print(bin(seat).count('1')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
この辺りもうちょっとスマートにならないかなぁ・・・