CSES - Datatähti 2022 alku - Results
Submission details
Task:Ositus
Sender:Mixu_78
Submission time:2021-10-05 17:10:35 +0300
Language:Node.js
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.43 s1, 2, 3details
#20.46 s1, 2, 3details
#30.46 s1, 2, 3details
#40.45 s1, 2, 3details
#5--2, 3details
#60.44 s3details
#70.44 s3details

Code

const fs = require("fs");

const str = fs.existsSync("./subIn.txt") ? fs.readFileSync("./subIn.txt").toString() : fs.readFileSync(0).toString();

/**
 * @param {string} str
 * @returns {Generator<string[]>}
 */
function* partitions(str) {
	if (str.length > 0) {
		for (let i = 1; i < str.length + 1; i++) {
			const a = str.slice(0, i);
			const rest = str.slice(i);
			for (const p of partitions(rest)) {
				yield [a, ...p];
			}
		}
	} else {
		yield [];
	}
}

/**@param {string} s */
const hasDuplicate = (s) => {
	for (let i = 0; i < s.length; i++) {
		if (s.lastIndexOf(s[i]) !== i) return true;
	}
	return false;
}

let total = 0;
for (const part of partitions(str)) {
	const ok = part.every((s) => !hasDuplicate(s));
	if (ok) total++;
}

console.log(total)

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
a

correct output
1

user output
2

Test 2

Group: 1, 2, 3

Verdict:

input
abcdefghij

correct output
512

user output
1024

Test 3

Group: 1, 2, 3

Verdict:

input
abcabaacbc

correct output
120

user output
240

Test 4

Group: 1, 2, 3

Verdict:

input
aaxxxxxxaa

correct output
4

user output
8

Test 5

Group: 2, 3

Verdict:

input
mfyzvoxmppoxcvktmcjkryyocfweub...

correct output
643221148

user output
(empty)

Test 6

Group: 3

Verdict:

input
weinscqmmpgbrlboocvtbptgbahmwv...

correct output
831644159

user output
(empty)

Error:
/box/input/code.js:1
(function (exports, require, module, __filename, __dirname) { const fs = require("fs");
^

RangeError: Maximum call stack size exceeded
    at partitions (/box/input/code.js:1:1)
    at partitions (/box/input/code.js:14:20)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)

Test 7

Group: 3

Verdict:

input
sxaoxcyrjoeieyinaqxwukgzdnhhsw...

correct output
816016015

user output
(empty)

Error:
/box/input/code.js:1
(function (exports, require, module, __filename, __dirname) { const fs = require("fs");
^

RangeError: Maximum call stack size exceeded
    at partitions (/box/input/code.js:1:1)
    at partitions (/box/input/code.js:14:20)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)
    at partitions.next (<anonymous>)
    at partitions (/box/input/code.js:14:15)