EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • šŸ‡²šŸ‡¾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🄰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. CodeNection
  2. 2024
  3. Preliminary Round

Codey and Toy Kingdom

https://www.hackerrank.com/contests/codenection-2024-preliminary-round-open-category/challenges/cn24-16

Question

Codey bought a new set of toys, which includes islands and bridges, and wanted to build a dream toy kingdom using them.

First, Codey arranged 2āˆ—n2*n2āˆ—n islands in a circle, numbered from 11 1 to 2āˆ—n2*n2āˆ—n in a clockwise direction, and connected each pair of adjacent islands with a bridge. Although this version of the toy kingdom allows travel between any two islands using a series of bridges, it is inefficient. To improve travel between distant islands, Codey decided to build bridges between islands that are not adjacent.

Codey used the nnn remaining bridges to connect different pairs of islands. Each island will have exactly one extra bridge connected to it. For each pair of bridges that intersect, the complexity of the toy kingdom increases by 111.

Help Codey determine the total complexity of the toy kingdom.

Input Format

The first line contains an integer n, which there are 2āˆ—n2*n2āˆ—n islands.

The next n lines contain two space-separated integers, aia_iai​ and bib_ibi​, representing the iii-th bridge between islands aia_iai​ and bib_ibi​.

Constraints

1≤n≤2āˆ—1051 \le n \le 2*10^51≤n≤2āˆ—105
1≤ai,bi≤2āˆ—n1 \le a_i,b_i \le 2*n1≤ai​,bi​≤2āˆ—n
  • Each island will have exactly one extra bridge connected to it.

Output Format

Output the total complexity of the toy kingdom.

Sample Inputs:

Input

3
1 3
2 5
4 6

Output

2

Explanation

The total complexity is 2 because the following pairs of bridges intersect:

  • (4,6)(4, 6)(4,6) and (2,5)(2, 5)(2,5)

  • (1,3)(1, 3)(1,3) and (2,5)(2, 5)(2,5)


Solution - WIP

WIP, haven't start yet.

PreviousCodey and RecipesNextCodey and Peaks

Last updated 5 months ago

šŸ‡²šŸ‡¾