結果

問題 No.8016 unordered_mapなるたけ落とすマン
ユーザー Tententen
提出日時 2020-12-14 10:05:04
言語 Java
(openjdk 23)
結果
MLE  
実行時間 -
コード長 2,104 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 79,588 KB
実行使用メモリ 73,448 KB
最終ジャッジ日時 2024-09-20 00:37:05
合計ジャッジ時間 40,867 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 3
other TLE * 36 MLE * 12
権限があれば一括ダウンロードができます

ソースコード

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