In a situation where no sooner a person starts prayer by standing up, saying Allahu Akbar and sitting down to join a congregation, the imam ends the prayer with salaam, it is still as if he has prayed as a part of the congregation provided that the imam has not uttered Assalamu Alaikum even to the extent of “Assalam” before he joins. He can continue the salaah by standing up preferably after reciting tashahhud.
In a situation where a person says Allahu Akbar to join the imam and the Imam ends his prayer by saying salaam, he need not sit down and should continue his prayer. Again it is as if he prayed with the congregation.
However when a person joins a congregation after the first Assalamu Alaikum has been said even so much as ‘Assalam’ he will not be considered to have prayed with the congregation.