CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:mbezirgan
Submission time:2021-10-17 23:46:07 +0300
Language:C++ (C++17)
Status:READY
Result:65
Feedback
groupverdictscore
#1ACCEPTED40
#2ACCEPTED25
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s2, 3details
#6ACCEPTED0.01 s3details
#7--3details

Code

#include <iostream>
#include <cmath>
#include <vector>

#include <iostream>
#include <cmath>
#include <vector>

#if 0

int main()
{
	std::string s;
	std::cin >> s;

	// How many combinations of multiplications can be put inside of the given range. First 2 numbers aren't needed but I'm too lazy to optimize it
	uint64_t* combinations = new uint64_t[s.size()]();
	uint64_t* sums = new uint64_t[s.size()]();

	for (uint64_t i = 0; i < s.size(); i++)
	{
		bool letters[26] = {};

		letters[s[i] - 'a'] = true;
		for (uint64_t j = i + 1; j < s.size(); j++)
		{
			if (letters[s[j] - 'a'])
				break;
			letters[s[j] - 'a'] = true;

			uint64_t left = i;
			uint64_t right = j;

			uint64_t lastTotal = 0;
			if (left)
			{
				for (int j = left - 1; j != 0; j--)
				{
					if (sums[j])
					{
						lastTotal = sums[j];
						break;
					}
				}
			}
			lastTotal %= 1000000007;

			combinations[right] += 1 + lastTotal;
			combinations[right] %= 1000000007;
			sums[left] = lastTotal + combinations[left];
			sums[left] %= 1000000007;
		}
	}
	
	uint64_t count = 1;
	for (uint64_t i = 1; i < s.size(); i++)
	{
		if (combinations[i])
		{
			count += combinations[i];
			count = count % 1000000007;
		}
	}

	std::cout << count;

	delete[] combinations;
	delete[] sums;
}

#else

int main()
{
	std::string s;
	std::cin >> s;


	// How many combinations of multiplications can be put inside of the given range. First 2 numbers aren't needed but I'm too lazy to optimize it
	uint64_t* combinations = new uint64_t[s.size()]();
	uint64_t* sums = new uint64_t[s.size()]();

	for (uint64_t i = 0; i < s.size(); i++)
	{
		bool letters[26] = {};

		letters[s[i] - 'a'] = true;
		for (uint64_t j = i + 1; j < s.size(); j++)
		{
			if (letters[s[j] - 'a'])
				break;
			letters[s[j] - 'a'] = true;

			uint64_t left = i;
			uint64_t right = j;

			uint64_t lastTotal = 0;
			if (left)
			{
				if (sums[left])
					lastTotal = sums[left];
				else
				{
					for (int j = left - 1; j != 0; j--)
					{
						lastTotal += combinations[j];
					}
					sums[left] = lastTotal;
				}
			}

			combinations[right] += 1 + lastTotal;
			combinations[right] = combinations[right] % 1000000007;
		}
	}

	uint64_t count = 1;
	for (uint64_t i = 1; i < s.size(); i++)
	{
		if (combinations[i])
		{
			count += combinations[i];
			count = count % 1000000007;
		}
	}

	std::cout << count;
}

#endif


/*
EXAMPLES FOR TESTING
A B A C
A B AC
A BA C
A BAC
AB A C
AB AC

A Y B A
A Y BA
A YB A
A YBA
AY B A
AY BA
AYB A

A Y B A B 1
A Y B AB 2
A Y BA B 3
A YB A B 4
A YB AB 5
A YBA B 6
AY B A B 7
AY B AB 8
AY BA B 9
AYB A B 10
AYB AB 11

*/

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
a

correct output
1

user output
1

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
abcdefghij

correct output
512

user output
512

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
abcabaacbc

correct output
120

user output
120

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
aaxxxxxxaa

correct output
4

user output
4

Test 5

Group: 2, 3

Verdict: ACCEPTED

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
643221148

Test 6

Group: 3

Verdict: ACCEPTED

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
831644159

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
(empty)