What the title says. As far as I am aware, Pikes are cheaper to make, have a larger reach, and are more resistant to cavalry. Why on earth did they focus on their swords and not pikes?
On costs:
Whether or not a pike is cheaper than a sword, a pikeman should be equipped with a sidearm in addition to his pike, and that sidearm will usually be a sword. If a pike is substantially cheaper than a sword, that merely means that it is only a little more expensive to equip a pikeman than a swordsman.
While spears were often (usually!) the dominant hand-to-hand weapons on the pre-gunpowder battlefield, the sword could easily be more common on the battlefield, with archers, spearmen, and cavalry usually carrying swords as sidearms.
On defeating the pike:
The pike phalanx, if properly deployed and handled, was a formidable enemy on the battlefield. Recognition of this led to the widespread adoption of the pike phalanx in Western Asia and around the Mediterranean. As you note, a great strength of the pike is the great length of the pike - reach matters. Indeed, that reach appears to be a major reason for the adoption of the pike - it provides much more reach than the one-handed spear with shield, and might have developed specifically to defeat the hoplite phalanx. Where the hoplite phalanx was replaced by the pike phalanx, the problem shifted from how to defeat the hoplite phalanx to how to defeat the pike phalanx. One solution was very simple: adopt the pike phalanx, and have more soldiers, better trained soldiers, and/or soldiers with higher morale. While this is simple to say, it is much harder to achieve, especially when facing states with large and experienced armies.
Since the pike, as used, was the longest practical weapon on the battlefield, it wasn't possible to try to bring hand-to-hand weapons with even more reach. But there are weapon that provide more range than a pike: the bow, the sling, the javelin, etc. The Roman "solution" versus the pike was essentially javelin and sword. The javelin part of that solution should not be ignored - it's an important part of Roman fighting against spear and pike phalanxes. While the sword has less reach than the spear/pike, the javelin makes up for this, and gives the Romans the first blow in battle.
A phalanx facing a Roman army equipped with pilum (javelin), sword, and shield has a tough decision to make: whether to endure a shower of javelins hoping that the supporting troops on the wings create the ideal conditions for the phalanx to advance on the Roman centre, or to advance on the Roman centre immediately. The latter has the advantage of giving the Romans less time to throw javelins at the phalanx, but the phalanx can suffer some disruption from casualties from the javelins while advancing, and risks flank attack on the phalanx if the battle goes poorly on the wings.
How well did the Roman system work against the pike phalanx? Sometimes, the Romans won, and sometimes the Romans lost. Neither then phalanx nor the legion had a decisive, or even great, advantage over the other.
On facing cavalry and other enemies:
The Roman system was more flexible than the phalanx. While the phalanx could be an awe-inspiring beast on the battlefield, it could be difficult or impossible to deploy in wooded terrain, hilly terrain, on ships, and was not suited to be divided into small squads for patrolling. As Polybius wrote about Roman training and discipline and flexibility in battle:
The Roman order on the other hand is flexible: for every Roman, once armed and on the field, is equally well equipped for every place, time, or appearance of the enemy. He is, moreover, quite ready and needs to make no change, whether he is required to fight in the main body, or in a detachment, or in a single maniple, or even by himself. Therefore, as the individual members of the Roman force are so much more serviceable, their plans are also much more often attended by success than those of others.
The phalangite (i.e., pikeman) was more vulnerable to archers than the armoured Roman infantryman - a large shield helps keep those arrows out.
Roman soldiers do not appear to have been overly vulnerable to cavalry. For example, while the Battle of Carrhae (53BC) was disastrous for the Romans, the Roman infantry held their own against attacks by Parthian cataphracts (heavy armoured cavalry with armoured horses). Alas for the Romans, they couldn't defend against the cataphracts while using the testudo formation, and their defence against the cataphracts left them more vulnerable to the Parthian archers. Javelins (and supporting archers and slingers) could be used to keep cavalry at a safe distance, and the pilum could be used in hand-to-hand combat against cavalry. From AD135, we have a detailed description of how a Roman army could deploy against cavalry. In Arrian's Array against the Alans, the main part of the infantry formation is spearmen and javelineers:
The Fifteenth Legion’s infantry should hold the entire right center above the middle of the whole area, because they are by far the most numerous: the infantrymen of the Twelfth Legion should hold the remaining space on the left filling it up to the point of the left flank. They should deploy in eight ranks and their deployment should be close ordered. And the front four ranks of the formation must be of spearmen, whose spearpoints end in thin iron shanks. And the foremost of them should hold them at the ready, in order that when the enemies near them, they can thrust the ironpoints of the spears at the breast of the horses in particular. Those standing in second, third an fourth rank of the formation must hold their spears ready for thrusting if possible, wounding the horses and killing the horsemen and put the rider out of action with the spear stuck in their heavy body armour and the iron point bent because of the softness. The following ranks should be of the javelineers. The ninth rank behind them should be the foot archers, those of the Numidians, Cyrenaicans, Bosporans and Ityraeans. Artillery pieces must be deployed on each flank to fire at the advancing enemies at maximum range, and behind the whole battle formation.
As the above quote shows, using the sword on the battlefield didn't mean that spears were abandoned. Where Roman infantry carried dual-use spears that could be thrown or used hand-to-hand, they could choose to use their spears in hand-to-hand fighting. Also, the Roman heavy infantry were not alone on the battlefield: they were accompanied by archers and/or slingers, cavalry, and auxiliary infantry (who often carried spears). While they didn't use the pike, they most certainly kept using the spear, in large numbers.