QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131838#5133. Imperfect Imperial Unitsmshcherba#WA 5ms4096kbC++171.5kb2023-07-28 15:23:492023-07-28 15:23:52

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-28 15:23:52]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:4096kb
  • [2023-07-28 15:23:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

map<string, int> idx;

int getIdx(const string& s) {
	if (!idx.count(s)) {
		int sz = SZ(idx);
		idx[s] = sz;
	}
	return idx[s];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << scientific << setprecision(10);
	int n, q;
	cin >> n >> q;
	vector d(2 * n, vector<double>(2 * n, -1));
	FOR(i, 0, 2 * n) {
		d[i][i] = 1;
	}
	FOR(i, 0, n) {
		string one, unit1, equals, unit2;
		double v;
		cin >> one >> unit1 >> equals >> v >> unit2;
		assert(one == "1" && equals == "=");
		int idx1 = getIdx(unit1), idx2 = getIdx(unit2);
		d[idx1][idx2] = v;
		d[idx2][idx1] = 1 / v;
	}
	int m = SZ(idx);
	FOR(k, 0, m) {
		FOR(i, 0, m) {
			FOR(j, 0, m) {
				if (d[i][k] >= 0 && d[k][j] >= 0) {
					d[i][j] = d[i][k] * d[k][j];
				}
			}
		}
	}
	while (q--) {
		double v;
		string unit1, unit2, to;
		cin >> v >> unit1 >> to >> unit2;
		assert(to == "to");
		int idx1 = getIdx(unit1), idx2 = getIdx(unit2);
		if (d[idx1][idx2] < 0) {
			cout << "impossible\n";
		}
		else {
			cout << v * d[idx1][idx2] << "\n";
		}
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3664kb

input:

4 3
1 foot = 12 inch
1 yard = 3 foot
1 meter = 100 centimeter
1 centimeter = 10 millimeter
750 millimeter to meter
42 yard to inch
10 meter to foot

output:

7.5000000000e-01
1.5120000000e+03
impossible

result:

ok 

Test #2:

score: 0
Accepted
time: 1ms
memory: 3736kb

input:

4 3
1 fortnight = 14 day
1 microcentury = 0.036525 day
1 microcentury = 1000 nanocentury
1 week = 7 day
22.2 fortnight to nanocentury
2.5 nanocentury to week
3.14 day to fortnight

output:

8.5092402464e+06
1.3044642857e-05
2.2428571429e-01

result:

ok 

Test #3:

score: 0
Accepted
time: 1ms
memory: 3748kb

input:

10 2
1 micrometer = 1000 nanometer
1 millimeter = 1000 micrometer
1 meter = 1000 millimeter
1 kilometer = 1000 meter
1 megameter = 1000 kilometer
1 lightsecond = 299.792458 meter
1 lightminute = 60 lightsecond
1 lighthour = 60 lightminute
1 lightday = 24 lighthour
1 lightyear = 365.25 lightday
42 na...

output:

4.4394035029e-18
3.9735067985e+20

result:

ok 

Test #4:

score: -100
Wrong Answer
time: 5ms
memory: 4096kb

input:

100 10000
1 ooooooooooooooooolol = 913.613760987 ooooooooooooolooooll
1 oooooooooooooloollol = 626.088582061 ooooooooooooololooll
1 oooooooooooooolololo = 955.470952951 oooooooooooooloolooo
1 oooooooooooooooooool = 942.991120183 oooooooooooooooloolo
1 oooooooooooooooloooo = 537.689261619 ooooooooooo...

output:

inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
...

result:

wrong answer