arXiv:2610.30103cs.CLOct 2026

Manuscript Offprint

arXiv:2610.30103

Did the Problem Actually Get Harder? Testing LLMs on Paired P and NP-Complete Problems Hardened by Adversarial Multi-Agent Rewriting

Nurul Labib Sayeedi, Md. Faiyaz Abdullah Sayeedi, Zabir Al Nazi, Mahbub E Sobhani, Shubhashis Roy Dipta

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Many NP-complete (NPC) problems have a polynomial-time (P) twin that differs in a single structural detail, such as 3- versus 2-colouring a graph. A model that reasons rather than recalls should notice which side of this boundary a problem falls on, yet existing benchmarks either fix the wording of each task or ignore its complexity class, so they cannot separate the two. We introduce P2NPCBENCH, a benchmark of 12 problem families in which every NPC problem is paired with a P twin in the same problem setting. To remove the textbook cues that enable recall, we build it with AGENTGAN, an adversarial multi-agent framework in which a generator rewrites each statement until a panel of frozen code models fails, while an executable validity gate keeps every rewrite answer- and class-preserving. The result is 2,114 hardened statements with human-verified reference solvers. Evaluating 12 proprietary and open-source models, we find that every model scores lower on NPC statements than on their P twins (35.4% vs. 63.8% pass@1), and that 95.1% of model-family pairs fail more often on the NPC side. A tenfold time limit raises NPC accuracy only from 28.5% to 31.9%. Hardening lowers accuracy on both classes, more on P statements (29.6 points) than on NPC statements (19.5 points). Finally, we build a failure taxonomy, where runtime errors are the largest NPC failure type (44.1%), and nearly half of them (46.5%) come from malformed or truncated code. The dataset and code are available at Github.

1 Introduction

Complexity theory separates problems solvable in polynomial time (P) from NP-complete (NPC) problems, the hardest problems in NP (non-deterministic polynomial time), for which no polynomial-time algorithm is known (Karp, 1972; Hartmanis, 1982). The boundary between the two is often a single structural detail: 2-colouring a graph takes linear time while 3-colouring is NP-complete. Such problems underlie practical tasks in routing, scheduling, and network design (Imajuku et al., 2026), where misreading the class is costly: a solver either runs an exhaustive search on an easy instance or, worse, applies a fast algorithm that silently returns wrong answers on a hard one.

Large language models (LLMs) now write competitive code, but they are mostly evaluated on textbook-style or contest problems whose solutions may already appear in their training data (Xia et al., 2025; Mirzadeh et al., 2025a). A model that reasons rather than recalls should choose its algorithm from the structure of the problem, not from its name or wording. This is hard for three reasons: memory favours textbook phrasings over real-life ones (Duchnowski et al., 2025a); context can mislead, since one irrelevant clause or misleading comment can flip the answer (Mirzadeh et al., 2025a; Lam et al., 2026; Al Nazi et al., 2026); and computation stops scaling with difficulty (Yang et al., 2025). Testing this ability therefore requires P and NPC problems that differ in class but not in surface form.

Existing benchmarks cannot measure this failure. Combinatorial benchmarks such as GraphArena (Tang et al., 2025) and NPPC (Yang et al., 2025), as well as training frameworks built on NP-hard tasks (Li et al., 2025), treat complexity merely as a difficulty level. Closest to our setting, NPHardEval (Fan et al., 2024) spans P, NP-complete, and NP-hard classes, but keeps a single clean wording for each task, while EHOP (Duchnowski et al., 2025a) rewrites problems as real-life stories, but only for three NP-hard problems. Neither varies wording and class together, so neither can show whether models break when a problem crosses from P to NP-complete. Code robustness studies perturb code but not complexity (Wang et al., 2023b; Lam et al., 2026), math stress tests stay at grade-school level (Mirzadeh et al., 2025a), and budget studies vary tokens but not problem class (Sun et al., 2025; Zhang et al., 2026). To the best of our knowledge, no existing benchmark varies the complexity class while holding the surface form fixed. A more detailed discussion of related work is given in Appendix A.

To address this gap, we introduce P2NPCBENCH, a benchmark of 12 problem families in which every NP-complete problem is paired with a polynomial-time twin posed over the same surface, so that a single structural edit moves it across the class boundary. To remove the textbook cues that let models recall rather than reason, we build it with AGENTGAN, a Generative Adversarial Network (GAN)-style framework of frozen LLM agents in which a generator rewrites each statement until a panel of code models fails, while an executable validity gate guarantees that every rewrite keeps its answer and its class. Across 12 models, every model scores lower on NP-complete statements than on their polynomial twins (35.4% vs. 63.8% pass@1), and a tenfold time limit barely helps (28.5% → 31.9%), so failures stem mainly from incorrect or non-executable solutions rather than from time constraints. Our contributions are as follows:

• P2NPCBENCH, to the best of our knowledge the first benchmark that pairs each NP-complete problem with a polynomial-time variant differing in a single structural detail, with 2,114 hardened statements and human-verified reference solvers.

• AGENTGAN, a training-free adversarial framework that hardens statements while keeping them answer- and class-preserving.

• We evaluate 12 proprietary and open-source models and show that the dominant failure lies in the P→NPC direction, and that hardening narrows the class gap from 24.6 to 14.5 points.