差分..好厉害的名词,其实听过几次,但是一直没什么感觉,就目前见过几次来说的话,就是一个数组,存a[i]-a[i-1]这样.
一些时候,如果看当前数字看不出规律,可以试着从差分上找.
好菜啊 T^T
boxes
#include <iostream>
#include <vector>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
const int MOD = 1e9+17;
LL a[MAXN],c[MAXN];
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
LL n;
cin>>n;
LL sum = 0;
for (int i = 0; i < n; ++i)
{
cin>>a[i];
sum+=a[i];
}
bool can = true;
if(sum%(((1LL+n)*n)/2)!=0) can = false;
LL cnt = sum/(((1LL+n)*n)/2);
for (int i = 0; i < n; ++i)
{
if(i==0) c[i] = a[0]-a[n-1];
else c[i] = a[i]-a[i-1];
}
for (int i = 0; i < n; ++i)
if(((c[i]-cnt)%n)!=0||c[i]-cnt>0) can = false;
if(can) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}