i was solving this problem "https://codeforces.net/problemset/problem/629/A" but i did not understand the 2nd testcase i think the output should be 8 not 9
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
i was solving this problem "https://codeforces.net/problemset/problem/629/A" but i did not understand the 2nd testcase i think the output should be 8 not 9
Название |
---|
answer is 3 on the second column
You are calculating pairs of 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
n = number of chocolates in given row/column
sol = n * (n - 1) / 2