結果

問題 No.831 都市めぐり
ユーザー tentententen
提出日時 2020-09-01 01:56:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 74,112 KB
実行使用メモリ 41,292 KB
最終ジャッジ日時 2024-04-28 11:46:52
合計ジャッジ時間 5,362 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
41,132 KB
testcase_01 AC 110 ms
40,120 KB
testcase_02 AC 120 ms
41,032 KB
testcase_03 AC 117 ms
40,892 KB
testcase_04 AC 119 ms
40,948 KB
testcase_05 AC 124 ms
41,232 KB
testcase_06 AC 113 ms
40,112 KB
testcase_07 AC 114 ms
41,292 KB
testcase_08 AC 118 ms
41,168 KB
testcase_09 AC 123 ms
41,044 KB
testcase_10 AC 113 ms
39,848 KB
testcase_11 AC 121 ms
41,164 KB
testcase_12 AC 126 ms
41,036 KB
testcase_13 AC 109 ms
40,152 KB
testcase_14 AC 124 ms
40,968 KB
testcase_15 AC 120 ms
41,044 KB
testcase_16 AC 115 ms
41,052 KB
testcase_17 AC 123 ms
40,816 KB
testcase_18 AC 122 ms
41,060 KB
testcase_19 AC 123 ms
40,860 KB
testcase_20 AC 123 ms
41,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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