题解:P15328 [GCPC 2025] Around the Table

· · 题解

--- ### 观前提示:本文思路参照了[官方题解](https://codeforces.com/gym/106129/attachments/download/33895/gcpc-25-solutions.pdf)。 为了方便,本文令 $l + r = n$,即总人数。 --- ![](https://cdn.luogu.com.cn/upload/image_hosting/kgt9zq72.png) 如图,将玩家从 $0$ 至 $n - 1$ 编号,观察可以发现: - 左侧的 $i$ 号玩家会遇到 $i + l \pmod n$ 和 $i + l - 1 \pmod n$。 - 右侧的 $i$ 号玩家会遇到 $i + r \pmod n$ 和 $i + r + 1 \pmod n$。 即一般情况下,一个人最多可能遇到 $4$ 个不同的人,也就是总共最多 $2n$ 组不同的配对。 --- 而在某些情况下,这 $4$ 名玩家可能有相同情况。 ::::info[推导过程] 我们设: - $A = i + l \pmod n

有这些情况相等:

其余情况不可能相等。

总结一下:

由于总配对数为所有玩家对手数之和的一半(每个配对被两侧玩家各计一次),可以得到下面的结论。

::::

::::info[结论]

十年 OI 一场空,不开 long long 见祖宗。

#include <bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
    int res = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        res = res * 10 + c - '0';
        c = getchar();
    }
    return res * f;
}
signed main(){
    int l = read(), r = read();
    if (r == l - 1) printf("%lld\n", l + r);
    else if (r == l || r == l - 2) printf("%lld\n", l + r + (l + r) / 2);
    else printf("%lld\n", 2 * (l + r));
    return 0;
}