@contrex,
I don't see why each prisoner has to flick the switch twice... unless they want to stay in prison for longer?
I think it should work like this:
One person is the counter.
The counting must start from the first time the counter enters the room.
Every time the counter enters the room he must make sure that switch A is in the on position. If it is not he makes it so and adds one to his count, if it is already in the on position he flicks switch B.
Everyone else must only flick switch A from the on position to the off position and they must only do this once; if these conditions can not be met then they must flick switch B.
When the counter reaches the same count as the number of prisoners he knows that every prisoner has been in the room at least once.