CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:mbezirgan
Submission time:2021-10-15 20:55:23 +0300
Language:C++17
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#20.01 s1, 2, 3details
#30.01 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s2, 3details
#60.01 s3details
#70.06 s3details

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()]();
	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[left - 1])
					{
						lastTotal = sums[left - 1];
						break;
					}
				}
			}

			combinations[right] += 1 + lastTotal;
			combinations[right] = combinations[right] % 1000000007;
			sums[left] = combinations[right];
		}
	}
	
	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:

input
abcdefghij

correct output
512

user output
759

Test 3

Group: 1, 2, 3

Verdict:

input
abcabaacbc

correct output
120

user output
26

Test 4

Group: 1, 2, 3

Verdict:

input
aaxxxxxxaa

correct output
4

user output
3

Test 5

Group: 2, 3

Verdict:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
255033462

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
812198673

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
379411843