Hi Ben!

Consider the case where size=10 and target=12. Your code will never find 
the diagonal consisting of 2 2's and 8 1's. I think there is a 
misunderstanding. Check out the analysis posted with the problem statement:
https://codingcompetitions.withgoogle.com/codejam/round/000000000019fd27/0000000000209aa0
specifically with regards to Test Set 2. It sheds some light on possible 
diagonals, how to achieve them, and how to then fill the rest of the square.

Best,
Matt

On Monday, April 13, 2020 at 12:10:42 PM UTC-4, Ben Long wrote:
>
> 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/70562403-b522-48f9-a38b-f6e7ba48f453%40googlegroups.com.

Reply via email to