Submission #55801342


Source Code Expand

Copy
#include<iostream>
#include<map>
using namespace std;
int n, m;
string s;
bool visited[20];
map<string, int> visited2;
int cnt;
bool check(string &p)
{
int i;
if (p.length() < m) return true;
for (i = 0; i < m; i++)
{
if (p[p.length() - i - 1] != p[p.length() - m + i]) return true;
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<iostream>
#include<map>
using namespace std;

int n, m;
string s;
bool visited[20];
map<string, int> visited2;
int cnt;

bool check(string &p)
{
	int i;

	if (p.length() < m) return true;

	for (i = 0; i < m; i++)
	{
		if (p[p.length() - i - 1] != p[p.length() - m + i]) return true;
	}

	return false;
}

void recur(int cur, string p)
{
	int i;

	if (!check(p)) return;

	if (cur == n)
	{
		if (visited2.find(p) != visited2.end()) return;

		visited2[p] = true;
		cnt++;

		return;
	}

	for (i = 0; i < n; i++)
	{
		if (visited[i]) continue;

		visited[i] = true;
		recur(cur + 1, p + s[i]);
		visited[i] = false;
	}
}

int main()
{
	cin >> n >> m;
	cin >> s;

	recur(0, "");

	cout << cnt;
}

Submission Info

Submission Time
Task C - Avoid K Palindrome 2
User gojib2002
Language C++ 20 (gcc 12.2)
Score 300
Code Size 760 Byte
Status AC
Exec Time 1476 ms
Memory 287036 KB

Compile Error

Main.cpp: In function ‘bool check(std::string&)’:
Main.cpp:15:24: warning: comparison of integer expressions of different signedness: ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
   15 |         if (p.length() < m) return true;
      |             ~~~~~~~~~~~^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 38
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3484 KB
example_01.txt AC 1 ms 3676 KB
example_02.txt AC 665 ms 37900 KB
hand_00.txt AC 1 ms 3672 KB
hand_01.txt AC 159 ms 3464 KB
hand_02.txt AC 1377 ms 286988 KB
hand_03.txt AC 1476 ms 287036 KB
hand_04.txt AC 184 ms 3476 KB
hand_05.txt AC 212 ms 6688 KB
hand_06.txt AC 214 ms 6556 KB
random_00.txt AC 1 ms 3484 KB
random_01.txt AC 1 ms 3468 KB
random_02.txt AC 1 ms 3468 KB
random_03.txt AC 1 ms 3464 KB
random_04.txt AC 1 ms 3448 KB
random_05.txt AC 3 ms 3536 KB
random_06.txt AC 5 ms 3620 KB
random_07.txt AC 5 ms 3484 KB
random_08.txt AC 8 ms 3496 KB
random_09.txt AC 17 ms 3640 KB
random_10.txt AC 5 ms 3500 KB
random_11.txt AC 266 ms 11148 KB
random_12.txt AC 22 ms 4340 KB
random_13.txt AC 22 ms 4336 KB
random_14.txt AC 547 ms 51596 KB
random_15.txt AC 52 ms 8156 KB
random_16.txt AC 286 ms 13752 KB
random_17.txt AC 559 ms 51688 KB
random_18.txt AC 1 ms 3484 KB
random_19.txt AC 1 ms 3532 KB
random_20.txt AC 59 ms 3488 KB
random_21.txt AC 28 ms 3472 KB
random_22.txt AC 186 ms 3580 KB
random_23.txt AC 248 ms 3604 KB
random_24.txt AC 4 ms 3756 KB
random_25.txt AC 3 ms 3612 KB
random_26.txt AC 239 ms 7092 KB
random_27.txt AC 239 ms 7160 KB


2025-03-16 (Sun)
20:04:41 +00:00