Submission #1093576


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    if (N == 1) {
      System.out.println("YES");
    }

    long[] A = sc.nextLongList(N);
    long sum = Arrays.stream(A).sum();

    long x = N * (N + 1) / 2;
    if (sum % x != 0) {
      System.out.println("NO");
      return;
    }
    long y = sum / x;

    long count = 0;
    for (int i = 0; i < N; i ++) {

      long now = A[(i + 1) % N] - A[i];
      
      if ((y - now) % N != 0) {
        System.out.println("NO");
        return;
      }
      long m = Math.abs(y - now) / N;
      count += m;
    }
    
    if (count != y) {
      System.out.println("NO");
      return;
    }
    System.out.println("YES");
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

Submission Info

Submission Time
Task B - Boxes
User hiromi_ayase
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 3520 Byte
Status WA
Exec Time 246 ms
Memory 15180 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 23
WA × 7
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
Case Name Status Exec Time Memory
in1.txt WA 246 ms 15180 KB
in10.txt AC 191 ms 13640 KB
in11.txt AC 211 ms 14520 KB
in12.txt AC 225 ms 15168 KB
in13.txt AC 207 ms 14268 KB
in14.txt WA 193 ms 13904 KB
in15.txt WA 187 ms 14032 KB
in16.txt AC 182 ms 13520 KB
in17.txt AC 189 ms 13900 KB
in18.txt AC 189 ms 14032 KB
in19.txt AC 189 ms 14160 KB
in2.txt WA 209 ms 14392 KB
in20.txt AC 180 ms 13776 KB
in21.txt AC 208 ms 14848 KB
in22.txt AC 214 ms 14532 KB
in23.txt AC 215 ms 14408 KB
in24.txt AC 201 ms 14152 KB
in25.txt AC 194 ms 13700 KB
in26.txt AC 212 ms 14284 KB
in27.txt AC 208 ms 14412 KB
in3.txt WA 209 ms 14660 KB
in4.txt WA 210 ms 14536 KB
in5.txt WA 207 ms 14528 KB
in6.txt AC 211 ms 14408 KB
in7.txt AC 209 ms 14780 KB
in8.txt AC 202 ms 14312 KB
in9.txt AC 196 ms 13836 KB
sample1.txt AC 180 ms 13644 KB
sample2.txt AC 182 ms 13512 KB
sample3.txt AC 193 ms 14036 KB