結果

問題 No.831 都市めぐり
ユーザー htensaihtensai
提出日時 2020-05-08 15:49:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 749 bytes
コンパイル時間 1,939 ms
コンパイル使用メモリ 71,664 KB
実行使用メモリ 56,428 KB
最終ジャッジ日時 2023-09-16 08:29:14
合計ジャッジ時間 6,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,984 KB
testcase_01 AC 120 ms
56,164 KB
testcase_02 AC 120 ms
56,056 KB
testcase_03 AC 120 ms
55,612 KB
testcase_04 AC 120 ms
55,788 KB
testcase_05 AC 122 ms
55,684 KB
testcase_06 AC 123 ms
56,072 KB
testcase_07 AC 121 ms
56,016 KB
testcase_08 AC 118 ms
55,944 KB
testcase_09 AC 119 ms
56,428 KB
testcase_10 AC 119 ms
55,848 KB
testcase_11 AC 121 ms
55,876 KB
testcase_12 AC 122 ms
55,804 KB
testcase_13 AC 121 ms
55,828 KB
testcase_14 AC 123 ms
55,564 KB
testcase_15 AC 125 ms
55,728 KB
testcase_16 AC 125 ms
55,548 KB
testcase_17 AC 126 ms
55,776 KB
testcase_18 AC 127 ms
56,052 KB
testcase_19 AC 126 ms
55,744 KB
testcase_20 AC 129 ms
55,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 1) {
		    System.out.println(0);
		    return;
		} else if (n == 2) {
		    System.out.println(4);
		    return;
		}
		long total = n + n - 1;
		long left = 2;
		long right = n;
		if (n % 2 == 1) {
    		while (right - left > 1) {
    		    total += left * right + left * (right - 2);
    		    left++;
    		    right--;
    		}
    		total += left * right;
		} else {
		    while (right - left > 2) {
    		    total += left * right + left * (right - 2);
    		    left++;
    		    right--;
		    }
		    total += left * right + left * (right - 1);
		}
		System.out.println(total);
	}
}
0