Submission #105331


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 2477 Byte
Status
Exec Time 1623 ms
Memory 63912 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 465 ms 23476 KB
00_sample_02.txt 463 ms 23472 KB
00_sample_03.txt 462 ms 23480 KB
chokudai_solo_01.txt 471 ms 23476 KB
chokudai_solo_02.txt 461 ms 23468 KB
chokudai_solo_03.txt 496 ms 23992 KB
chokudai_vs_cucumber_01.txt 525 ms 26724 KB
chokudai_vs_cucumber_02.txt 761 ms 42440 KB
chokudai_vs_cucumber_03.txt 684 ms 42352 KB
chokudai_vs_cucumber_04.txt 543 ms 26588 KB
chokudai_vs_cucumber_05.txt 699 ms 41388 KB
chokudai_vs_kensho_01.txt 544 ms 26752 KB
chokudai_vs_kensho_02.txt 516 ms 24632 KB
chokudai_vs_kensho_03.txt 532 ms 26860 KB
chokudai_vs_kensho_04.txt 549 ms 26768 KB
chokudai_vs_kensho_05.txt 677 ms 42748 KB
chokudai_vs_kensho_06.txt 735 ms 42564 KB
chokudai_vs_kensho_07.txt 1623 ms 63912 KB
chokudai_vs_kensho_08.txt 781 ms 42600 KB
chokudai_vs_kensho_09.txt 500 ms 24240 KB
chokudai_vs_laycurse_01.txt 536 ms 26644 KB
chokudai_vs_laycurse_02.txt 523 ms 26608 KB
chokudai_vs_laycurse_03.txt 543 ms 26652 KB
chokudai_vs_sanagipp_01.txt 541 ms 27532 KB
chokudai_vs_sanagipp_02.txt 548 ms 26292 KB
chokudai_vs_sanagipp_03.txt 530 ms 26640 KB
chokudai_vs_sanagipp_04.txt 546 ms 26864 KB
chokudai_vs_takahashikun_01.txt 470 ms 23860 KB
chokudai_vs_takahashikun_02.txt 496 ms 24360 KB
chokudai_vs_takahashikun_03.txt 537 ms 26632 KB
chokudai_vs_takahashikun_04.txt 536 ms 26768 KB
chokudai_vs_uwitenpen_01.txt 543 ms 26788 KB
chokudai_vs_uwitenpen_02.txt 521 ms 24888 KB
chokudai_vs_uwitenpen_03.txt 549 ms 28100 KB