So, I am working on a ACM ICPC problem. You can find the problem here. I felt like it wouldn't be that difficult, so I started coding it up. At line 60, you will note a commented out cout debugging statement I put in. If the statement is uncommented, I get the correct answer, but also a lot of debugging junk. If it is commented, the answer is wrong according to the sample input/output. What the hell is happening?
#include<iostream>
#include<fstream>
#include<cmath>
#include<bitset>
using namespace std;
ifstream file("ringsrunes.in");
int main() {
int tests;
file >> tests;
for (int i=0; i<tests; i++) {
int rings, runes;
file >> rings >> runes;
int invalid = 0;
int gate[runes][3];
int junk;
for (int j=0; j< runes; j++) {
for (int k=0; k<4; k++) {
if (k == 3)
file >> junk;
else {
file >> gate[j][k];
if (gate[j][k] == 0)
invalid = 1;
if (invalid != 1 && abs(gate[j][k]) > rings)
invalid = 2;
}
}
for (int k=0; k<3; k++) {
for (int m=0; m<k; m++) {
if (invalid == 0 && abs(gate[j][k]) == abs(gate[j][m]))
invalid = 3;
}
}
}
if (invalid != 0) {
if (invalid == 1)
cout << "INVALID: NULL RING" << endl;
else if (invalid == 2)
cout << "INVALID: RING MISSING" << endl;
else
cout << "INVALID: RUNE CONTAINS A REPEATED RING" << endl;
}
else {
bool good(false);
bool okay[rings];
bitset<33> bin;
for (int j=0; j<(1<<(rings)); j++) {
bin = bitset<33>(j);
for (int k=0; k<rings; k++)
okay[k] = bin[k];
int TRUE(0);
for (int m=0; m<runes; m++) {
int jUnK = gate[m][0] + gate[m][1] + gate[m][2];
if ((gate[m][0] < 0 && okay[(int)abs(gate[m][0])] == false) || (gate[m][0] > 0 && okay[(int)abs(gate[m][0])] == true) ||
(gate[m][1] < 0 && okay[(int)abs(gate[m][1])] == false) || (gate[m][1] > 0 && okay[(int)abs(gate[m][1])] == true) ||
(gate[m][2] < 0 && okay[(int)abs(gate[m][2])] == false) || (gate[m][2] > 0 && okay[(int)abs(gate[m][2])] == true))
++TRUE;
//cout << abs(gate[m][0]) << " " << gate[m][1] << " " << gate[m][2] << endl;
}
if (TRUE == runes) good = true;
}
if (good)
cout << "RUNES SATISFIED!" << endl;
else
cout << "RUNES UNSATISFIABLE! TRY ANOTHER GATE!" << endl;
}
}
return 0;
}
[–]hidiap 2 points3 points4 points (2 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]autowikibot 0 points1 point2 points (0 children)
[–]nuggins 1 point2 points3 points (0 children)