Submission #105417


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>();

    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(" ")[0]);
                if(val * m[i] > mx){
                    mx = val * m[i];
                    mxSmall = a.split(" ")[1];
                }
            }
        String ans = mx + " " + 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(" ")[0];
                String name = a.split(" ")[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 2481 Byte
Status
Exec Time 1955 ms
Memory 64140 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 586 ms 23476 KB
00_sample_02.txt 515 ms 23512 KB
00_sample_03.txt 506 ms 23472 KB
chokudai_solo_01.txt 500 ms 23344 KB
chokudai_solo_02.txt 501 ms 23344 KB
chokudai_solo_03.txt 539 ms 24244 KB
chokudai_vs_cucumber_01.txt 554 ms 27836 KB
chokudai_vs_cucumber_02.txt 769 ms 42284 KB
chokudai_vs_cucumber_03.txt 844 ms 42040 KB
chokudai_vs_cucumber_04.txt 711 ms 26936 KB
chokudai_vs_cucumber_05.txt 858 ms 41256 KB
chokudai_vs_kensho_01.txt 614 ms 26432 KB
chokudai_vs_kensho_02.txt 523 ms 24844 KB
chokudai_vs_kensho_03.txt 609 ms 26700 KB
chokudai_vs_kensho_04.txt 632 ms 26780 KB
chokudai_vs_kensho_05.txt 750 ms 42220 KB
chokudai_vs_kensho_06.txt 859 ms 42120 KB
chokudai_vs_kensho_07.txt 1955 ms 64140 KB
chokudai_vs_kensho_08.txt 874 ms 42228 KB
chokudai_vs_kensho_09.txt 548 ms 24100 KB
chokudai_vs_laycurse_01.txt 602 ms 26452 KB
chokudai_vs_laycurse_02.txt 642 ms 26740 KB
chokudai_vs_laycurse_03.txt 632 ms 26984 KB
chokudai_vs_sanagipp_01.txt 587 ms 27440 KB
chokudai_vs_sanagipp_02.txt 557 ms 27324 KB
chokudai_vs_sanagipp_03.txt 550 ms 26760 KB
chokudai_vs_sanagipp_04.txt 557 ms 26420 KB
chokudai_vs_takahashikun_01.txt 473 ms 23732 KB
chokudai_vs_takahashikun_02.txt 500 ms 24628 KB
chokudai_vs_takahashikun_03.txt 537 ms 26728 KB
chokudai_vs_takahashikun_04.txt 581 ms 26564 KB
chokudai_vs_uwitenpen_01.txt 728 ms 32576 KB
chokudai_vs_uwitenpen_02.txt 584 ms 26544 KB
chokudai_vs_uwitenpen_03.txt 734 ms 31368 KB