結果

問題 No.11 カードマッチ
ユーザー SagToki
提出日時 2018-06-04 10:17:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 160 ms / 5,000 ms
コード長 1,770 bytes
コンパイル時間 4,313 ms
コンパイル使用メモリ 80,692 KB
実行使用メモリ 54,412 KB
最終ジャッジ日時 2024-06-30 09:32:38
合計ジャッジ時間 7,873 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.InputMismatchException;

public class CardMatch {
    static Scanner scanner = new Scanner(System.in);
    
    public static void main(String[] args){
        long W = Input(1,1000000);
        long H = Input(1,1000000);
        long N = Input(1, (int) Math.min(W*H,100));
        ArrayList<Integer> S = new ArrayList<>();
        ArrayList<Integer> K = new ArrayList<>();
        for(int i = 0 ; i < N ; i++){
           S.add(Input(1, (int) W));
           K.add(Input(1, (int) H));
        }
        long Result = Processing(W,H,N,S,K);
        System.out.println(Result);
    }
    
    public static int Input(int Min , int Max){
        int Number = scanner.nextInt();
        try{
            if(Number < Min || Number > Max){
                System.out.println(Min + "以上" + Max + "以下の数字で入力してください");
                System.exit(0);
            } 
        }catch(InputMismatchException e){
            System.out.println("数字を入力してください");
            System.exit(0);
        }catch(Exception E){
            System.out.println("想定外のエラーです");
            System.exit(0);
        }
        return Number;
    }
    
    public static long Processing(long W , long H , long N
                                  , ArrayList<Integer> S , ArrayList<Integer> K){
        ArrayList<Integer> CountS = new ArrayList<>(new HashSet<>(S));
        ArrayList<Integer> CountK = new ArrayList<>(new HashSet<>(K));
        long Total = W * H ;
        long UnmatchW = W - CountS.size();
        long UnmatchH = H - CountK.size();
        long Result = Total - UnmatchW * UnmatchH - N;
        return Result;
    }
}
0