I think I have the answer:
The first step is to determine the color of the square numbers.
Now, because the 16 and the 25 are adjacent and have the same color, they must be part of the same flag. This means they must be part of the flag of Denmark, Sweden or Finland. So let us try first with Sweden. There are 2 possible positions, either with the top of the flag in the 1st or 2nd row. Starting with the 2nd row, we have:
The yellow 9 could be taken by Lithuania, but then we have no choice for the yellow 1. We could use Cameroon instead (as pictured) but then we have no choice for the yellow 4. So this position is not possible. The other possibility is having the Swedish flag in the top row. But this means Lithuania must be used for the yellow 9 and we have no choice for the yellow 1. So, we cannot use the Swedish flag.
Next, let us try the
Finnish flag. Again, we start with the top of the flag in the 2nd row:
The only choice for the blue 9 is Estonia. But then we have a problem with the blue 1. It cannot be Sweden or Guatemala as they would both border the blue 4. And if we place the Finnish flag in the top row, there is no choice for the blue 9 at all. So it cannot be the Finnish flag and must be the Danish flag.
Again, the flag could be in
two positions. If the top of the flag was in the 2nd row, we get this:
The white 9 could be Russia or Bulgaria. But Russia needs to border Austria, which would not be possible. So it must be Bulgaria. The choices for the white 36 are now N. Ossetia or Russia. But again, it cannot be Russia as it need to border Austria, which isn't possible. So it must N. Ossetia and the white 1 must be Russia. The only way to make Austria adjacent to Russia is as shown. But now we have a problem with the white 4. It must be at the end of a horizontal flag and there is no horizontal flag with white at the end. So the Danish flag must be in the top row.
Knowing this, we get
the following snapshot:
Again, Russia cannot use the white 9 as it needs to border Austria. And it also cannot use the white 1, so we must have the situation above (Estonia is the only possibility for using the white 81).
A few more
placements are shown below.
Bulgaria is the only remaining choice for the white 1 and Cameroon the only choice for being below the Danish flag. In addition I have started to look for positions where the Finnish flag can be placed. These are shown as 3x3 thick border boxes.
When you now consider
how the placement of the Swedish flag affects the possible locations of the Finnish flag, it turns out that the only possible placement of the Finnish flag is as shown below:
Below the Finnish flag there must be
a horizontal flag. The only possibility is the flag of Guinea. And the only possibility for the flag below Guinea is Guatemala. Now, Mali cannot be used to cover the white 4 and we need 2 more horizontals in the 2 bottom rows, so one of them must be Mali. It can only be placed as shown below. This means Nigeria cannot be the last remaining horizontal in the 2 bottom rows as it clashes with the green of Mali. Hence the last horizontal must be Cote d' Ivoire. And Nigeria must cover the white 4. The 2 verticals which need to be placed at the left end of the bottom row must both be non-European and can only be Armenia and S. Leone as shown.
It remains to place
the Swedish flag. It cannot be placed with the top left corner in square 28 or square 20 as this would leave spaces which could not be filled with vertical 3-pieces. So it must be placed with the top left corner in square 12. We now have 5 remaining flags (Germany, Hungary, Lithuania, Netherlands and Gabon) and there is only one spot where Lithuania can be, giving us:
Neither Germany nor Gabon can have their top in the 2 square or the 40 square and because of their common yellow color, it must be Germany in square 39 and Gabon in square 29. This in turn forces the Netherlands to use square 2 and Hungary to use square 40. And we are done!
Whew! That was a long explanation. But I hope it makes sense.
An excellent puzzle, as usual!