i have two problems with my code:
1. It's giving TLE
2. It's giving WA for a case..
2 6
kalopace 2 5
juqeh 1 1
xosufifu 4 5
xosufifu 5 6
kalopace 6 3
kalopace 1 5
the answer should be 5 problems found( The 6th paper is correctly checked i think ) but the answer given in the sample output is 6 problems found..can you please point out my mistake..
My code is:
#include <iostream>
using namespace std;
int a[1002][1002];
string str[1002];
int checkers(int i, int n)
{
int cnt = 0;
for(int j=1; j<=n; j++)
if(a[i][j] == 1 && i != j)
cnt++;
return cnt;
}
bool same_univ(int i, int n)
{
for(int j=1; j<n; j++) {
for(int k=j+1; k<=n; k++) {
if(str[j] == str[k] && (a[i][j] != 0 && a[i][k] != 0)) {
return true;
}
}
}
return false;
}
bool extra(int i, int n)
{
for(int j=1; j<=n; j++) {
if(a[i][j] > 1) {
return true;
}
}
return false;
}
int main()
{
int n, k;
cin >> k >> n;
while(k != 0 && n != 0) {
int paper;
int err=0;
for(int i=0; i<=n; i++)
for(int j=0; j<=n; j++)
a[i][j] = 0;
for(int i=1; i<=n; i++) {
cin >> str[i];
for(int j=1; j<=k; j++) {
cin >> paper;
a[paper][i]++;
}
}
//to print the paper v/s unversity matrix
/*
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
cout << a[i][j] << " ";
}
cout << endl;
}*/
for(int i=1; i<=n; i++) {
if(checkers(i,n) != k) {
err++;
}
else if(extra(i,n)) {
err++;
}
else if(a[i][i] == 1) {
err++;
}
else if(same_univ(i,n)) {
err++;
}
}
if(err == 0)
printf("NO PROBLEMS FOUND\n");
else
printf("%d PROBLEMS FOUND\n", err);
cin >> k >> n;
}
return 0;
}
Also if there is any other mistake can u please tell me... Thnx in advance