QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397610#5133. Imperfect Imperial Unitsucup-team1001#WA 1ms3812kbC++232.0kb2024-04-24 14:30:492024-04-24 14:30:49

Judging History

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

  • [2024-04-24 14:30:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3812kb
  • [2024-04-24 14:30:49]
  • 提交

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 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--) {
        double x;
        string s1, s2;
        cin >> x;
        cin >> s1 >> s2;
        cin >> s2;
        cout << s2 << endl;
        if(dis[ma[s1]][ma[s2]] == -1) {
            cout << "impossible" << endl;
        }
        else {
            printf("%.9f\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: 0
Wrong Answer
time: 1ms
memory: 3812kb

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:

meter
0.750000000
inch
1512.000000000
foot
impossible

result:

wrong answer