Programming Challenge from Kattis: Distinctive CharactersHackers Ranking String SimilarityRemoving accents from certain charactersFinding longest substring containing k distinct charactersFunny String Java SolutionProgramming Challenge from Kattis: ApparatusReturn characters in a string in alphabetical orderLeetcode: String to Integer (atoi)Sliding window to solve “longest substring, no repeating chars”Morgan and a String HackerRank challengeProgramming Challenge from Kattis: Watchdog
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
Unable to deploy metadata from Partner Developer scratch org because of extra fields
Why is consensus so controversial in Britain?
What does the "remote control" for a QF-4 look like?
Watching something be written to a file live with tail
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
Can a Cauchy sequence converge for one metric while not converging for another?
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
What would happen to a modern skyscraper if it rains micro blackholes?
When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?
Has there ever been an airliner design involving reducing generator load by installing solar panels?
How does one intimidate enemies without having the capacity for violence?
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Important Resources for Dark Age Civilizations?
Codimension of non-flat locus
Add text to same line using sed
Revoked SSL certificate
Malformed Address '10.10.21.08/24', must be X.X.X.X/NN or
What's the output of a record needle playing an out-of-speed record
Client team has low performances and low technical skills: we always fix their work and now they stop collaborate with us. How to solve?
Perform and show arithmetic with LuaLaTeX
Rock identification in KY
RSA: Danger of using p to create q
Is it inappropriate for a student to attend their mentor's dissertation defense?
Programming Challenge from Kattis: Distinctive Characters
Hackers Ranking String SimilarityRemoving accents from certain charactersFinding longest substring containing k distinct charactersFunny String Java SolutionProgramming Challenge from Kattis: ApparatusReturn characters in a string in alphabetical orderLeetcode: String to Integer (atoi)Sliding window to solve “longest substring, no repeating chars”Morgan and a String HackerRank challengeProgramming Challenge from Kattis: Watchdog
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.
I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.
Example input:
3 5
01001
11100
10111
Example output:
00010
My code:
import sys
import itertools
def similarity(sx, sy):
'''Naively calculates similarity between two
strings.'''
result = 0
for i in range(n_feat):
if sx[i] == sy[i]:
result += 1
return result
line_1 = sys.stdin.readline()
line_1 = line_1.split()
N = int(line_1[0])
n_feat = int(line_1[1])
characters = set()
for i in range(N):
characters.add(str(sys.stdin.readline()))
# Generate all possible ways to write n_feat long string with alphabet 0,1
all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
# Subset actually possible (removed ones have similarity == n_feat)
pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]
# Impossibly high starting-point.
curr_min = n_feat+1
curr_small = ""
for pos_char in pos_chars:
curr = max(similarity(pos_char, character) for character in characters)
if curr == 0:
curr_small = pos_char
break;
if curr <= curr_min:
curr_min = curr
curr_small = pos_char
print(curr_small)
This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in
where 1.in is the example input given above and received this:
300 function calls in 0.001 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.001 0.001 built-in method builtins.exec
1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
1 0.000 0.000 0.000 0.000 built-in method builtins.print
31 0.000 0.000 0.000 0.000 built-in method builtins.max
124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters)
, and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20
, and the next 10000 lines are 20 zeros:
python -m cProfile -s cumtime dischar2.py < 6.in
11111111111111111111
7360118 function calls in 9.280 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 9.280 9.280 built-in method builtins.exec
1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
1 0.000 0.000 0.000 0.000 built-in method builtins.print
28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?
python performance algorithm python-3.x programming-challenge
New contributor
$endgroup$
add a comment |
$begingroup$
I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.
I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.
Example input:
3 5
01001
11100
10111
Example output:
00010
My code:
import sys
import itertools
def similarity(sx, sy):
'''Naively calculates similarity between two
strings.'''
result = 0
for i in range(n_feat):
if sx[i] == sy[i]:
result += 1
return result
line_1 = sys.stdin.readline()
line_1 = line_1.split()
N = int(line_1[0])
n_feat = int(line_1[1])
characters = set()
for i in range(N):
characters.add(str(sys.stdin.readline()))
# Generate all possible ways to write n_feat long string with alphabet 0,1
all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
# Subset actually possible (removed ones have similarity == n_feat)
pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]
# Impossibly high starting-point.
curr_min = n_feat+1
curr_small = ""
for pos_char in pos_chars:
curr = max(similarity(pos_char, character) for character in characters)
if curr == 0:
curr_small = pos_char
break;
if curr <= curr_min:
curr_min = curr
curr_small = pos_char
print(curr_small)
This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in
where 1.in is the example input given above and received this:
300 function calls in 0.001 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.001 0.001 built-in method builtins.exec
1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
1 0.000 0.000 0.000 0.000 built-in method builtins.print
31 0.000 0.000 0.000 0.000 built-in method builtins.max
124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters)
, and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20
, and the next 10000 lines are 20 zeros:
python -m cProfile -s cumtime dischar2.py < 6.in
11111111111111111111
7360118 function calls in 9.280 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 9.280 9.280 built-in method builtins.exec
1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
1 0.000 0.000 0.000 0.000 built-in method builtins.print
28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?
python performance algorithm python-3.x programming-challenge
New contributor
$endgroup$
add a comment |
$begingroup$
I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.
I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.
Example input:
3 5
01001
11100
10111
Example output:
00010
My code:
import sys
import itertools
def similarity(sx, sy):
'''Naively calculates similarity between two
strings.'''
result = 0
for i in range(n_feat):
if sx[i] == sy[i]:
result += 1
return result
line_1 = sys.stdin.readline()
line_1 = line_1.split()
N = int(line_1[0])
n_feat = int(line_1[1])
characters = set()
for i in range(N):
characters.add(str(sys.stdin.readline()))
# Generate all possible ways to write n_feat long string with alphabet 0,1
all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
# Subset actually possible (removed ones have similarity == n_feat)
pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]
# Impossibly high starting-point.
curr_min = n_feat+1
curr_small = ""
for pos_char in pos_chars:
curr = max(similarity(pos_char, character) for character in characters)
if curr == 0:
curr_small = pos_char
break;
if curr <= curr_min:
curr_min = curr
curr_small = pos_char
print(curr_small)
This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in
where 1.in is the example input given above and received this:
300 function calls in 0.001 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.001 0.001 built-in method builtins.exec
1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
1 0.000 0.000 0.000 0.000 built-in method builtins.print
31 0.000 0.000 0.000 0.000 built-in method builtins.max
124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters)
, and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20
, and the next 10000 lines are 20 zeros:
python -m cProfile -s cumtime dischar2.py < 6.in
11111111111111111111
7360118 function calls in 9.280 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 9.280 9.280 built-in method builtins.exec
1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
1 0.000 0.000 0.000 0.000 built-in method builtins.print
28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?
python performance algorithm python-3.x programming-challenge
New contributor
$endgroup$
I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. Similarity between two strings is measured by increasing the similarity by 1 if both strings have the same character in the same position. E.g: "01001" "11110" has similarity 1, because they both have 1 in their 2nd position, and for every other position they have different characters. An input starts with one line giving two numbers N and P, being first the number of strings in the list, and then the length of each string. The rest of the input is then N lines of single strings. The output should be a string that has the least possible similarity to any string in the input.
I'd like suggestions on how to reduce the number of calls I'm doing in my solution to this problem. Likely by some algorithmic magic.
Example input:
3 5
01001
11100
10111
Example output:
00010
My code:
import sys
import itertools
def similarity(sx, sy):
'''Naively calculates similarity between two
strings.'''
result = 0
for i in range(n_feat):
if sx[i] == sy[i]:
result += 1
return result
line_1 = sys.stdin.readline()
line_1 = line_1.split()
N = int(line_1[0])
n_feat = int(line_1[1])
characters = set()
for i in range(N):
characters.add(str(sys.stdin.readline()))
# Generate all possible ways to write n_feat long string with alphabet 0,1
all_pos_chars = ["".join(seq) for seq in itertools.product("01", repeat=n_feat)]
# Subset actually possible (removed ones have similarity == n_feat)
pos_chars = [pos_char for pos_char in all_pos_chars if pos_char not in characters]
# Impossibly high starting-point.
curr_min = n_feat+1
curr_small = ""
for pos_char in pos_chars:
curr = max(similarity(pos_char, character) for character in characters)
if curr == 0:
curr_small = pos_char
break;
if curr <= curr_min:
curr_min = curr
curr_small = pos_char
print(curr_small)
This solution works fine for smaller inputs. For example, I ran python -m cProfile -s cumtime dischar.py < 1.in
where 1.in is the example input given above and received this:
300 function calls in 0.001 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.001 0.001 built-in method builtins.exec
1 0.000 0.000 0.001 0.001 dischar2.py:1(<module>)
1 0.000 0.000 0.000 0.000 built-in method builtins.print
31 0.000 0.000 0.000 0.000 built-in method builtins.max
124 0.000 0.000 0.000 0.000 dischar2.py:34(<genexpr>)
93 0.000 0.000 0.000 0.000 dischar2.py:5(similarity)
4 0.000 0.000 0.000 0.000 method 'readline' of '_io.TextIOWrapper' objects
1 0.000 0.000 0.000 0.000 dischar2.py:26(<listcomp>)
2 0.000 0.000 0.000 0.000 cp1252.py:22(decode)
32 0.000 0.000 0.000 0.000 method 'join' of 'str' objects
1 0.000 0.000 0.000 0.000 dischar2.py:28(<listcomp>)
2 0.000 0.000 0.000 0.000 built-in method _codecs.charmap_decode
2 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
3 0.000 0.000 0.000 0.000 method 'add' of 'set' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
But I was worried about the number of calls at line:34, which is this bit of code: curr = max(similarity(pos_char, character) for character in characters)
, and then onwards to line:5 which is the similartiy-function. I made a 6.in, where the first line is 10000 20
, and the next 10000 lines are 20 zeros:
python -m cProfile -s cumtime dischar2.py < 6.in
11111111111111111111
7360118 function calls in 9.280 seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 9.280 9.280 built-in method builtins.exec
1 0.756 0.756 9.280 9.280 dischar2.py:1(<module>)
1048575 0.663 0.000 7.700 0.000 built-in method builtins.max
3145725 0.777 0.000 7.037 0.000 dischar2.py:34(<genexpr>)
2097150 6.260 0.000 6.260 0.000 dischar2.py:5(similarity)
1 0.325 0.325 0.656 0.656 dischar2.py:26(<listcomp>)
1048576 0.332 0.000 0.332 0.000 method 'join' of 'str' objects
1 0.161 0.161 0.161 0.161 dischar2.py:28(<listcomp>)
10001 0.004 0.000 0.005 0.000 method 'readline' of '_io.TextIOWrapper' objects
10000 0.001 0.000 0.001 0.000 method 'add' of 'set' objects
28 0.000 0.000 0.001 0.000 cp1252.py:22(decode)
28 0.001 0.000 0.001 0.000 built-in method _codecs.charmap_decode
1 0.000 0.000 0.000 0.000 built-in method builtins.print
28 0.000 0.000 0.000 0.000 codecs.py:281(getstate)
1 0.000 0.000 0.000 0.000 method 'split' of 'str' objects
1 0.000 0.000 0.000 0.000 method 'disable' of '_lsprof.Profiler' objects
As you can see, this adds up quickly! I think my solution is sound, it provides the correct output for every case I can test for. But there has to be some trick that I'm not seeing, because Kattis expects the solution to run within 2 CPU-seconds. Any suggestions?
python performance algorithm python-3.x programming-challenge
python performance algorithm python-3.x programming-challenge
New contributor
New contributor
New contributor
asked 7 mins ago
RoyMRoyM
284
284
New contributor
New contributor
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
RoyM is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216960%2fprogramming-challenge-from-kattis-distinctive-characters%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
RoyM is a new contributor. Be nice, and check out our Code of Conduct.
RoyM is a new contributor. Be nice, and check out our Code of Conduct.
RoyM is a new contributor. Be nice, and check out our Code of Conduct.
RoyM is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216960%2fprogramming-challenge-from-kattis-distinctive-characters%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown