Submission #1514806
Source Code Expand
// #includes {{{
#include <bits/stdc++.h>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
#define EXIST(e,s) ((s).find(e)!=(s).end())
#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command
//debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;
const int INF=0x3f3f3f3f;
typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;
typedef pair<int,int> pii;
/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}
//{{{ io
FILE *file_in=stdin,*file_out=stdout;
#define fin normal_in
#define fout normal_out
//const char fname[]="";
//FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w");
#ifdef __MINGW32__
#define LLD "%I64d"
#define LLU "%I64u"
#else
#define LLD "%lld"
#define LLU "%llu"
#endif
struct NORMAL_IN{
bool cnt;
NORMAL_IN():cnt(true){}
operator int() const {return cnt;}
#define endl "\n"
NORMAL_IN& operator>>(int &n){cnt=fscanf(file_in,"%d",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(unsigned int &n){cnt=fscanf(file_in,"%u",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(long long &n){cnt=fscanf(file_in,LLD,&n)!=EOF;return *this;}
NORMAL_IN& operator>>(unsigned long long &n){cnt=fscanf(file_in,LLU,&n)!=EOF;return *this;}
NORMAL_IN& operator>>(double &n){cnt=fscanf(file_in,"%lf",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(long double &n){cnt=fscanf(file_in,"%Lf",&n)!=EOF;return *this;}
NORMAL_IN& operator>>(char *c){cnt=fscanf(file_in,"%s",c)!=EOF;return *this;}
NORMAL_IN& operator>>(string &s){
s.clear();
for(bool r=false;;){
const char c=getchar();
if(c==EOF){ cnt=false; break;}
const int t=isspace(c);
if(!r and !t)r=true;
if(r){
if(!t)s.push_back(c);
else break;
}
}
return *this;
}
template<class T>
NORMAL_IN& operator>>(vector<T> &v){
int n;fscanf(file_in,"%d",&n);
REP(i,n){
T t;*this>>t;
v.push_back(t);
}
}
} normal_in;
struct NORMAL_OUT{
NORMAL_OUT& operator<<(const int &n){fprintf(file_out,"%d",n);return *this;}
NORMAL_OUT& operator<<(const unsigned int &n){fprintf(file_out,"%u",n);return *this;}
NORMAL_OUT& operator<<(const long long &n){fprintf(file_out,LLD,n);return *this;}
NORMAL_OUT& operator<<(const unsigned long long &n){fprintf(file_out,LLU,n);return *this;}
NORMAL_OUT& operator<<(const double &n){fprintf(file_out,"%lf",n);return *this;}
NORMAL_OUT& operator<<(const long double &n){fprintf(file_out,"%Lf",n);return *this;}
NORMAL_OUT& operator<<(const char c[]){fprintf(file_out,"%s",c);return *this;}
NORMAL_OUT& operator<<(const string &s){fprintf(file_out,"%s",s.c_str());return *this;}
} normal_out;
//}}}
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
int main(){
Int N;fin>>N;
vector<Int> A(N), k(N);
REP(i,N)fin>>A[i];
// auto s = whole(accumulate,A,(Int)0ll);
Int s = accumulate(ALL(A),0ll);
Int s0 = N*(Int)(N+1)/2;
if(s%s0!=0){
fout<<"NO"<<endl;
return 0;
}
Int t = s/s0, usum = 0;
REP(i,N){
int j = (i-1+N)%N;
Int u = t - (A[i]-A[j]);
if(u<0 or u%N!=0){
fout<<"NO"<<endl;
return 0;
}
u/=N;
k[i] = u;
usum+=u;
}
if(usum!=t){
fout<<"NO"<<endl;
return 0;
}
Int a0 = 0;
for(int i=1;i<=N;i++){
int j = (0-(i-1)+N)%N;
a0 += i*k[j];
}
if(a0!=A[0]){
fout<<"NO"<<endl;
return 0;
}
fout<<"YES"<<endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Boxes |
User |
chaemon |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
4150 Byte |
Status |
AC |
Exec Time |
17 ms |
Memory |
1792 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt |
All |
sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name |
Status |
Exec Time |
Memory |
in1.txt |
AC |
16 ms |
1792 KB |
in10.txt |
AC |
2 ms |
384 KB |
in11.txt |
AC |
13 ms |
1792 KB |
in12.txt |
AC |
13 ms |
1792 KB |
in13.txt |
AC |
11 ms |
1536 KB |
in14.txt |
AC |
1 ms |
256 KB |
in15.txt |
AC |
1 ms |
256 KB |
in16.txt |
AC |
1 ms |
256 KB |
in17.txt |
AC |
1 ms |
256 KB |
in18.txt |
AC |
1 ms |
256 KB |
in19.txt |
AC |
1 ms |
256 KB |
in2.txt |
AC |
17 ms |
1792 KB |
in20.txt |
AC |
1 ms |
256 KB |
in21.txt |
AC |
13 ms |
1792 KB |
in22.txt |
AC |
13 ms |
1792 KB |
in23.txt |
AC |
13 ms |
1792 KB |
in24.txt |
AC |
2 ms |
384 KB |
in25.txt |
AC |
2 ms |
384 KB |
in26.txt |
AC |
13 ms |
1792 KB |
in27.txt |
AC |
12 ms |
1792 KB |
in3.txt |
AC |
17 ms |
1792 KB |
in4.txt |
AC |
17 ms |
1792 KB |
in5.txt |
AC |
17 ms |
1792 KB |
in6.txt |
AC |
13 ms |
1792 KB |
in7.txt |
AC |
13 ms |
1792 KB |
in8.txt |
AC |
2 ms |
384 KB |
in9.txt |
AC |
2 ms |
384 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |
sample3.txt |
AC |
1 ms |
256 KB |