#include #include #include #include #include using namespace std; int root[100]; int getRoot(int v){ return root[v]==-1 ? v : root[v] = getRoot(root[v]); } class OneDimensionalBalls { public: long long countValidGuesses(vector firstPicture, vector secondPicture) { set S; int n = firstPicture.size(); int m = secondPicture.size(); long long res = 0; for(int i=0;i::iterator it=S.begin();it!=S.end();it++){ if((*it)==0) continue; memset(root, -1, sizeof(root)); for(int i=0;i0){ if(a+1==b) cnt *= b; if(a>b) cnt = 0; } } if(ok) res += cnt; } return res; } };