Finally I was able to get my code to work.

I am pasting the code.

Two changes I made :

1. I removed the cin.sync();
2. I added cin.ignore() before the for loop for reading the matrix (using 
getline())
    Required because the newline after the reading of C and N was being 
treated as a single line.

--------------------------------
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <ios>
#include <limits>

using namespace std;

int main() {
  int C;
  cin >> C;
  for (int caseno = 1; caseno <= C; caseno++) {
    int N; cin >> N;
    int tracesum=0;   
    string numbers;
    int intnumbers;
    
    vector<bool> rowsrepeat;
    vector<bool> colsrepeat;
    vector<bool> arrelementrowcount1;
    vector <vector<bool> > arrelementrowcount2;
    vector<bool> arrelementcolcount1;
    vector <vector<bool> > arrelementcolcount2;
    int rowsrepeatnum=0;
    int colsrepeatnum=0;
    for (int i=0; i<N; i++) {
      rowsrepeat.push_back(false);
      colsrepeat.push_back(false);
    }

    for (int i=0; i<=N; i++) { 
      arrelementrowcount1.push_back(false);
    }
    for (int i=0; i<N; i++) {  
      arrelementrowcount2.push_back(arrelementrowcount1);
    }

    for (int i=0; i<=N; i++) { 
      arrelementcolcount1.push_back(false);
    }
    for (int i=0; i<N; i++) {  
      arrelementcolcount2.push_back(arrelementcolcount1);
    }

    vector<int>  arrinput1;
    vector <vector<int> >  arrinput2;

    cin.ignore();
    for (int i=0; i<N; i++) {        
        arrinput1.clear();

        getline(cin, numbers);
        istringstream ss(numbers);    

        while (ss >> intnumbers) {
          arrinput1.push_back(intnumbers);          
        }  
        arrinput2.push_back(arrinput1);
    }         
    int i=0;int j=0;    
    for (auto it1 = arrinput2.begin(); it1 != arrinput2.end(); it1++) {
      j=0;
      for (auto it2 = (*it1).begin(); it2 != (*it1).end(); it2++ ) {    
      int in = *it2;
        if (arrelementrowcount2[i][in]) {          
          rowsrepeat[i] = true;          
        }
        arrelementrowcount2[i][in] = true;
        if (arrelementcolcount2[j][in]) {          
          colsrepeat[j] = true;          
        }
        arrelementcolcount2[j][in] = true;
        if (i==j) {
          tracesum = tracesum + in;                
        }
        j++;      
        
      }
     i++; 
     
    }              
    
    for (int i=0; i<N; i++) {
      if (rowsrepeat[i]) rowsrepeatnum++; 
      if (colsrepeat[i]) colsrepeatnum++;       
    }
      
      cout << "Case #" << caseno << ":" << " " << tracesum << " " << 
rowsrepeatnum << " " << colsrepeatnum << endl;        
} 
}
--------------------

Thanks

Saimohan Kuncham

On Wednesday, April 8, 2020 at 9:22:25 PM UTC+5:30, Saimohan Kuncham wrote:
>
> When I run my code locally using MinGW compiler I am getting the right 
> answers. 
>
> I have tried the sample testcases given in the problem and they also give 
> the correct results when run locally. On the Code jam environment I am 
> getting wrong results both in test (where I manually enter the inputs)and 
> attempt when I run the program. 
>
> My program which compiles and runs without any errors should work at least 
> for the Sample testcases. What could be the problem ?
>
> Is there any specific name for the cpp file which I have to upload ? I 
> tried renaming to Solution.cc and then upload it but it did not help.
>
> Any help will be appreciated.
>
> Thanks
> Saimohan Kuncham
>

-- 
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/ca9c7047-c0ef-4add-afe7-8aa5b69e5360%40googlegroups.com.

Reply via email to