Not sure how far away you'd need to be. In practice you can't predict the strike site, so you'd not know which way to swim.
The charge from a strike spreads out, forming a current through the water or ground & setting up a voltage gradient. Whether it harms you will depend on how near, which bit of you it runs through, & whether you conduct better than the substrate.
Earth does not conduct well, so the voltage gradient on land is very steep, & flesh conducts better than it. If you're standing with your feet apart & one foot is nearer the lightning, there'll be a large voltage difference between your feet - current will run up one leg and down the other.
I'm not sure what would happen in water. However, sea water conducts quite well. The gradient should therefore be less steep, & you might be better off. But you're in good contact with the water, & the current will cross your chest. Also, unconsciousness may cause you to drown. Fresh might be different.
If the current crosses your chest there's a risk it'll stop your heart. Four-legged animals are much more often killed by nearby lightning strikes to the ground. They always have some legs nearer than others, and the current will go up at least one front leg & so cross the chest. Whole herds can be killed. Humans may be standing sideways - & even if it does go up one leg and down the other, it may miss the chest.
So on land keep your feet together, crouch down, & keep well away from any companions - then you won't all need CPR at once.
I believe most people "struck" by lightning are actually shocked by a nearby strike rather than hit directly. This happened to my partner -she crouched in a dry ditch in a storm, some distance from a companion. They were both thrown through the air by the shock, but were otherwise unharmed.