QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#397607 | #5133. Imperfect Imperial Units | ucup-team1001# | WA | 16ms | 4260kb | C++23 | 1.9kb | 2024-04-24 14:26:35 | 2024-04-24 14:26:35 |
Judging History
answer
/*
Author: Haze
2024/4/24
*/
#include <bits/stdc++.h>
#define irep(i, l, r) for(int i = (l); i <= (r); ++ i)
#define drep(i, r, l) for(int i = (r); i >= (l); -- i)
#define IOS ios::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
typedef long long ll;
inline ll read() {
ll s = 0;
bool fl = false;
char ch = (char) getchar();
while (!isdigit(ch)) {
if (ch == '-')fl = true;
ch = (char) getchar();
}
while (isdigit(ch)) {
s = s * 10 + (ch ^ 48);
ch = (char) getchar();
}
return fl ? -s : s;
}
const int mod = 1000000000 + 7;
const int itinf = 1000000999;
const ll llinf = 2e18;
const int N = 500099;
void solve() {
int n, q;
cin >> n >> q;
vector<vector<double>> dis(2 * n + 1, vector<double>(2 * n + 2, -1));
map<string, int> ma;
int cnt = 0;
for(int i = 0; i < n; i++) {
double x, y;
string s1, s2;
cin >> x >> s1;
cin >> s2;
cin >> y >> s2;
if(!ma[s1]) {
ma[s1] = ++ cnt;
}
if(!ma[s2]) {
ma[s2] = ++ cnt;
}
dis[ma[s1]][ma[s2]] = y / x;
dis[ma[s2]][ma[s1]] = x / y;
}
for(int k = 1; k <= cnt; k++)
for(int i = 1; i <= cnt; i++) {
for(int j = 1; j <= cnt; j++) {
if(dis[i][k] == -1 || dis[k][j] == -1)
continue;
else
dis[i][j] = dis[i][k] * dis[k][j];
}
}
while(q--) {
double x;
string s1, s2;
cin >> x;
cin >> s1 >> s2;
cin >> s2;
if(dis[ma[s1]][ma[s2]] == -1) {
cout << "impossible" << endl;
}
else {
printf("%.7f\n", x * dis[ma[s1]][ma[s2]]);
}
}
}
int main() {
//IOS
int T = 1;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3928kb
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:
0.7500000 1512.0000000 impossible
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3808kb
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:
8509240.2464066 0.0000130 0.2242857
result:
ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3964kb
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:
0.0000000 397350679848393637888.0000000
result:
ok
Test #4:
score: -100
Wrong Answer
time: 16ms
memory: 4260kb
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