Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

electro177's blog

By electro177, history, 6 days ago, In English

A big binary number

You are given a number n. Find the decimal value of the number that is formed by concatenating the binary representations of the first n positive

Integers. Print the answer modulo 10^9 +7.

Example

Consider N = 2:

The binary representation of 1 is 1.

• The binary representation of 2 is 10

. So the number form after concatenation is 110. in decimals this is equivalent to 6.

n<1e9;

Some help what to do

Read more »

 
 
 
 
  • Vote: I like it
  • +1
  • Vote: I do not like it

By electro177, history, 2 weeks ago, In English

hello friends

Is there any way or stl trick to convert vector to vector but there should'nt be any equal elements eg)

[[1,1,6],[1,2,5],[1,2,5],[1,7],[1,7],[2,6]]

to

[[1,1,6],[1,2,5],[1,7],[2,6]]

for vector there exist a std::unique but for this case what to do :)

Read more »

 
 
 
 
  • Vote: I like it
  • +3
  • Vote: I do not like it

By electro177, history, 3 weeks ago, In English

Using set implementation it is working.but using vector the code gives some mingw error which i cannot understand.can anyone know what to do in order to make it work in vectors

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

const int mxN = 2e5;
int n;
ar<int, 3> a[mxN];

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i][1] >> a[i][0] >> a[i][2];
  }
  sort(a, a + n);
  set<ar<ll, 2>> dp;
  dp.insert({0, 0});
  ll ldp = 0;
  for (int i = 0; i < n; ++i) {
    auto it = dp.lower_bound({a[i][1]});
    --it;
    ldp = max(ldp, (*it)[1] + a[i][2]);
    dp.insert({a[i][0], ldp});
  }
  cout << ldp;
}


#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN = 2e5; int n; ar<int, 3> a[mxN]; int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i][1] >> a[i][0] >> a[i][2]; } sort(a, a + n); vector<ar<ll, 2>> dp; dp.push_back({0, 0}); ll ldp = 0; for (int i = 0; i < n; ++i) { auto it = lower_bound(dp.begin(), dp.end(), a[i][1]) ; --it; ldp = max(ldp, (*it)[1] + a[i][2]); dp.push_back({a[i][0], ldp}); } cout << ldp; }

Read more »

 
 
 
 
  • Vote: I like it
  • -2
  • Vote: I do not like it

By electro177, history, 4 weeks ago, In English

Hello folks ,Could you share how to stop addicted from something which u are already addicted at,I feel many of you have diffrent techniques for it.please share .it will be useful for other coders out there as well

Read more »

 
 
 
 
  • Vote: I like it
  • -1
  • Vote: I do not like it

By electro177, history, 4 weeks ago, In English

const int mxN = 2e5; int n, d[mxN], ans; vector<int> adj[mxN]; void dfs(int u = 0, int p = -1) { for (int v : adj[u]) { if (v == p) continue; dfs(v, u); ans = max(d[u] + d[v] + 1, ans); d[u] = max(d[u], d[v] + 1); } }

ans gives the diameter of the tree .It is not that trivial to understand for me.can someone explain please explain how the code works

Read more »

 
 
 
 
  • Vote: I like it
  • -10
  • Vote: I do not like it

By electro177, history, 5 weeks ago, In English
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define ar array
 
const int mxa = 1e5 + 1;
ll a, b, c, n, m;
vector <ar<ll, 2>> adj[mxa];
ll dist[mxa];
 
 
 
int main() {
 
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b >> c; --a, --b;
    adj[a].push_back({c, b});
 
  }
 
  memset(dist, 0x3f, sizeof(dist));
 
  priority_queue< ar<ll, 2>  , vector<ar<ll, 2>>, greater<ar<ll, 2>> > pq;
  dist[0] = 0;
  pq.push({0, 0});
  while (pq.size()) {
 
    ar<ll, 2> node = pq.top();
    pq.pop();
 
    if (node[0] > dist[node[1]])continue;
 
    for ( ar<ll, 2> child : adj[node[1]]) {
 
      if (dist[child[1]] > node[0] + child[0]) {
        dist[child[1]] = node[0] + child[0];
        pq.push({dist[child[1]], child[1]});
      }
    }
 
  }
 
  for (int i = 0; i < n; i++) cout << dist[i] << " ";
 
}

I have implemented code for Dijstra ,but it finds only min distance of each node from source node. could anyone please help how to retace the shortest path in this approach .Thank you

Read more »

 
 
 
 
  • Vote: I like it
  • -21
  • Vote: I do not like it

By electro177, history, 5 weeks ago, In English
priority_queue<ar<ll, 2>, vector<ar<ll, 2>>, greater<ar<ll, 2>>> pq;
  pq.push({0, 0});
  memset(d, 0x3f, sizeof(d));
  d[0] = 0;
  while (pq.size()) {
    ar<ll, 2>    u = pq.top(); 
    pq.pop();
    
    if ( u [0]  > d[ u[1] ] ) // i have a doubt here
      continue;
    
    for (ar<ll, 2> v : adj[u[1]]) {

      if (d[v[1]] > u[0] + v[0]) {
        d[v[1]] = u[0] + v[0];
        pq.push({d[v[1]], v[1]});
      }


    }
  }

I do not understand why if ( u [0] > d[ u[1] ] ) continue; in the code .please give the reason ,is it related to connected component?

Read more »

 
 
 
 
  • Vote: I like it
  • -3
  • Vote: I do not like it

By electro177, history, 5 weeks ago, In English

while this is working fine ~~~~~ Your code here... bool emp (int i, int j) { if ( i >= 0 && i < n && j >= 0 && j < m && s[i][j] == '.' )return 1; else return 0;

} ~~~~~

this is giving run time error ~~~~~ Your code here...

bool emp (int i, int j) { if ( s[i][j] == '.' && i >= 0 && i < n && j >= 0 && j < m )return 1; else return 0;

} ~~~~~

does anyone know the reason

Read more »

 
 
 
 
  • Vote: I like it
  • -20
  • Vote: I do not like it

By electro177, history, 6 weeks ago, In English

I was doing problem towers.I sorted all the blocks according to weight + strength from exchange arguments and then now i did not get idea how to do transitions in dp ,but i saw some code and i thought i should do it by weights from 0 to total weight (but i do not know why) and the transition was

Your code here...

for (auto block : blocks) {
int w = block.w, s = block.s; ll v = block.v;
for (int i = w + s; i >= w; i--) 
dp[i] = max(dp[i], dp[i - w] + v);
}

Please help me how to take the dp state and also the transitions mainly(i did not understand after thinking a lot) Thank you

Read more »

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

By electro177, history, 7 weeks ago, In English

this template is not working in my sublime text

Your code here...
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template < class T, class = decay_t<decltype(*begin(declval<T>()))>,
           class = enable_if_t < !is_same<T, string>::value >>
ostream & operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = c.begin(); it != c.end(); ++it)
    os << &", "[2 * (it == c.begin())] << *it;
  return os << ']';
}
//support up to 5 args
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_0(_CALL, ...)
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(dummy, ##__VA_ARGS__, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1, _FE_0)     \
  (MACRO, ##__VA_ARGS__)
//Change output format here
#define out(x) #x " = " << x << "; "
#define dbg(...)                                                              \
  cerr << "Line " << __LINE__ << ": " FOR_EACH_MACRO(out, __VA_ARGS__) << "\n"

` ~~~ ~~~~~

`

I think it is because i may be using older c++ compiler,i do not know how to upgrade to c++ 17,please help

but this is working

Your code here..

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

Read more »

 
 
 
 
  • Vote: I like it
  • -16
  • Vote: I do not like it

By electro177, history, 7 weeks ago, In English

I have beem trying this for 2 days but i could not get idea nor understand solutions,could someone please explain it clearly ,i need your help (https://atcoder.jp/contests/dp/tasks/dp_o) someone help please:)

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By electro177, history, 2 months ago, In English

Please help me with run time error, this is the cses book shop problem

with all type int ,it is accepted ,while with all long long it gives run time error,I thought of always using long long because it is helpful, can u please say when to not use long long

( run time error)//////

include<bits/stdc++.h>

include

using namespace std;

define rep(i,x,y) for(ll i=x; i<=y; i++)

define ll long long

void task() { ll n,target; cin >> n >> target; vector price(n), pages(n); for (ll&v : price) cin >> v; for (ll&v : pages) cin >> v;

vector<vector> dp(n + 1, vector(target + 1, 0));

// dp[0][0] = 0;

rep(i, 1, n) { rep(j, 0, target) {

dp[i][j] = dp[i - 1][j];
  int left = j - price[i - 1];
  if (left >= 0)
    dp[i][j] = max(dp[i][j] ,  dp[i - 1][j - price[i - 1]] + pages[i - 1] );

}

}

cout << dp[n][target] << '\n'; }

int main() { int case = 1 ;

for (int i = 0; i < case; i++) task(); }

(accepted)//////

include<bits/stdc++.h>

include

using namespace std;

define rep(i,x,y) for(int i=x; i<=y; i++)

define ll long long

void task() { int n, target; cin >> n >> target; vector price(n), pages(n); for (int&v : price) cin >> v; for (int&v : pages) cin >> v;

vector<vector> dp(n + 1, vector(target + 1, 0));

// dp[0][0] = 0;

rep(i, 1, n) { rep(j, 0, target) {

dp[i][j] = dp[i - 1][j];
  int left = j - price[i - 1];
  if (left >= 0)
    dp[i][j] = max(dp[i][j] ,  dp[i - 1][j - price[i - 1]] + pages[i - 1] );

}

}

cout << dp[n][target] << '\n'; }

int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int case = 1 ; for (int i = 0; i < case; i++) task(); }

Read more »

 
 
 
 
  • Vote: I like it
  • -7
  • Vote: I do not like it

By electro177, history, 2 months ago, In English

I thought about it for a long time and i am cleearly commenting the code to help understand it easily

i cannot code it here properly for some reason ,so check my submission

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

By electro177, history, 3 months ago, In English

Hello codeforces community ,many of you here are motivated and working towards your goals which is great ,but not all .I am distracted by something or the other .I am addicted to some shitty websites like omegle and some other .But I want to be a good guy and a good coder ,what are the best personal experience of defeating any addiction .please help me and some others like me .addictions can be too dangerous :( . I have already tried to focus many times but could not able to do that. that's why i am asking your help. it can be soo silly but this is most serious issue.

Read more »

 
 
 
 
  • Vote: I like it
  • -19
  • Vote: I do not like it

By electro177, history, 3 months ago, In English

Hello codeforces, I am currently practicing dp and not getting questions contiously. I am feeling like not doing anything. How to be motivated while doing cp, I don't have any cp friend also. I think this will affect life in general

Read more »

 
 
 
 
  • Vote: I like it
  • +16
  • Vote: I do not like it

By electro177, history, 3 months ago, In English

omegle website is the place to meet new boys and girls (i got a gf from there ).And it acts as entertainment .you can show ur cp skills(logical) there too.it is the best website other than codeforces i ever saw.what do u think .if u did not try it yet google omegle.com

Read more »

 
 
 
 
  • Vote: I like it
  • -35
  • Vote: I do not like it

By electro177, history, 7 months ago, In English

This award goes to tourist because of the insane hard work and genius . You can refer (https://youtu.be/nfAnKzyiKTo) Salute to your work man.

Read more »

 
 
 
 
  • Vote: I like it
  • -44
  • Vote: I do not like it

By electro177, history, 7 months ago, In English

We are all getting older day by day. We are loosing our childhood so easily. I cannot understand how life works. Any ideas? What is your ultimate goal in your life?

Read more »

 
 
 
 
  • Vote: I like it
  • +57
  • Vote: I do not like it