AtCoder Grand Contest 010 B(差分)

题目链接

B - Boxes


Time limit : 2sec / Memory limit : 256MB

Score : 500 points

Problem Statement

There are N boxes arranged in a circle. The i-th box contains Ai stones.

Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:

  • Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box.

Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed.

Constraints

  • 1≦N≦105
  • 1≦Ai≦109

Input

The input is given from Standard Input in the following format:

N
A1 A2AN

Output

If it is possible to remove all the stones from the boxes, print YES. Otherwise, print NO.


Sample Input 1

Copy
5
4 5 1 2 3

Sample Output 1

Copy
YES

All the stones can be removed in one operation by selecting the second box.


Sample Input 2

Copy
5
6 9 12 10 8

Sample Output 2

Copy
YES

Sample Input 3

Copy
4
1 2 3 1

Sample Output 3

Copy
NO



博客传送门


Source code

 
 
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstring>
  5. #include<vector>
  6. #include<queue>
  7. #include<stack>
  8. using namespace std;
  9. #define rep(i,a,n) for (int i=a;i<n;i++)
  10. #define per(i,a,n) for (int i=n-1;i>=a;i--)
  11. #define pb push_back
  12. #define fi first
  13. #define se second
  14. typedef vector<int> VI;
  15. typedef long long ll;
  16. typedef pair<int,int> PII;
  17. const int inf=0x3fffffff;
  18. const ll mod=1000000007;
  19. const int maxn=1e5+100;
  20. int a[maxn];
  21. int main()
  22. {
  23. int n;
  24. scanf("%d",&n);
  25. ll sum=0,t=0;
  26. rep(i,1,n+1) scanf("%d",&a[i]),sum+=a[i],t+=i;
  27. if(sum%t)
  28. {
  29. puts("NO");
  30. return 0;
  31. }
  32. ll tmp=a[1];
  33. rep(i,1,n) a[i]=a[i+1]-a[i];
  34. a[n]=tmp-a[n];
  35. ll d=sum/t;
  36. rep(i,1,n+1)
  37. {
  38. a[i]-=d;
  39. if(a[i]%n||a[i]>0)
  40. {
  41. puts("NO");
  42. return 0;
  43. }
  44. }
  45. puts("YES");
  46. return 0;
  47. }




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值