Блог пользователя bluemmb

Автор bluemmb, история, 9 лет назад, По-английски

Hi , obviously this problem can be solved in O(N*M) with help of an array for counting, because numbers are <=1000 . but what is the best algorithm for solving this problem when numbers are <=1e9 ?

I wrote this code that works in O( N*M*log(N*M) ) but it got TimeLimit ( in 1second ) . How can we reduce this complexity ?

UPD : sorry , I linked to wrong source code. fixed.

  • Проголосовать: нравится
  • +5
  • Проголосовать: не нравится

»
9 лет назад, # |
Rev. 2   Проголосовать: нравится +3 Проголосовать: не нравится

The first thing I came up with was a combination of unordered_map and set, which should have fit into the time limit, but somehow it didn't. So I tried a few things, some got MLE and others TLE again.

What I ended up with is a code combining lists of people for each chat count, along with a variable storing the minimum chat count that gets updated dynamically and an unordered_map for keeping count of chats for each person. It's rather messy, but it worked (393 ms).

Here's the code: C++11 Code

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by bluemmb (previous revision, new revision, compare).