結果

問題 No.2655 Increasing Strides
コンテスト
ユーザー ks2m
提出日時 2024-03-01 21:34:52
言語 Java
(openjdk 26.0.2.1 + ACL)
コンパイル:
javac -J-Duser.language=en -encoding UTF8 -cp /opt/aclib/ac_library.jar _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true -cp .:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 56 ms / 2,000 ms
+ 711µs
コード長 790 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,660 ms
コンパイル使用メモリ 84,464 KB
実行使用メモリ 43,256 KB
最終ジャッジ日時 2026-09-06 02:27:31
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		long s0 = 0;
		long s1 = 0;
		for (int i = 2; i <= n; i += 2) {
			s0 += i;
		}
		for (int i = 1; i <= n; i += 2) {
			s1 += i;
		}
		if (s0 % 2 != 0 || s1 % 2 != 0) {
			System.out.println("No");
			return;
		}
		s0 /= 2;
		s1 /= 2;

		int start = n;
		if (n % 2 == 1) {
			start--;
		}
		for (int i = start; i > 0; i -= 2) {
			if (i <= s0) {
				s0 -= i;
			}
		}

		start = n;
		if (n % 2 == 0) {
			start--;
		}
		for (int i = start; i > 0; i -= 2) {
			if (i <= s1) {
				s1 -= i;
			}
		}

		if (s0 == 0 && s1 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}
0