CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:mbezirgan
Submission time:2021-10-15 18:24:47 +0300
Language:C++ (C++17)
Status:READY
Result:40
Feedback
groupverdictscore
#1ACCEPTED40
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#50.01 s2, 3details
#60.04 s3details
#7--3details

Code

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

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

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()]();

	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--)
				{
					lastTotal += combinations[j];
				}
			}

			combinations[right] += 1 + lastTotal;
			if (combinations[right] >= 1000000007)
				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;
}

/*
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:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
31643221365

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
2421831661106

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
(empty)