Tuesday, July 15, 2014

Codechef July 2014 Long Contest - RETPO - reach the point solution

Codechef July 2014 Long Contest - RETPO - reach the point: http://www.codechef.com/JULY14/problems/RETPO

Codechef July 2014 Long Contest - RETPO - reach the point editorial: http://discuss.codechef.com/questions/47238/retpo-editorial

Codechef July 2014 Long Contest - RETPO - reach the point solution: http://ideone.com/gu1gDi


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main() {
    int t, x, y;
    long long cnt;
    scanf("%d", &t);
    while(t--) {
        cnt=0;
        scanf("%d%d", &x, &y);
        x=abs(x), y=abs(y);
        while(x>0 && y>0) {
            cnt+=min(x, y), cnt<<=1;
            if(x<y) y-=x, x=0;
            else x-=y, y=0;
        }
        if(x==0 && y>0) {
            if(y%2==0) y<<=1;
            else y<<=1, y--;
            cnt+=y;
        }
        else if(y==0 && x>0) {
            if(x%2==0) x<<=1;
            else x<<=1, x++;
            cnt+=x;
        }
        printf("%lld\n", cnt);
    }
    return 0;
}


No comments:

Post a Comment