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

Автор Egor, 9 лет назад, По-русски

Привет!

Не получается решить эту задачу. Вот мой код:


#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; }

Помогите

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

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

Подсказка
Используйте +

Ну явно мало плюсов в коде.

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

    Аж 8, куда же больше?

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

      Ой, я отправил, а оно прошло. Наверное, админ тимуса после этого поста нашёл баг и исправил его.

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

A simple 3D segment tree does the job.

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

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

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

Серые да зелёные повылазили...

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

    А я почему-то верю в автора. Нутром чую — у него большое будущее.

    Вспомните потом мои слова — не пройдет и двух недель, как он станет красным.

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

      Хм, а предсказание-то постепенно сбывается. Еще недавно он был серым, а сейчас уже синий...

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

        фиолетовый! Хотя я не помню ни одного контеста за эти дни. И когда он качаться успевает? Сразу видно — талант!

        UPD: уже оранжевый! И что удивительно — опять не было ни одного контеста.

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

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

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

Надо через динамику по маскам решать, там намного проще! в крайнем случае — декартка

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

Капитан Очевидность сообщает, что нужно отправлять не exeшник, а cppшник

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

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

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

You must read this :)

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

You must read this :)

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

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; }
»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Так версия Java не та, это же 7, а ты наверно под 8 сабмитил

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

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

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

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;
}
»
9 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

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

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

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.

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

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 :(

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

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

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

    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.

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

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

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

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

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.

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

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; }

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

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;
}
»
9 лет назад, # |
  Проголосовать: нравится +45 Проголосовать: не нравится

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);
}
»
9 лет назад, # |
  Проголосовать: нравится +27 Проголосовать: не нравится

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.

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

    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.

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

Я так и не решил :( мой профиль

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

Используй какой-нибудь компилятор C++, под паскалем работать не будет.

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

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

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

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

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

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?

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

    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.

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

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...

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

    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:)

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

      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!

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

Ничего эти серые не умеют.

Не "Не могу решить задачу", а "Нимагу ришит зодачю", не "Помогите" а "Памагити". Код тоже не надо писать — нужно требовать, чтобы его кто-нибудь вместо тебя написал.

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

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;
}


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

Egor Lol :P

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

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!

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

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;
}

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +172 Проголосовать: не нравится
    #include <iostream>
    
    int main() {
    	long long a, b; 
    	std::cin >> a >> b;
    	std::cout << a - -b;
    }
    

    But yours much easier to understand

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

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.

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

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;}
»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

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

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 :)

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

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.

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

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

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

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

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

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

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

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

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

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.

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

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);
}

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

finally accepted with this code. :D

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

Можно немного ускорить с помощью meet-in-the-meedle:


#include <iostream> #include <algorithm> #include <vector> using namespace std; int main () { int a, b; cin >> a >> b; vector <int> v; for (int i = 0; i <= a; ++i) v.push_back (i); for (int j = 0; j <= b; ++j) { int l = lower_bound (v.begin (), v.end (), a + b - j) - v.begin (); if (v[l] + j == a + b) { cout << v[l] + j; return 0; } } }
»
9 лет назад, # |
  Проголосовать: нравится +20 Проголосовать: не нравится

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!!!!!!

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

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

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

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;
}

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

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

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

    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; }

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

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

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

Now Egor is green! Did you solve this problem?

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

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

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

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! :)

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

.-. 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; }
»
9 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

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

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

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!

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

One thousand upvotes. Wow.

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

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

it prints the answer for x , y

printf("%d",printf("%*c%*c", x,'\r', y, '\r'));
  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится -11 Проголосовать: не нравится

    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; }

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

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

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

Use ++i and ++ans.

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

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

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

you are Candidate master now.Now try once again.

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

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

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

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

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

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

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

.

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

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; } ~~~~~

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

The editorial is finally here, check it out.

»
8 лет назад, # |
  Проголосовать: нравится +113 Проголосовать: не нравится
#good_old_times
»
8 лет назад, # |
  Проголосовать: нравится -29 Проголосовать: не нравится

Попробуй закодить в блокноте! Я так закодил и получилось!

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

[deleted]