結果

問題 No.84 悪の算盤
ユーザー soujikisoujiki
提出日時 2015-04-29 21:55:17
言語 Java19
(openjdk 19.0.1)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 925 bytes
コンパイル時間 4,211 ms
コンパイル使用メモリ 73,780 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-08-03 12:07:09
合計ジャッジ時間 6,352 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,328 KB
testcase_01 AC 124 ms
55,608 KB
testcase_02 AC 123 ms
55,840 KB
testcase_03 AC 122 ms
55,664 KB
testcase_04 AC 123 ms
55,696 KB
testcase_05 AC 124 ms
55,564 KB
testcase_06 AC 123 ms
53,792 KB
testcase_07 AC 131 ms
55,804 KB
testcase_08 AC 126 ms
55,672 KB
testcase_09 AC 124 ms
56,084 KB
testcase_10 AC 123 ms
55,604 KB
testcase_11 AC 122 ms
55,716 KB
testcase_12 AC 123 ms
55,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Yukicoder_84{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		long R = stdIn.nextLong();
		long C = stdIn.nextLong();
		long ans = 0;
		if(R==1 && C==1){
			System.out.println(0);
		}
		else{
			if(R%2==0){
				if(C%2==0){
					if(R==C){
						ans = (long)Math.pow(R/2,2)-1;
					}
					else{
						ans = R*C/2-1;
					}
				}
				else{
					if(C==1){
						ans = R/2-1;
					}
					else{
						ans = (C-1)*R/2+R/2-1;
					}
				}
			}
			else{
				if(C%2==0){
					if(R==1){
						ans = C/2-1;
					}
					else{
						ans = (R-1)*C/2+C/2-1;
					}
				}
				else{
					if(R==C){
						if(R==999999999){
							ans = (long)499999999*(long)500000000;
						}
						else{
							ans = (long)1+R/(long)2;
							ans = ans*R/(long)2;
						}
					}
					else{
						ans = (R-1)*(C-1)/2+(C-1)/2+(R-1)/2;
					}
				}
			}
			System.out.println(ans);
		}
	}
}
0