AtCoder Grand Contest 010

Submission #1092258

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int main() {
  ll n;
  scanf("%lld", &n);
  vll a(n);
  ll sum = 0;
  rep (i, n) {
    scanf("%lld", &a[i]);
    sum += a[i];
  }
  ll tsum = n * (n+1) / 2;
  if (sum % tsum != 0) {
    printf("NO\n");
    return 0;
  }
  ll times = sum / tsum;
  vll diff(n);
  rep (i, n-1) {
    diff[i] = a[i+1] - a[i];
  }
  diff[n-1] = a[0] - a[n-1];
  ll cnt = 0;
  rep (i, n) {
    if (diff[i] == times) {
      continue;
    }
    ll delta = times - diff[i];
    if (delta < 0 || delta % n != 0) {
      printf("NO\n");
      return 0;
    }
    cnt += (delta / n);
  }
  if (cnt != times) {
    printf("NO\n");
    return 0;
  }
  printf("YES\n");
  return 0;
}

Submission

Task問題 B - Boxes
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 500
Source lengthソースコード長 1590 Byte
File nameファイル名
Exec time実行時間 17 ms
Memory usageメモリ使用量 1792 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt,sample3.txt
All 500 / 500 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt AC 15 ms 1792 KB
in10.txt AC 4 ms 384 KB
in11.txt AC 17 ms 1792 KB
in12.txt AC 17 ms 1792 KB
in13.txt AC 15 ms 1536 KB
in14.txt AC 3 ms 256 KB
in15.txt AC 3 ms 256 KB
in16.txt AC 3 ms 256 KB
in17.txt AC 3 ms 256 KB
in18.txt AC 3 ms 256 KB
in19.txt AC 3 ms 256 KB
in2.txt AC 17 ms 1792 KB
in20.txt AC 3 ms 256 KB
in21.txt AC 16 ms 1024 KB
in22.txt AC 16 ms 1024 KB
in23.txt AC 16 ms 1024 KB
in24.txt AC 3 ms 384 KB
in25.txt AC 4 ms 384 KB
in26.txt AC 17 ms 1792 KB
in27.txt AC 17 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 16 ms 1024 KB
in7.txt AC 16 ms 1024 KB
in8.txt AC 4 ms 384 KB
in9.txt AC 4 ms 384 KB
sample1.txt AC 3 ms 256 KB
sample2.txt AC 3 ms 256 KB
sample3.txt AC 3 ms 256 KB