結果

問題 No.2655 Increasing Strides
コンテスト
ユーザー ks2m
提出日時 2024-03-01 21:34:52
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 790 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,797 ms
コンパイル使用メモリ 82,992 KB
実行使用メモリ 41,856 KB
最終ジャッジ日時 2026-04-15 22:19:04
合計ジャッジ時間 5,337 ms
ジャッジサーバーID
(参考情報)
judge3_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