I am able to get all the answers for the sample inputs given in the problem. But still I get “Wrong answer”.
my problem code is :: CHEFKEY and my answer code is below .
/*
----- Kiamottullah -----
(20/ 10/ 2016)
All code is written by me .
You can allways use this code for
Learning context . keep learning
*/
#include
#include
using namespace std;
class Pair{
private :
long long int X;
long long int Y;
public :
Pair(int x, int y){
X = x;
Y = y; // constructor
}
// prototypes of this class
int getX (){
return X;
}
int getY (){
return Y;
}
void show (){
cout << getX() << " " << getY() << endl;
}
};
class Testcase{
private :
int N; // height
int M; // width
long long int C; // number of colours
vector <Pair> Pairs; // it's pairs
public :
Testcase (int n, int m, int c){
N = n;
M = m; // constructor
C = c;
calculatePairs();
}
// prototypes of this class
int getN (){
return N;
}
int getM (){
return M;
}
int getC (){
return C;
}
void calculatePairs (){
// is all color (C) fit in (n*m) display
if((N * M) >= C){
// firstly push two pairs (1, C) and (C, 1)
int x = 1, y = C;
if(isFit(x, y)){
Pairs.push_back(Pair(x, y));
}
x = C, y = 1;
if(isFit(x, y)){
Pairs.push_back(Pair(x, y));
}
// checking all the pairs from 2 to C/2
int hulf = C/2;
for(int i = 2; i <= hulf; i++){
for(int j = 2; j <= C/i; j++){
if(isPair(i, j)){
if(isFit(i, j)){
Pairs.push_back(Pair(i, j));
}
}
}
}
}else {
// so if all color can't drawble
// Pair size will be 0
}
}
void showPairs (){
int s = Pairs.size(); // this function show all the Pairs
for(int i = 0;i < s; i++){ // of C ... one by one
Pairs[i].show();
}
}
bool isFit (int x, int y){
if(((x <= N) && (y <= M))){
return true; // this function check whether
}else { // A pair (rect) fit into display (n*m)
return false;
}
}
int getPairsLength (){
return Pairs.size(); // this function return the number of
} // Pairs in Pairs vector .
bool isPair (int x, int y){
if ((x * y) == C){ // this function return true if (x*y) == C
return true; // else return false that's it ((x*y) != C)
}else {
return false;
}
}
};
int main() {
// number of test case;
int T;
// get input of number of test case
cin >> T;
// make an vector of size T;
vector <Testcase> cases;
for(int i = 0; i < T; i++){ // while (i < T) take input of
int n, m, c; // (n, m, c) for each testcase
cin >> n >> m >> c; // then push them in `cases`
cases.push_back(Testcase(n, m, c)); // vector
}
for(int i = 0; i < cases.size(); i++){ // for each testcase `tc`
Testcase tc = cases[i]; // cout the length of Pairs
cout << tc.getPairsLength() << endl;
}
return 0;
}