LeetCode Weekly Contest 182 3問目 - Design Underground System [1396]

Source

LeetCode Weekly Contest 182
問題文

問題概要

省略

解法

省略

cLayversion 20200325-1)のコード

C++に変換後のコードはこちら

#define main dummy_main
{}
#undef main

class UndergroundSystem {
public:
  int sn;
  map<string,int> sID;
  map<int,int> p2s, p2t;
  map<pair<int,int>,double> tm, tot;

  UndergroundSystem() {
    sn = 0;
  }

  int stationID(string stationName){
    if(sID.count(stationName)) return sID[stationName];
    return sID[stationName] = sn++;
  }

  void checkIn(int id, string stationName, int t) {
    p2s[id] = stationID(stationName);
    p2t[id] = t;
  }

  void checkOut(int id, string stationName, int t) {
    int x = p2s[id];
    int y = stationID(stationName);
    tm[make_pair(x,y)] += 1;
    tot[make_pair(x,y)] += t - p2t[id];
  }

  double getAverageTime(string startStation, string endStation) {
    int x = stationID(startStation);
    int y = stationID(endStation);
    return tot[make_pair(x,y)] / tm[make_pair(x,y)];
  }
};

Current time: 2024年04月26日07時54分16秒
Last modified: 2020年03月30日02時54分39秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る

Logged in as: unknown user (not login)

ログイン: