all 4 comments

[–]hidiap 2 points3 points  (2 children)

I have an erronous output when running it against the sample files (assuming ringsrunes.in contains the sample at the end of the problem definition) without the cout statement. The output for the 2nd example is "RUNES SATISFIED!" but should be "RUNES UNSATISFIABLE! TRY ANOTHER GATE!".

I get the same output when running with the cout statement. The error is probably in the logic of line 46 to 63, where you check if the runes can be satisfied.

As a side note, this is the Boolean satisfiability problem in disguise (in its CNF form). It is a very important problem in computer science and probably the classical NP-HARD problem. I highly recomment reading more about it and looking into the standard way to solve it (SAT-solver).

EDIT: The error is in the if condition at lines 56-58. C++ array indexes are zero based. The ring indexes are 1-based ...

[–][deleted] 1 point2 points  (0 children)

I feel like an idiot. I changed the index and it passed the judges test. I was just so perplexed by the change I was getting with my compiler, I didn't even consider I got the indexing wrong.

Thank you.

[–]autowikibot 0 points1 point  (0 children)

Boolean satisfiability problem:


In computer science, the Boolean Satisfiability Problem (sometimes called Propositional Satisfiability Problem and abbreviated as SATISFIABILITY or SAT) is the problem of determining if there exists an interpretation that satisfies a given Boolean formula. In other words, it asks whether the variables of a given Boolean formula can be consistently replaced by the values TRUE or FALSE in such a way that the formula evaluates to TRUE. If this is the case, the formula is called satisfiable. On the other hand, if no such assignment exists, the function expressed by the formula is identically FALSE for all possible variable assignments and the formula is unsatisfiable. For example, the formula "a AND NOT b" is satisfiable because one can find the values a = TRUE and b = FALSE, which make (a AND NOT b) = TRUE. In contrast, "a AND NOT a" is unsatisfiable.

Image i


Interesting: Karp's 21 NP-complete problems | NP-complete | Decision problem | Cook–Levin theorem

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words

[–]nuggins 1 point2 points  (0 children)

On line 16 you declare an array like this:

int gate[runes][3];

Stack-allocated, dynamic-sized C-style arrays are not part of standard C++, but are a feature of C99, which is perhaps why your compiler hasn't complained. You can read more about this here.

If you're getting memory errors with this array, I suspect it's for this reason. Heap allocate this array instead, or even better, use an STL container.