結果

問題 No.3016 unordered_mapなるたけ落とすマン
ユーザー TententenTententen
提出日時 2020-12-14 10:05:04
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,104 bytes
コンパイル時間 5,252 ms
コンパイル使用メモリ 87,332 KB
実行使用メモリ 76,104 KB
最終ジャッジ日時 2023-10-20 04:54:00
合計ジャッジ時間 52,992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 MLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 MLE -
testcase_31 MLE -
testcase_32 TLE -
testcase_33 MLE -
testcase_34 TLE -
testcase_35 MLE -
testcase_36 MLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 MLE -
testcase_40 MLE -
testcase_41 MLE -
testcase_42 MLE -
testcase_43 MLE -
testcase_44 MLE -
testcase_45 MLE -
testcase_46 MLE -
testcase_47 MLE -
testcase_48 MLE -
testcase_49 MLE -
testcase_50 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        MyMap exists = new MyMap();
        for (int i = 0; i < n; i++) {
            long x = sc.nextLong();
            exists.add(x);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m; i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(exists.get(sc.nextLong()));
        }
        System.out.println(sb);
    }
    
    static class MyMap {
        Unit[][] list;
        
        public MyMap() {
            list = new Unit[1000][100];
        }
        
        public void add(long x) {
            int hash = (int)(x % 1000);
            int idx = 0;
            while (list[hash][idx] != null && list[hash][idx].idx != x) {
                idx++;
                if (idx >= 100) {
                    hash++;
                    hash %= 1000;
                    idx = 0;
                }
            }
            if (list[hash][idx] == null) {
                list[hash][idx] = new Unit(x, 1);
            } else {
                list[hash][idx].value++;
            }
        }
        
        public int get(long x) {
            int hash = (int)(x % 1000);
            int idx = 0;
            while (list[hash][idx] != null && list[hash][idx].idx != x) {
                idx++;
                if (idx >= 100) {
                    hash++;
                    hash %= 1000;
                    idx = 0;
                }
            }
            if (list[hash][idx] == null) {
                return 0;
            } else {
                return list[hash][idx].value;
            }
        }
    }
    
    static class Unit {
        long idx;
        int value;
        
        public Unit(long idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public String toString() {
            return idx + ":" + value;
         }
    }
}
0