i was solving this problem "https://codeforces.com/problemset/problem/629/A" but i did not understand the 2nd testcase i think the output should be 8 not 9

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

1 | jiangly | 3678 |

2 | Benq | 3602 |

3 | ecnerwala | 3542 |

4 | maroonrk | 3541 |

5 | cnnfls_csy | 3540 |

6 | orzdevinwang | 3493 |

7 | inaFSTream | 3478 |

8 | Um_nik | 3430 |

9 | Geothermal | 3409 |

9 | Rebelz | 3409 |

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

1 | maomao90 | 174 |

2 | adamant | 164 |

3 | TheScrasse | 161 |

3 | SecondThread | 161 |

3 | awoo | 161 |

6 | nor | 159 |

7 | maroonrk | 158 |

8 | Um_nik | 156 |

9 | BledDest | 145 |

9 | Geothermal | 145 |

i was solving this problem "https://codeforces.com/problemset/problem/629/A" but i did not understand the 2nd testcase i think the output should be 8 not 9

↑

↓

Codeforces (c) Copyright 2010-2024 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Feb/22/2024 21:46:30 (l1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

answer is 3 on the second column

Yep, my bad.

pieces that share the same row are: $$$\newline$$$ (1,1) and (1,2) $$$\newline$$$ (2,1) and (2,4) $$$\newline$$$ (3,2) and (3,3) $$$\newline$$$ (4,2) and (4,3) $$$\newline$$$ pieces that share the same column are: $$$\newline$$$ (1,1) and (2,1) $$$\newline$$$ (1,2) and (3,2) $$$\newline$$$ (1,2) and (4,2) $$$\newline$$$ (3,2) and (4,2) $$$\newline$$$ (3,3) and (4,3) $$$\newline$$$ The total is 9. $$$\newline$$$ I think you made a little mistake by not counting the 3 possible combinations in column 2.

thanks you are right i only counted adjacent ones

You are calculating

pairsof chocolates that share the same row and column. In second example:1st row has 1 pair:

`{(1,1) , (1,2)}`

2nd row has 3 pairs:

`{(2, 1), (2, 3)}, {(2, 1), (2, 4)} , {(2,3), (2,4)}`

3rd row has 1 pair:

`{(3, 3), (3, 4)}`

4th row has no pairs because it has only 1 element;

All columns have only 1 pair each:

1st:

`{(1, 1), (2, 1)}`

2nd:`{(1, 2), (4, 2)}`

3rd:`{(2, 3), (3, 3)}`

4th:`{(2, 4), (3, 4)}`

Counting all pairs we get:

`sol = 1 + 3 + 1 + 0 + 1 + 1 + 1 + 1 = 9`

In case you don't know, there is also a formula for calculating pairs in single column/row

Formulan = number of chocolates in given row/column

`sol = n * (n - 1) / 2`