QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#216485#5133. Imperfect Imperial UnitsMovingUp#WA 443ms4076kbC++20878b2023-10-15 19:01:142023-10-15 19:01:14

Judging History

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

  • [2023-10-15 19:01:14]
  • 评测
  • 测评结果:WA
  • 用时:443ms
  • 内存:4076kb
  • [2023-10-15 19:01:14]
  • 提交

answer

#include <iostream>
#include <map>
#include <vector>

using namespace std;

map<string, vector<pair<string, long double>>> g;
map<string, long double> dist;

void dfs(string curr, long double d) {
  dist[curr] = d;

  for (auto [u, x] : g[curr]) {
    if (dist.find(u) == dist.end()) {
      dfs(u, d * x);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, q;
  cin >> n >> q;

  for (int i = 0; i < n; i++) {
    long double a, tmp1;
    string u, v, tmp2;
    cin >> tmp1 >> u >> tmp2 >> a >> v;

    g[u].push_back({v, (long double)a});
    g[v].push_back({u, 1.0 / a});
  }

  for (int i = 0; i < q; i++) {
    long double a;
    string u, tmp, v;
    cin >> a >> u >> tmp >> v;

    dist.clear();
    dfs(u, a);

    if (dist.find(v) != dist.end())
      cout << dist[v] << endl;
    else
      cout << "impossible" << endl;
  }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3944kb

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

result:

ok 

Test #2:

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

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.50924e+06
1.30446e-05
0.224286

result:

ok 

Test #3:

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

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.4394e-18
3.97351e+20

result:

ok 

Test #4:

score: -100
Wrong Answer
time: 443ms
memory: 3988kb

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:

7.54057e+09
7.48033e-12
6.21273
107.447
537.477
4.80843e-07
2.50069
4.35548e+07
436.991
1.6359e+10
6.08918e-06
70214.2
2.96239
0.0192656
2.91425e+12
5.20322e+06
15634.5
55.3631
1.03915e+08
9.51114e+08
3.6751e+06
110054
0.216159
17377.7
115253
119783
0.312768
1.82553e+10
4.18295e-08
27.6886
4244.27
9...

result:

wrong answer