Submission #105569


Source Code Expand

Copy
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args) throws Exception{
        new Main().run();
    }

    int n;
    String[] large;
    int[] m;
    String[] small;
    HashSet<String> us = new HashSet<String>();
    HashMap<String, String> memo = new HashMap<String, String>();
    final String S = "\t";

    String tra(String s){
        if(memo.containsKey(s))
            return memo.get(s);
        int mx = 1;
        String mxSmall = s;
        for(int i = 0; i < n; i++)
            if(large[i].equals(s)){
                String a = tra(small[i]);
                int val = Integer.parseInt(a.split(S)[0]);
                if(val * m[i] > mx){
                    mx = val * m[i];
                    mxSmall = a.split(S)[1];
                }
            }
        String ans = mx + S + mxSmall;
        memo.put(s, ans);
        return ans;
    }

    void run() throws Exception{
        Scanner sc = new Scanner(System.in);
        //BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
        // only sc.readLine() is available
        n = sc.nextInt();
        large = new String[n];
        m = new int[n];
        small = new String[n];
        for(int i = 0; i < n; i++){
            large[i] = sc.next();
            m[i] = sc.nextInt();
            small[i] = sc.next();
            us.add(large[i]); us.add(small[i]);
        }
        ArrayList<String> ua = new ArrayList<String>();
        for(String s : us)ua.add(s);
        boolean[] cand = new boolean[ua.size()];
        Arrays.fill(cand, true);
        for(int i = 0; i < ua.size(); i++)
            for(int j = 0; j < n; j++)
                if(ua.get(i).equals(small[j])){
                    cand[i] = false;
                    break;
                }
        int mx = 0;
        String mxLarge = "hoge";
        String mxSmall = "fuga";
        for(int i = 0; i < ua.size(); i++)
            if(cand[i]){
                String a = tra(ua.get(i));
                String num = a.split(S)[0];
                String name = a.split(S)[1];
                int val = Integer.parseInt(num);
                if(mx < val){
                    mx = val;
                    mxLarge = ua.get(i);
                    mxSmall = name;
                }
            }
        System.out.printf("1%s=%d%s\n", mxLarge, mx, mxSmall);
    }
}

Submission Info

Submission Time
Task C - 変わった単位
User chronotable
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 2495 Byte
Status
Exec Time 1637 ms
Memory 63880 KB

Test Cases

Set Name Score / Max Score Test Cases
All 0 / 100 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, chokudai_solo_01.txt, chokudai_solo_02.txt, chokudai_solo_03.txt, chokudai_vs_cucumber_01.txt, chokudai_vs_cucumber_02.txt, chokudai_vs_cucumber_03.txt, chokudai_vs_cucumber_04.txt, chokudai_vs_cucumber_05.txt, chokudai_vs_kensho_01.txt, chokudai_vs_kensho_02.txt, chokudai_vs_kensho_03.txt, chokudai_vs_kensho_04.txt, chokudai_vs_kensho_05.txt, chokudai_vs_kensho_06.txt, chokudai_vs_kensho_07.txt, chokudai_vs_kensho_08.txt, chokudai_vs_kensho_09.txt, chokudai_vs_laycurse_01.txt, chokudai_vs_laycurse_02.txt, chokudai_vs_laycurse_03.txt, chokudai_vs_sanagipp_01.txt, chokudai_vs_sanagipp_02.txt, chokudai_vs_sanagipp_03.txt, chokudai_vs_sanagipp_04.txt, chokudai_vs_takahashikun_01.txt, chokudai_vs_takahashikun_02.txt, chokudai_vs_takahashikun_03.txt, chokudai_vs_takahashikun_04.txt, chokudai_vs_uwitenpen_01.txt, chokudai_vs_uwitenpen_02.txt, chokudai_vs_uwitenpen_03.txt
Case Name Status Exec Time Memory
00_sample_01.txt 542 ms 23476 KB
00_sample_02.txt 483 ms 23352 KB
00_sample_03.txt 488 ms 23476 KB
chokudai_solo_01.txt 488 ms 23472 KB
chokudai_solo_02.txt 479 ms 23476 KB
chokudai_solo_03.txt 516 ms 23992 KB
chokudai_vs_cucumber_01.txt 560 ms 26652 KB
chokudai_vs_cucumber_02.txt 789 ms 42356 KB
chokudai_vs_cucumber_03.txt 707 ms 42476 KB
chokudai_vs_cucumber_04.txt 575 ms 26592 KB
chokudai_vs_cucumber_05.txt 740 ms 41392 KB
chokudai_vs_kensho_01.txt 573 ms 26808 KB
chokudai_vs_kensho_02.txt 543 ms 24748 KB
chokudai_vs_kensho_03.txt 568 ms 26784 KB
chokudai_vs_kensho_04.txt 587 ms 27360 KB
chokudai_vs_kensho_05.txt 673 ms 42728 KB
chokudai_vs_kensho_06.txt 760 ms 42412 KB
chokudai_vs_kensho_07.txt 1637 ms 63880 KB
chokudai_vs_kensho_08.txt 826 ms 42532 KB
chokudai_vs_kensho_09.txt 518 ms 24120 KB
chokudai_vs_laycurse_01.txt 576 ms 26712 KB
chokudai_vs_laycurse_02.txt 550 ms 26784 KB
chokudai_vs_laycurse_03.txt 572 ms 26832 KB
chokudai_vs_sanagipp_01.txt 565 ms 26904 KB
chokudai_vs_sanagipp_02.txt 575 ms 26572 KB
chokudai_vs_sanagipp_03.txt 549 ms 26740 KB
chokudai_vs_sanagipp_04.txt 554 ms 26724 KB
chokudai_vs_takahashikun_01.txt 495 ms 23732 KB
chokudai_vs_takahashikun_02.txt 529 ms 23984 KB
chokudai_vs_takahashikun_03.txt 561 ms 26612 KB
chokudai_vs_takahashikun_04.txt 566 ms 26268 KB
chokudai_vs_uwitenpen_01.txt 565 ms 26696 KB
chokudai_vs_uwitenpen_02.txt 546 ms 24884 KB
chokudai_vs_uwitenpen_03.txt 571 ms 26796 KB