Submission #308129


Source Code Expand

Copy
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
double memo[400];
bool vis[400];
vector<P> G[400];
void solve(int idx) {
	for(int i=0;i<G[idx].size();i++) {
		P p=G[idx][i];
		if(!vis[p.first]) {
			if(p.second>0) memo[p.first]=memo[idx]*p.second;
			else memo[p.first]=memo[idx]/(-p.second);
			vis[p.first]=1;
			solve(p.first);
		}
	}
}
int main() {
	int N;
	cin>>N;
	map<string,int> en;
	vector<string> de;
	for(int i=0;i<N;i++) {
		string large,small;
		int m,L,S;
		cin>>large>>m>>small;
		if(en.find(large)==en.end()) {
			L=en.size();
			en[large]=L;
			de.push_back(large);
		}else {
			L=en[large];
		}
		if(en.find(small)==en.end()) {
			S=en.size();
			en[small]=S;
			de.push_back(small);
		}else {
			S=en[small];
		}
		G[L].push_back(P(S,-m));
		G[S].push_back(P(L,m));
	}
	memo[0]=1;
	vis[0]=1;
	solve(0);
	int L=0,S=0;
	for(int i=0;i<en.size();i++) {
		if(memo[L]<memo[i]) L=i;
		if(memo[S]>memo[i]) S=i;
	}
	cout<<"1"<<de[L]<<"="<<(int)(memo[L]/memo[S]+0.5)<<de[S]<<endl;
}

Submission Info

Submission Time
Task C - 変わった単位
User Div9851
Language C++ (G++ 4.6.4)
Score 100
Code Size 1157 Byte
Status
Exec Time 35 ms
Memory 1076 KB

Test Cases

Set Name Score / Max Score Test Cases
All 100 / 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 35 ms 1004 KB
00_sample_02.txt 27 ms 1044 KB
00_sample_03.txt 27 ms 1048 KB
chokudai_solo_01.txt 28 ms 1048 KB
chokudai_solo_02.txt 27 ms 1044 KB
chokudai_solo_03.txt 28 ms 1040 KB
chokudai_vs_cucumber_01.txt 29 ms 1048 KB
chokudai_vs_cucumber_02.txt 28 ms 1044 KB
chokudai_vs_cucumber_03.txt 28 ms 1040 KB
chokudai_vs_cucumber_04.txt 30 ms 1056 KB
chokudai_vs_cucumber_05.txt 31 ms 1008 KB
chokudai_vs_kensho_01.txt 30 ms 1056 KB
chokudai_vs_kensho_02.txt 29 ms 1072 KB
chokudai_vs_kensho_03.txt 30 ms 1076 KB
chokudai_vs_kensho_04.txt 30 ms 1072 KB
chokudai_vs_kensho_05.txt 30 ms 1052 KB
chokudai_vs_kensho_06.txt 28 ms 1052 KB
chokudai_vs_kensho_07.txt 31 ms 1072 KB
chokudai_vs_kensho_08.txt 33 ms 992 KB
chokudai_vs_kensho_09.txt 30 ms 940 KB
chokudai_vs_laycurse_01.txt 32 ms 980 KB
chokudai_vs_laycurse_02.txt 29 ms 1052 KB
chokudai_vs_laycurse_03.txt 29 ms 1060 KB
chokudai_vs_sanagipp_01.txt 29 ms 1064 KB
chokudai_vs_sanagipp_02.txt 29 ms 1064 KB
chokudai_vs_sanagipp_03.txt 28 ms 1056 KB
chokudai_vs_sanagipp_04.txt 29 ms 1064 KB
chokudai_vs_takahashikun_01.txt 28 ms 1052 KB
chokudai_vs_takahashikun_02.txt 28 ms 936 KB
chokudai_vs_takahashikun_03.txt 27 ms 1048 KB
chokudai_vs_takahashikun_04.txt 29 ms 1064 KB
chokudai_vs_uwitenpen_01.txt 28 ms 1060 KB
chokudai_vs_uwitenpen_02.txt 28 ms 1064 KB
chokudai_vs_uwitenpen_03.txt 29 ms 1060 KB