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

Автор abba5, история, 4 года назад, По-английски

I was trying to submit this -> Remove Max Number of Edges to Keep Graph Fully Traversable question.
but I got TLE because of sort using rbegin

sort( edges.rbegin(), edges.rend())

but after change with comparator funtction code got accepted.

sort(edges.begin(), edges.end(), [&](vector <int> &a, vector <int> &b){
            return a[0] > b[0];
        });

Submission Using rbegin

Submission Using comparator

I tried to run this in local and got similar performance but when I used some different build command I got 2x time difference for $$$N = 10^5$$$

Build command:

  1. g++ a.cpp

  2. g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -DLOCAL a.cpp

output using 1st build command:

0.0290290006s
0.0652360022s

output using 2nd build command:

0.9816750288s
2.1033749580s

Following code I used for bench-marking.

Bench-marking code

Can anyone explain why this time difference happening?
Will this happen in code-forces also?

Полный текст и комментарии »

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

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

there is $$$N$$$ number of cites in one dimension. the location of the city is $$$a_{i}$$$ you have to place $$$k$$$ ATM such that the sum of all the cities to its nearest ATM distance is minimum.

I don't remember constraints but it was not big.

the question was asked in Honeywell Hiring Challange(closed).

Brute Force solution

$$$N = 3$$$

$$$A = [1, 2, 3]$$$

$$$K = 1$$$

$$$ans = 2$$$

Thanks in Advance!

Полный текст и комментарии »

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

Автор abba5, история, 6 лет назад, По-английски
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится