Hi All,

I thought I had a pretty strong understanding of the Indicium problem, and 
the possible solutions. It is my understanding that in order for you to not 
repeat values across the diagonal the values have to be either all the same 
like:
3 2 1
1 3 2
2 1 3

or they must be a different value from 1 - N where N is the size of the 
matrix like:
3 1 2
1 2 3
2 3 1

Is my understanding wrong? I could not think of a case where you can have a 
possible solution if you don't adhere to one of the above formats. My code 
is pasted below if anyone wants to review that for an issue, but in my 
testing my code worked. However, I received a grade of Wrong Answer during 
competition.

Thank you in advance for any responses. 

// GoogleCodeJam2020QualificationIndicium.cpp : This file contains the 
'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
int main()
{
    /*ifstream cin;
    ofstream cout;
    cout.open("output.txt");
    cin.open("input.txt");*/
    int testCases{};
    int test = 1;
    cin >> testCases;
    while (test <= testCases) {
        int size, target;
        bool possible = false;
        cin >> size >> target;
        //check factorial;
        int temp = size;
        int sum = 0;
        if (size > 2) {
            while (temp > 0) {
                sum += temp;
                temp--;
            }
        }
        if ( sum == target) {
            cout << "Case #" << test << ": " << "POSSIBLE" << "\n";
            for (int i = 0; i < size; i++) {
                int start = size - i;
                for (int j = 0; j < size; j++) {
                    cout << start << " ";
                    start--;
                    if (start == 0) {
                        start = size;
                    }
                }
                cout << "\n";
            }
            possible = true;
        }
        else {
            //check each term multiplied by the size;
            temp = size;
            while (temp > 0) {
                if (temp * size == target) {
                    possible = true;
                    cout << "Case #" << test << ": " << "POSSIBLE" << "\n";
                    for (int i = 0; i < size; i++) {
                        for (int j = 0; j < size; j++) {
                            cout << temp << " ";
                            if (j != size - 1) {
                                temp--;
                            }
                            if (temp == 0) {
                                temp = size;
                            }
                            
                        }
                        cout << "\n";
                    }
                    break;
                }
                temp--;
            }
        }
        if (!possible) {
            cout << "Case #" << test << ": " << "IMPOSSIBLE" << "\n";
        }
        
        test++;
    }
    //cin.close();
    //cout.close();
}

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/ead606d3-ce4b-4939-870d-859f0062932f%40googlegroups.com.

Reply via email to