Egor's blog

By Egor, 10 years ago, translation, In English

Hi!

I can't solve this зproblem. My code:


#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; int ans = 0; for (int i = 0; i < a; i++) ans++; for (int i = 0; i < b; i++) ans++; cout << ans << endl; return 0; }

Please help

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

| Write comment?
»
10 years ago, # |
Rev. 2   Vote: I like it +512 Vote: I do not like it

A simple 3D segment tree does the job.

»
10 years ago, # |
  Vote: I like it +30 Vote: I do not like it

change the ints to long long and it will pass i guarantee it !!! says this with thumbs up

»
10 years ago, # |
  Vote: I like it +91 Vote: I do not like it

Look, you are a newbie. This world of Codeforces is really very tough for newbies. Sorry to say that :(

Work hard. You will succeed here. Though it is gonna be tough. :P

»
10 years ago, # |
  Vote: I like it +151 Vote: I do not like it

I think you should read my new book: How to Get 2700+ Rating on Codeforces in 10 Days

»
10 years ago, # |
  Vote: I like it +39 Vote: I do not like it

You must read this :)

»
10 years ago, # |
Rev. 2   Vote: I like it +86 Vote: I do not like it

ugh newbies these days....

theres an easier way to do this


#include <weed> #include <alcohool> #include <nicky minaj> int mein(){ int tequila,vodka; int drunk==0; f>>tequila>>vodka; drunk=tequila-vodka; cout<<drunk<<'enld'; return 0; }
»
10 years ago, # |
Rev. 5   Vote: I like it +35 Vote: I do not like it

Egor it seems that you need to make training like cgy4ever
I expect you will be better in the near future I discovered a lot of guys but this time really I believe that you someday will be good and I'm sure you will be red.
anyway If you need any kind of help in any hard problems just tell me.
I will make training soon for some Beginners if you are interested you can join :P

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    I want to join to.
    Do you grantee to get a good result after 10 days?
    ;;)

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +5 Vote: I do not like it

    after training two days you become Green, Congrats

»
10 years ago, # |
  Vote: I like it +86 Vote: I do not like it

My solution also gives TLE, I think I should try memoization:

#include <iostream>
using namespace std;

int compute(int n){
    if(n<3) return n;
    return 2*compute(n-1) - compute(n-2);
}


int main() {
    int a,b;
    cin >> a >> b;
    cout << compute(a)+compute(b) << endl;
}
»
10 years ago, # |
  Vote: I like it +4 Vote: I do not like it

I like your sense of humor, Egor. It sure makes me laugh (although I am a poor newbie as well :P)

»
10 years ago, # |
Rev. 10   Vote: I like it +119 Vote: I do not like it

Indeed, it's a tough problem for your level. I think it can be solved by defining the addition operation through Lambda Calculus.

First, let's define Natural Numbers. Let's say that a number x is a function that given another function y and a variable z, applies y on z for x times.

0 ::== λx.λy.z
1 ::== λx.λy.x y
2 ::== λx.λy.x x y
...

So, let's define the addition operator. It would simply be:
add a b ::== a λx.λy.x b x y (Remember: a, b are natural numbers, so they are just functions.)

I'll leave the easy work of handling negative numbers, thinking about how to relate that to code, .. etc, to you as a kind of practice.

One last note: I really didn't try to learn these things, so I'm probably speaking nonsense. But a newbie like you wouldn't tell.

»
10 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I have this problem: http://www.spoj.com/problems/TEST

I'm thinking about an approach using Suffix Tree, Splay Tree, Dynamic convex hull, Max flow using pre-flow push with global heuristic. But I still don't have any good solution. Can anyone help me please :(

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Poor ! You could have done it with Heavy Light Decomposition. :p

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +8 Vote: I do not like it

      Uff these newbies are always irritating us international grandmaster ( I always wanted yo say this ) :D

      • »
        »
        »
        »
        10 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Y u so cocky!:)

        • »
          »
          »
          »
          »
          10 years ago, # ^ |
            Vote: I like it +8 Vote: I do not like it

          Performed poorly in last contest :( straight newbie from international grandmaster :(

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it +11 Vote: I do not like it

    Let IGM help you :)

     while(cin>>n){
    if(n==42)break;
    else cout<<n<<endl;
    }

    Magical suggestion: You need practice a lot of practice to apply these complicated things. Sometimes programming is tough, but don't lose heart and keep practicing :) Upsolving is important too.

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +21 Vote: I do not like it

      I submitted your code with out any changes but get compilation error. :|

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

It's so hard for you to solve this problem... :|

You should practice hard to do that... :|

»
10 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Once mathlover told me this problem can be solved by using network flow. I think the approach newbie mathlover told us can be understood easily by us poor newbies.

»
10 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Interesting... I really enjoy this problem but since I am only an expert, I am looking forward to opinions from these explosions of International Grandmasters, (I honestly don't know how).

Your code runs in linear time, with a constant factor of one. The constant factor however can be reduced to half with two simple base cases by doing the following:

int main() { int a, b; cin >> a >> b; int ans = 0; if (a == 1) { cout << b + 1 << endl; } else { cout << a + 1 << endl; } for (int i = 0; i < a; i += 2) ans += 2; for (int i = 0; i < b; i += 2) ans += 2; cout << ans << endl; return 0; }

»
10 years ago, # |
  Vote: I like it +18 Vote: I do not like it

It requires complex bit manipulation.
So, I think it might be too tough for your level. First work on easier problems and build your level up to this.
Anyway, here is my AC solution for your reference.

int add(int a, int b) {
    if (!b) return a;
    return add(a^b, (a&b) << 1);
}

int main() {
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

    int a, b;
    cin>>a>>b;
    cout<<add(a,b)<<"\n";

    clock_t endTime = clock();
    return 0;
}
»
10 years ago, # |
  Vote: I like it +45 Vote: I do not like it

Your solution is O(a+b) which is quite slow , you can use a technique similar to Exponentiation by squaring so it will become O(log(a)+log(b)), also it's better if you use fast input/output methods

here's the code

#include <iostream>
#include <stdio.h>
using namespace std;

int a,b,ans=0;

int main(){
    scanf("%d %d",&a,&b);
    int p=1;
    while(a>0){
        if(a%2){
            ans+=p;
        }
        a/=2;
        p*=2;
    }
    p=1;
    while(b>0){
        if(b%2){
            ans+=p;
        }
        b/=2;
        p*=2;
    }
    printf("%d\n",ans);
}
»
10 years ago, # |
  Vote: I like it +27 Vote: I do not like it

Your algorithm is O(a+b). You can easily make it O(min(a,b)). Here is how to do it:

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if(a>b) swap(a,b);
  int ans = b;
  for (int i = 0; i < a; i++) ans++;
  cout << ans << endl;
  return 0;
}

Also, you should use faster IO methods.

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it +13 Vote: I do not like it

    It's also provable that O(a+b) and O(min(a,b)) are both the same thing, but this requires some deep analysis. For the problem, it's a classic application of FFT. Maybe you may want to chose an easier problem to get you started.

»
10 years ago, # |
  Vote: I like it +10 Vote: I do not like it

Did you try to solve it for small a and b? It must be a pattern there, and then precalc does the matter.

»
10 years ago, # |
  Vote: I like it +12 Vote: I do not like it

The answer is trivial . 1- Swap a and b

2- find the largest a*b digit prime that can be expressed only by powers of 2 ;) eg 7 = 2^3 — 2^0

3- Now multiply that prime number by a|b

4- print a+b

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I have been searching for a solution to this problem for over a year.. And today I found a solution thanks to google. However it was too complicated and I couldnt prove it. Please help, heres the code:


#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << a+b << endl; return 0; }

What does this '+' magical symbol does?

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +28 Vote: I do not like it

    This code uses a special greedy algorithm that fails for large cases; In that case we must build complex data structure (the code is too long for me to post here) to fix it.

»
10 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

No no. You're wrong. You should solve it in a clear recursively way like this:

#include<iostream>
using namespace std;
typedef long long ll;
int sum(int x,int y)
{
    if (x==0)
       return y;
    else
       return sum(x-1,y)+1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    int a,b;
    cin >> a >> b;
    cout<< sum(a,b) <<endl;
    return 0;
}

Also be sure to use

ios_base::sync_with_stdio(0);

to not be time limit exceeded while getting the input. :)

*I suggest you first of all learn functions and then try to solve a+b problem. Because it needs recursive functions...

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    I getted compail errer with youre code.

      File "main.py", line 2
        using namespace std;
                      ^
    SyntaxError: invalid syntax
    

    Do youre code is rially collect? Pleeze fix me:)

    • »
      »
      »
      10 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Oh! Thanks for reminding me!

      Pay attention to this point:

      You should notice you can add two values recursively only with C++. In other languages, it is much more harder!

»
10 years ago, # |
Rev. 4   Vote: I like it +12 Vote: I do not like it

your code is too complicated to understand . as a newbie coder i suggest you to follow the way you actually do computation in mind . how do you add in mind ? obviously by memorizing the last state. so here is the best thing for newbies :D

#include<bits/stdc++.h>
using namespace std;
int mem[1000][1000];
int a,b;
int dp(int x,int y)
{
    if(x<0 || y<0) return 0;
    if(x==0) return y;
    if(y==0) return x;
    int &ret=mem[x][y];
    if(ret!=-1) return ret;
    ret=0;
    ret+=dp(x-1,y-1)+2;
    return ret;
}
int main()
{
    cin>>a>>b;
    memset(mem,-1,sizeof(mem));
    cout<<dp(a,b)<<endl;
    return 0;
}


»
10 years ago, # |
Rev. 3   Vote: I like it +15 Vote: I do not like it

Egor Lol :P

  • »
    »
    10 years ago, # ^ |
    Rev. 4   Vote: I like it 0 Vote: I do not like it

    del

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    congrats karan :D

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      lol ayush :P :P jokes apart,i have a lot to learn :)

      • »
        »
        »
        »
        10 years ago, # ^ |
          Vote: I like it -8 Vote: I do not like it

        You have the best rating I've ever seen(1001 !! That's great!!) Seriously, why do you want to be red??

      • »
        »
        »
        »
        10 years ago, # ^ |
          Vote: I like it +3 Vote: I do not like it

        I guess we have some misunderstandings here.
        I wasn't joking in my last comment... I LOVE palindromes and 1001 is the first non-obvious palindrome number! (Contains even number of digits and has at least two different digits.) From my point of view, it's one of the best ratings! :)

»
10 years ago, # |
Rev. 3   Vote: I like it +6 Vote: I do not like it

there is my code for this problem, it works for 1<=a,b <=1000

RGHOST

MEGA

i will try to type code solving for constraints up to 10000!

»
10 years ago, # |
  Vote: I like it +148 Vote: I do not like it

I think the hint is misleading, you shouldn't use '+'. This code gets AC and has no '+' at all:

#include <iostream>

int main() {
	long long a, b; 
	std::cin >> a >> b;
	
	for (int i = 10000 ; i ; i--) {
		long long x = 1LL << (rand() % 33);
		if (a & x) if (b & x) if (!(a & (2*x))) { a ^= x ; b ^= x ; a ^= 2 * x ; continue; }
		if (a & x) if (b & x) if (!(b & (2*x))) { a ^= x ; b ^= x ; b ^= 2 * x ; continue; }
		if (b & x) if (!(a & x)) { a |= x; b ^= x ; continue; } 
	}
	std::cout << a;
}

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +172 Vote: I do not like it
    #include <iostream>
    
    int main() {
    	long long a, b; 
    	std::cin >> a >> b;
    	std::cout << a - -b;
    }
    

    But yours much easier to understand

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You're asked to use the + operator. This is why I think the following link may be useful:

http://stackoverflow.com/a/19412942

You may need to make a few insignificant changes if this program wouldn't strictly conform to the required input specification.

»
10 years ago, # |
Rev. 2   Vote: I like it +116 Vote: I do not like it

I watched some lectures about randomized algorithms from Burunduk1 recently, and i tried his usual recipe — as everybody knows, it works for every problem...

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

int main(){

int a,b,res;

cin>>a>>b;
while (true)
{
 res=rand();
 if (res-b==a)
 {
  cout<<res<<endl;
  break;
 }
}

return 0;}
»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Same problem here

it took 2 hrs of coding but nothing at the end :(

I'll keep trying, I'll teach you if i got accepted

»
10 years ago, # |
Rev. 2   Vote: I like it +65 Vote: I do not like it

It is easy to guarantee constant time lookup:

#include <iostream>                                                           
int main()                                                                    
{                                                                             
  int a,b;                                                                    
  cin >> a >> b;                                                              
  if(a==0 && b==0){                                                           
    cout << 0 << endl;                                                        
  }                                                                           
  if(a==0 && b==1){                                                           
    cout << 1 << endl;                                                        
  }                                                                           
  if(a==0 && b==2){                                                           
    cout << 2 << endl;                                                        
  }                                                                           
  if(a==0 && b==3){                                                           
    cout << 3 << endl;                                                        
  }                                                                           
  if(a==0 && b==4){                                                           
    cout << 4 << endl;                                                        
  }                                                                           
  if(a==1 && b==0){                                                           
    cout << 1 << endl;                                                        
  }                                                                           
  if(a==1 && b==1){                                                           
    cout << 2 << endl;                                                        
  }                                                                           
  if(a==1 && b==2){                                                           
    cout << 3 << endl;
  }
  if(a==1 && b==3){                                                           
    cout << 4 << endl;                                                        
  }                                                                           
  if(a==1 && b==4){                                                           
    cout << 5 << endl;                                                        
  }                                                                           
  if(a==2 && b==0){                                                           
    cout << 2 << endl;                                                        
  }                                                                           
  if(a==2 && b==1){                                                           
    cout << 3 << endl;                                                        
  }                                                                           
  if(a==2 && b==2){                                                           
    cout << 4 << endl;                                                        
  }                                                                           
  if(a==2 && b==3){                                                           
    cout << 5 << endl;                                                        
  }                                                                           
  if(a==2 && b==4){                                                           
    cout << 6 << endl;                                                        
  }                                                                           
  if(a==3 && b==0){                                                           
    cout << 3 << endl;                                                        
  }                                                                           
  if(a==3 && b==1){                                                           
    cout << 4 << endl;                                                        
  }                                                                           
  if(a==3 && b==2){                                                           
    cout << 5 << endl;
  }                                                                           
  if(a==3 && b==3){                                                           
    cout << 6 << endl;                                                        
  }                                                                           
  if(a==3 && b==4){                                                           
    cout << 7 << endl;                                                        
  }                                                                           
  if(a==4 && b==0){                                                           
    cout << 4 << endl;                                                        
  }                                                                           
  if(a==4 && b==1){                                                           
    cout << 5 << endl;                                                        
  }                                                                           
  if(a==4 && b==2){                                                           
    cout << 6 << endl;                                                        
  }                                                                           
  if(a==4 && b==3){                                                           
    cout << 7 << endl;                                                        
  }                                                                           
  if(a==4 && b==4){                                                           
    cout << 8 << endl;                                                        
  }                                                                           
} 

I think you can easily see how to extend this :)

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    brilliant! In fact you can extend this to negative numbers by adding in a simple if statement! Still constant time lookup and constant memory! Best if all only logic operaters!

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    Calm down dude ... He's still a newbie ... ! you should explain more ... !

  • »
    »
    10 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hey VeniVidiVici, did you generate this code?? or simply you write it?? because it looks like a lot of implementation, and it is highly probably that red coders hack this solution, even when the test cases are hard to see...

  • »
    »
    10 years ago, # ^ |
    Rev. 2   Vote: I like it +5 Vote: I do not like it

    An IGM told me this is not O(1) but O(ab). However I'm a poor newbie and don't know why.

»
10 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

It seems you have chosen a very hard problem. You must try another problem easier than this... You are good enough this problem is so hard don't cry.

»
10 years ago, # |
Rev. 2   Vote: I like it +26 Vote: I do not like it

anyway, try to solve it before participating in TCO 2015 Final Round because it's a very important classic problem :D

»
10 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Wow this problem is quite impressive because I have seen in all online judge I have been. I don't know any aproach to attack this kind of problem, good luck Egor

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Change your rating back, maybe it's the problem.

»
10 years ago, # |
Rev. 2   Vote: I like it +25 Vote: I do not like it

After a day of thinking, I realized that this was a simple binary search exercise:

#include<iostream>

using namespace std;

int main() {
   int a, b;
   int ans;
   cin >> a >> b;
   int l = 0, r = 1 << 30;
   while (l + 1 < r) {
      int mid = (l + r - 1) / 2;
      if (mid == a + b) ans = mid;
      else if (mid < a + b) l = mid + 1;
      else r = mid + 1;
   }
}

Of course to be safe, at the end you can add a check to see if this is the right sum by doing if (ans == a + b) ... Oh wait a minute.

»
10 years ago, # |
Rev. 4   Vote: I like it +11 Vote: I do not like it

you could solve it with binary index trees in o(log(a+b))

#include<bits/stdc++.h>
#define ll long long unsigned int
using namespace std;
ll maxn=100000;
ll bt[100000];
void update(ll ind,ll v){
    while(ind<maxn){
        bt[ind]+=v;
        ind+=(ind&-ind);
    }
}
ll query(ll ind){
    ll ans=0;
    while(ind>0){
        ans+=bt[ind];
        ind-=(ind&-ind);
    }
    return ans;
}
int main(){
    ll a,b;
    cin>>a>>b;
    update(a,a);
    update(b,b);
    cout<<query(a+b);
}

»
10 years ago, # |
  Vote: I like it +58 Vote: I do not like it

finally accepted with this code. :D

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    great work the easiest solution I have ever seen :D

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Tears of joy in my eyes...The future of Earth is on your shoulders

»
10 years ago, # |
  Vote: I like it +20 Vote: I do not like it

I know all of you are alien machine of gods' from 57Ds outspace ,Gods wants all of you to maitain the society of 3Ds,not disturb the 3Ds world,just keep it,not doing crime!!!!!!

»
10 years ago, # |
  Vote: I like it +22 Vote: I do not like it

Congratulation for being Specialist from Newbie.
No doubt that, you have tried hard for this rating change. Try more. If you rightly do your work, sure, you will be able to solve this hard problem in 8 days. :P

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +78 Vote: I do not like it

    I bet he will become International Grandmaster after 10th of January

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it +6 Vote: I do not like it

      Ah yes, in that case he must read my book

    • »
      »
      »
      10 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      Yep... He is working hard. I'm sure he will continue this & he is gonna attend in Round 285 being International Grandmaster .
      Great inspiration for new coders !!!

    • »
      »
      »
      10 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      It turned out to be true... How did you know?

»
10 years ago, # |
  Vote: I like it -10 Vote: I do not like it

Finally I did it:

#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

int main()
{
    long long int first,second;
    char a[128],b[128],c[128];
    int asz,bsz,curr,t=0,i;
    scanf("%lld %lld", &first, &second);
    sprintf(a,"%lld",first);
    sprintf(b,"%lld",second);
    reverse(a,a+strlen(a));
    reverse(b,b+strlen(b));
    while(strlen(a)<strlen(b))
        strcat(a,"0");
    while(strlen(b)<strlen(a))
        strcat(b,"0");
    asz=bsz=strlen(b);
    for(i=0;i<asz;i++)
    {
        curr=t+a[i]-'0'+b[i]-'0';
        t=curr/10;
        curr%=10;
        c[i]=curr+'0';
    }
    if(t)
        c[asz]=t+'0';
    reverse(c,c+strlen(c));
    printf("%s\n",c);
    return 0;
}

»
10 years ago, # |
  Vote: I like it -10 Vote: I do not like it

Wow... You improved... You are specialist now...

  • »
    »
    10 years ago, # ^ |
      Vote: I like it -70 Vote: I do not like it

    try this one :

    include <bits/stdc++.h>

    typedef long long ll;

    define mp make_pair

    define pb push_back

    using namespace std; vector v; int ans=0; int main() { int a,b; cin>>a>>b; for(int i=0;i<a;i++) v.pb(1); for(int i=0;i<b;i++) v.pb(2); for(int i=0;i<v.size();i++) { if(v[i]==1) ans++; if(v[i]==2) ans++; } cout<<ans; return 0; }

»
10 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Egor, you must be enjoying this :D Plot twist: he can't solve the problem for real (:ok je sors:).

»
10 years ago, # |
  Vote: I like it -12 Vote: I do not like it

Now Egor is green! Did you solve this problem?

»
10 years ago, # |
  Vote: I like it +102 Vote: I do not like it

Hi Egor. I think your code is ok for nonnegative values, but it fails for negative ones!

»
10 years ago, # |
Rev. 2   Vote: I like it +56 Vote: I do not like it

ur problem looks very similar to this problem.
u should just submit the same solution 5 times, it will give u WA. when u submit 6th time, u will get AC! :)

»
10 years ago, # |
Rev. 5   Vote: I like it -14 Vote: I do not like it

.-. LOL very hard problem.

This is a very complex MST problem. It took me two days to reach the conclusion that I can do it like this: Nodes A and B are connected with a total weight of A+B This is my AC code:



#include <iostream> #include <algorithm> #include <vector> #include <tuple> using namespace std; int a,b; vector<tuple<int,int,int> >EdgeList; vector<int> pset(1000000); void initSet(int N) { for(int i=0;i<=N;i++) pset[i] = i; } int findSet(int i) {return (pset[i] == i) ? i : (pset[i]=findSet(pset[i])); } void unionSet(int i, int j) {pset[findSet(i)] = findSet(j); } int isSameSet(int i, int j) {return findSet(i) == findSet(j); } int main() { ios::sync_with_stdio(false);cin.tie(0); while(cin>>a>>b){ initSet(max(a,b)+1); EdgeList.clear(); EdgeList.push_back(make_tuple(a+b,a,b)); sort(EdgeList.begin(),EdgeList.end()); int mst=0; for(tuple<int,int,int> u:EdgeList){ int w,a,b; tie(w,a,b)=u; if(!isSameSet(a,b)){ unionSet(a,b); mst+=w; } } cout<<mst<<"\n"; } return 0; }
»
10 years ago, # |
  Vote: I like it +5 Vote: I do not like it

Congrats Egor, now you're "Expert" :)) I think you have solved this problem finally, have you? :D

»
10 years ago, # |
  Vote: I like it +79 Vote: I do not like it

Egor must be truly great rising star of competitive programming since he became blue from grey in such a short period of time! Even lack of contests wasn't an obstacle for him!

»
10 years ago, # |
  Vote: I like it -21 Vote: I do not like it

One thousand upvotes. Wow.

»
10 years ago, # |
  Vote: I like it +16 Vote: I do not like it
»
10 years ago, # |
  Vote: I like it +56 Vote: I do not like it

»
10 years ago, # |
  Vote: I like it +34 Vote: I do not like it

it prints the answer for x , y

printf("%d",printf("%*c%*c", x,'\r', y, '\r'));
  • »
    »
    10 years ago, # ^ |
      Vote: I like it -11 Vote: I do not like it

    include <bits/stdc++.h> typedef long long ll; define mp make_pair define pb push_back using namespace std; vector v; int ans=0; int main() { int a,b; cin>>a>>b; for(int i=0;i<a;i++) v.pb(1); for(int i=0;i<b;i++) v.pb(2); for(int i=0;i<v.size();i++) { if(v[i]==1) ans++; if(v[i]==2) ans++; } cout<<ans; return 0; }

»
10 years ago, # |
  Vote: I like it +3 Vote: I do not like it

It Seems like This post gonna be on Top till next Christmas :D

»
10 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Use ++i and ++ans.

»
10 years ago, # |
Rev. 3   Vote: I like it +9 Vote: I do not like it

Congratulation Egor !!!
You are in div 1 now !!! Wish you best luck.

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    He's improving too soon too fast ... ! :D

  • »
    »
    10 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    I was so confused! His rating is increasing without any contest!!!

»
10 years ago, # |
  Vote: I like it +23 Vote: I do not like it

you are Candidate master now.Now try once again.

»
10 years ago, # |
  Vote: I like it +11 Vote: I do not like it

International master ... ! way to go Egor ... ! :D

»
10 years ago, # |
  Vote: I like it -35 Vote: I do not like it

Why you posting a blog for vain Threads.:| you are crazy !

  • »
    »
    10 years ago, # ^ |
      Vote: I like it -45 Vote: I do not like it

    Я хочу поздравить всех пользователей интеллектуальной игры "Clash Of Clans" стем что вы нашли и играете лучшую игру в мире! Поздравляю

»
10 years ago, # |
Rev. 2   Vote: I like it -33 Vote: I do not like it

.

»
10 years ago, # |
  Vote: I like it -22 Vote: I do not like it

U BAD U BAD U BAD U BAD U BAD

here is the code: ;)

if you need any more help feel free to contact me ~~~~~

include

using namespace std; int main() { int a,b; cin>>a>>b; cout<<a+b; return 0; } ~~~~~

»
10 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The editorial is finally here, check it out.

»
9 years ago, # |
  Vote: I like it +113 Vote: I do not like it
#good_old_times
»
5 years ago, # |
Rev. 2   Vote: I like it -15 Vote: I do not like it

[deleted]