QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397616#5133. Imperfect Imperial Unitsucup-team1001#WA 25ms4484kbC++232.0kb2024-04-24 14:55:402024-04-24 14:55:41

Judging History

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

  • [2024-04-24 14:55:41]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:4484kb
  • [2024-04-24 14:55:40]
  • 提交

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<long double>> dis(2 * n + 2, vector<long double>(2 * n + 2, -1));
    map<string, int> ma;
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        long 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 i = 1; i <= cnt; i++)
        dis[i][i] = 1;
    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--) {
        long double x;
        string s1, s2;
        cin >> x;
        cin >> s1 >> s2;
        cin >> s2;
        if(dis[ma[s1]][ma[s2]] == -1) {
            cout << "impossible" << endl;
        }
        else {
            cout << setprecision(40) << x * dis[ma[s1]][ma[s2]]  << endl;
        }
    }
}

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: 1ms
memory: 3764kb

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.7499999999999999999457898913757247782996
1512
impossible

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3812kb

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.246406570840008498635143041610718
1.304464285714285713785179072519786712403e-05
0.2242857142857142856552741388975746872347

result:

ok 

Test #3:

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

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.439403502903200959400885367301800808019e-18
397350679848377132000

result:

ok 

Test #4:

score: -100
Wrong Answer
time: 25ms
memory: 4484kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer