let's say I have 2 numbers x and y. How do I check if x*y results in an overflow in C++?. Both x and y are long long int.

# | User | Rating |
---|---|---|

1 | tourist | 3565 |

2 | Benq | 3540 |

3 | Petr | 3519 |

4 | maroonrk | 3503 |

5 | jiangly | 3391 |

6 | ecnerwala | 3363 |

7 | Radewoosh | 3349 |

8 | scott_wu | 3313 |

9 | ainta | 3298 |

10 | boboniu | 3289 |

# | User | Contrib. |
---|---|---|

1 | 1-gon | 199 |

2 | Errichto | 196 |

3 | rng_58 | 194 |

4 | SecondThread | 186 |

4 | awoo | 186 |

6 | Um_nik | 182 |

7 | vovuh | 178 |

8 | Ashishgup | 176 |

9 | antontrygubO_o | 174 |

10 | -is-this-fft- | 173 |

You have 2 arrays A and B each of size n, that contains integers from 1 to n inclusive. In one move, you can swap corresponding elements of two arrays. Determine if it is possible to have such series of operations (possibly zero) that both arrays contain integers from 1 to n exactly once, if possible print the series of operations (ie indices on which you apply the operations) and -1 if not possible.

eg

A = 3 1 2 1 2

B = 5 4 4 5 3

ans = 3 4

explanation :

after operations

A = 3 1 4 5 2

B = 5 4 2 1 3

Can someone tell me the approach/pseudocode for this?

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Mar/04/2021 22:27:21 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|