Submission #105733


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);
        double mx = 1;
        String mxSmall = s;
        for(int i = 0; i < n; i++)
            if(large[i].equals(s)){
                String a = tra(small[i]);
                double val = Double.parseDouble(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;
                }
        double 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];
                double val = Double.parseDouble(num);
                if(mx < val){
                    mx = val;
                    mxLarge = ua.get(i);
                    mxSmall = name;
                }
            }
        System.out.printf("1%s=%d%s\n", mxLarge, (int)mx, mxSmall);
    }
}

Submission Info

Submission Time
Task C - 変わった単位
User chronotable
Language Java (OpenJDK 1.7.0)
Score 0
Code Size 2516 Byte
Status
Exec Time 1761 ms
Memory 64652 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 531 ms 23604 KB
00_sample_02.txt 465 ms 23468 KB
00_sample_03.txt 468 ms 23596 KB
chokudai_solo_01.txt 463 ms 23468 KB
chokudai_solo_02.txt 478 ms 23476 KB
chokudai_solo_03.txt 537 ms 24040 KB
chokudai_vs_cucumber_01.txt 566 ms 26372 KB
chokudai_vs_cucumber_02.txt 768 ms 41756 KB
chokudai_vs_cucumber_03.txt 712 ms 41760 KB
chokudai_vs_cucumber_04.txt 538 ms 26516 KB
chokudai_vs_cucumber_05.txt 722 ms 41304 KB
chokudai_vs_kensho_01.txt 564 ms 26544 KB
chokudai_vs_kensho_02.txt 525 ms 24712 KB
chokudai_vs_kensho_03.txt 549 ms 26928 KB
chokudai_vs_kensho_04.txt 557 ms 26908 KB
chokudai_vs_kensho_05.txt 667 ms 42708 KB
chokudai_vs_kensho_06.txt 754 ms 41816 KB
chokudai_vs_kensho_07.txt 1761 ms 64652 KB
chokudai_vs_kensho_08.txt 829 ms 41604 KB
chokudai_vs_kensho_09.txt 544 ms 24120 KB
chokudai_vs_laycurse_01.txt 553 ms 26472 KB
chokudai_vs_laycurse_02.txt 541 ms 26896 KB
chokudai_vs_laycurse_03.txt 543 ms 26468 KB
chokudai_vs_sanagipp_01.txt 580 ms 28300 KB
chokudai_vs_sanagipp_02.txt 550 ms 26628 KB
chokudai_vs_sanagipp_03.txt 554 ms 26724 KB
chokudai_vs_sanagipp_04.txt 586 ms 26824 KB
chokudai_vs_takahashikun_01.txt 487 ms 23860 KB
chokudai_vs_takahashikun_02.txt 502 ms 24120 KB
chokudai_vs_takahashikun_03.txt 549 ms 26752 KB
chokudai_vs_takahashikun_04.txt 543 ms 26584 KB
chokudai_vs_uwitenpen_01.txt 574 ms 27048 KB
chokudai_vs_uwitenpen_02.txt 527 ms 24880 KB
chokudai_vs_uwitenpen_03.txt 551 ms 26532 KB