Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active August 29, 2015 14:04
Show Gist options
  • Save cocodrips/7f2ccfaa1fe6709444cb to your computer and use it in GitHub Desktop.
Save cocodrips/7f2ccfaa1fe6709444cb to your computer and use it in GitHub Desktop.
SRM620 Div1 Easy in C++ PairGame
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <tuple>
#include <sstream>
#include <typeinfo>
#include <fstream>
using namespace std;
class PairGame {
public:
vector<vector<int> > parts(int a, int b){
vector<vector<int> > sums(2000000);
sums[a+b] = {a,b};
while(a > 0 and b > 0){
if (a > b) {
a = a - b;
} else {
b = b - a;
}
sums[a+b] = {a,b};
}
return sums;
}
int maxSum(int a, int b, int c, int d) {
auto sumsA = parts(a, b);
auto sumsC = parts(c, d);
for (int i = sumsA.size() - 1; i >= 0; --i){
if (!sumsC[i].empty()){
if (sumsA[i] == sumsC[i]){
return i;
}
}
}
return -1;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment