結果

問題 No.11 カードマッチ
ユーザー jp_stejp_ste
提出日時 2016-03-02 12:52:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 354 ms / 5,000 ms
コード長 2,167 bytes
コンパイル時間 5,211 ms
コンパイル使用メモリ 74,384 KB
実行使用メモリ 69,784 KB
最終ジャッジ日時 2023-08-02 00:19:51
合計ジャッジ時間 8,112 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,884 KB
testcase_01 AC 128 ms
55,748 KB
testcase_02 AC 128 ms
55,840 KB
testcase_03 AC 126 ms
55,904 KB
testcase_04 AC 188 ms
60,800 KB
testcase_05 AC 129 ms
55,672 KB
testcase_06 AC 354 ms
69,784 KB
testcase_07 AC 312 ms
60,720 KB
testcase_08 AC 306 ms
62,832 KB
testcase_09 AC 348 ms
67,888 KB
testcase_10 AC 266 ms
69,352 KB
testcase_11 AC 293 ms
64,444 KB
testcase_12 AC 305 ms
69,488 KB
testcase_13 AC 319 ms
53,460 KB
testcase_14 AC 210 ms
60,588 KB
testcase_15 AC 161 ms
56,224 KB
testcase_16 AC 199 ms
56,368 KB
testcase_17 AC 173 ms
55,672 KB
testcase_18 AC 171 ms
56,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            int W = scan.nextInt();
            int H = scan.nextInt();
            int N = scan.nextInt();
            
            ArrayList<Card> cardList = new ArrayList<>();            
            for(int i=0; i<N; i++) {
                int mark = scan.nextInt();
                int number = scan.nextInt();
                cardList.add(new Card(mark, number));
            }
            
            int numOfEachMark[] = new int[W+1];
            int numOfEachNumber[] = new int[H+1];
            boolean useMarks[] = new boolean[W+1];
            boolean useNumbers[] = new boolean[H+1];
            
            for(Card c : cardList) {
                numOfEachMark[c.mark]++;
                numOfEachNumber[c.number]++;
                useMarks[c.mark] = true;
                useNumbers[c.number] = true;
            }
            
            int ans = 0;
            for(int i=0; i<useMarks.length; i++) {
                if(useMarks[i]) {
                    ans += (H - numOfEachMark[i]);
                }
            }
            
            int numOfFoundNumber[] = new int[H+1];
            boolean flag[] = new boolean[W+1];
            for(Card c : cardList) {
                if(flag[c.mark]) {
                     numOfFoundNumber[c.number]--;
                } else {
                    flag[c.mark] = true;
                    for(int j=1; j<numOfFoundNumber.length; j++) {
                        if(j != c.number) { 
                            numOfFoundNumber[j]++;
                        }
                    }
                }
            }
            
            for(int i=0; i<useNumbers.length; i++) {
                if(useNumbers[i]) {
                    ans += (W - numOfEachNumber[i] - numOfFoundNumber[i]);
                }
            }
            
            System.out.println(ans);
        }
    }
}

class Card {
    int mark, number;
    Card(int mark, int number) {
        this.mark = mark;
        this.number = number;
    }
}
0