AtCoder Grand Contest 010

Submission #1358864

Source codeソースコード

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
	}

	public boolean hasNext() {
		// return cnt < N;
		return cnt < 1;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		String[] strArr = str.split(" ");
		long sum = 0;
		for (int i = 0; i < N; i++) {
			sum += Long.parseLong(strArr[i]);
		}

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

		boolean able = true;
		long edge = 0;
		for (int i = 0; i < N; i++) {
			long d = -Long.parseLong(strArr[i]) - k;
			if (i == N - 1)
				d += Long.parseLong(strArr[0]);
			else
				d += Long.parseLong(strArr[i + 1]);
			// System.out.println(d);
			if (d > 0) {
				able = false;
				break;
			}
			if (d < 0) {
				if (d % N != 0) {
					able = false;
					break;
				}
				edge -= d;
			}
		}
		if (able) {
			// System.out.println(edge);
			able = (edge == N * k);
		}

		if (able)
			System.out.println("YES");
		else
			System.out.println("NO");
	}

}

Submission

Task問題 B - Boxes
User nameユーザ名 i-don
Created time投稿日時
Language言語 Java8 (OpenJDK 1.8.0)
Status状態 AC
Score得点 500
Source lengthソースコード長 1683 Byte
File nameファイル名
Exec time実行時間 203 ms
Memory usageメモリ使用量 38208 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,sample1.txt,sample2.txt,sample3.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
in1.txt AC 188 ms 35620 KB
in10.txt AC 111 ms 23380 KB
in11.txt AC 167 ms 35028 KB
in12.txt AC 180 ms 35852 KB
in13.txt AC 179 ms 32908 KB
in14.txt AC 70 ms 19412 KB
in15.txt AC 71 ms 23252 KB
in16.txt AC 69 ms 18132 KB
in17.txt AC 70 ms 19668 KB
in18.txt AC 71 ms 18900 KB
in19.txt AC 72 ms 19028 KB
in2.txt AC 191 ms 38208 KB
in20.txt AC 70 ms 19156 KB
in21.txt AC 174 ms 37716 KB
in22.txt AC 183 ms 37656 KB
in23.txt AC 181 ms 37516 KB
in24.txt AC 99 ms 21076 KB
in25.txt AC 114 ms 23508 KB
in26.txt AC 164 ms 34004 KB
in27.txt AC 171 ms 36876 KB
in3.txt AC 197 ms 37624 KB
in4.txt AC 203 ms 36232 KB
in5.txt AC 191 ms 38040 KB
in6.txt AC 180 ms 36876 KB
in7.txt AC 186 ms 35416 KB
in8.txt AC 114 ms 24532 KB
in9.txt AC 112 ms 23892 KB
sample1.txt AC 72 ms 20944 KB
sample2.txt AC 70 ms 15828 KB
sample3.txt AC 71 ms 21076 KB