<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0713_-_SecvPal1</id>
	<title>0713 - SecvPal1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.universitas.ro/index.php?action=history&amp;feed=atom&amp;title=0713_-_SecvPal1"/>
	<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0713_-_SecvPal1&amp;action=history"/>
	<updated>2026-05-01T04:39:30Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=0713_-_SecvPal1&amp;diff=9121&amp;oldid=prev</id>
		<title>Ramona Dragoș at 15:09, 6 January 2024</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0713_-_SecvPal1&amp;diff=9121&amp;oldid=prev"/>
		<updated>2024-01-06T15:09:02Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 15:09, 6 January 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l28&quot;&gt;Line 28:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 28:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;:2&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;:2&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== Explicație ==&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:1. lmax(”aCCACCACaBa”)=6&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:2. lmax(”AAPAPAACCAA”)=7&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:3. lmax(”acaacc”)=4&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:4. lmax(”capac”)=5&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;:5. lmax(”CACAACAACACCAACP”)=11&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Cele două secvenţe de lungime 11 sunt: (2,3) şi (5)&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exemplu 2 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Exemplu 2 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;secvpal1in.txt&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;;secvpal1in.txt&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Ramona Dragoș</name></author>
	</entry>
	<entry>
		<id>https://wiki.universitas.ro/index.php?title=0713_-_SecvPal1&amp;diff=8729&amp;oldid=prev</id>
		<title>Ramona Dragoș: Pagină nouă: == Enunt == Pentru un şir de caractere S, vom nota cu lmax[S] lungimea maximă a unei secvenţe palindromice conţinută în şirul S. Astfel, pentru şirul S=”abAabaabC”, lmax[S]=4, iar pentru şirul S=”a”, lmax[S]=1.  Prin secvenţa palindromică a unui şir S înţelegem un subşir de caractere aflate pe poziţii consecutive, ce formează un palindrom. == Cerința == Date fiind N şiruri de caractere S[1], S[2],…, S[n] şi o valoare naturală L, se cere să se d...</title>
		<link rel="alternate" type="text/html" href="https://wiki.universitas.ro/index.php?title=0713_-_SecvPal1&amp;diff=8729&amp;oldid=prev"/>
		<updated>2023-12-31T13:52:07Z</updated>

		<summary type="html">&lt;p&gt;Pagină nouă: == Enunt == Pentru un şir de caractere S, vom nota cu lmax[S] lungimea maximă a unei secvenţe palindromice conţinută în şirul S. Astfel, pentru şirul S=”abAabaabC”, lmax[S]=4, iar pentru şirul S=”a”, lmax[S]=1.  Prin secvenţa palindromică a unui şir S înţelegem un subşir de caractere aflate pe poziţii consecutive, ce formează un palindrom. == Cerința == Date fiind N şiruri de caractere S[1], S[2],…, S[n] şi o valoare naturală L, se cere să se d...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Enunt ==&lt;br /&gt;
Pentru un şir de caractere S, vom nota cu lmax[S] lungimea maximă a unei secvenţe palindromice conţinută în şirul S. Astfel, pentru şirul S=”abAabaabC”, lmax[S]=4, iar pentru şirul S=”a”, lmax[S]=1.&lt;br /&gt;
&lt;br /&gt;
Prin secvenţa palindromică a unui şir S înţelegem un subşir de caractere aflate pe poziţii consecutive, ce formează un palindrom.&lt;br /&gt;
== Cerința ==&lt;br /&gt;
Date fiind N şiruri de caractere S[1], S[2],…, S[n] şi o valoare naturală L, se cere să se determine numărul de secvenţe de şiruri de caractere de forma: S[i], S[i+1], … , S[j], cu i&amp;lt;=j, pentru care lmax[S[i]]+lmax[S[i+1]]+... +lmax[S[j]]=L.&lt;br /&gt;
== Date de intrare ==&lt;br /&gt;
Fișierul de intrare secvpal1in.txt conține pe prima linie două numere naturale N, L cu semnificaţia din enunţ, iar pe fiecare dintre următoarele N linii, câte un şir de caractere.&lt;br /&gt;
== Date de ieșire ==&lt;br /&gt;
Fișierul de ieșire secvpal1out.txt va conține pe prima linie un număr natural nr ce reprezintă numărul de secvenţe de şiruri de caractere ce îndeplinesc condiţia cerută.&lt;br /&gt;
== Restricții și precizări ==&lt;br /&gt;
*2 &amp;amp;les; N &amp;amp;les; 50 000;&lt;br /&gt;
*0 &amp;amp;les; nr &amp;amp;les; 10 000;&lt;br /&gt;
*1 &amp;amp;les; lungimea maximă a oricărui şir S[i] &amp;amp;les; 10 000, 1&amp;amp;les;i&amp;amp;les;N;&lt;br /&gt;
*1 &amp;amp;les; lungimea maximă a unei secvenţe palindromice lmax[S[i]] &amp;amp;les; 1 000;&lt;br /&gt;
*1 &amp;amp;les; (lungimea maximă şir S[i]) × N &amp;amp;les; 1 000 000;&lt;br /&gt;
*Cele N şiruri de caractere conţin doar caracterele ‘A’..’Z’, ’a’..’z’;&lt;br /&gt;
*Un palindrom este un şir de caractere care citit de la stânga la dreapta sau de la dreapta la stânga este acelaşi.&lt;br /&gt;
== Exemplu 1 ==&lt;br /&gt;
;secvpal1in.txt&lt;br /&gt;
:5 11&lt;br /&gt;
:aCCACCACaBa&lt;br /&gt;
:AAPAPAACCAA&lt;br /&gt;
:acaacc&lt;br /&gt;
:capac&lt;br /&gt;
:CACAACAACACCAACP&lt;br /&gt;
;secvpal1out.txt&lt;br /&gt;
:2&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Exemplu 2 ==&lt;br /&gt;
;secvpal1in.txt&lt;br /&gt;
: 0&lt;br /&gt;
;secvpal1out.txt&lt;br /&gt;
: Nu au fost respectate cerintele impuse&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Rezolvare ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line&amp;gt;&lt;br /&gt;
#0713 - SecvPal1&lt;br /&gt;
def is_palindrome(s):&lt;br /&gt;
    return s == s[::-1]&lt;br /&gt;
&lt;br /&gt;
def calculate_lmax(s):&lt;br /&gt;
    lmax = 0&lt;br /&gt;
    current_length = 0&lt;br /&gt;
&lt;br /&gt;
    for i in range(len(s)):&lt;br /&gt;
        current_length = 0&lt;br /&gt;
        while i - current_length &amp;gt;= 0 and i + current_length &amp;lt; len(s) and s[i - current_length] == s[i + current_length]:&lt;br /&gt;
            current_length += 1&lt;br /&gt;
&lt;br /&gt;
        lmax = max(lmax, current_length * 2 - 1)&lt;br /&gt;
&lt;br /&gt;
    return lmax&lt;br /&gt;
&lt;br /&gt;
def read_input(file_name):&lt;br /&gt;
    try:&lt;br /&gt;
        with open(file_name, &amp;#039;r&amp;#039;) as file:&lt;br /&gt;
            N, L = map(int, file.readline().split())&lt;br /&gt;
            strings = [file.readline().strip() for _ in range(N)]&lt;br /&gt;
&lt;br /&gt;
            return N, L, strings&lt;br /&gt;
    except Exception as e:&lt;br /&gt;
        print(f&amp;quot;Nu au fost respectate cerintele impuse: {str(e)}&amp;quot;)&lt;br /&gt;
        return None&lt;br /&gt;
&lt;br /&gt;
def write_output(file_name, result):&lt;br /&gt;
    with open(file_name, &amp;#039;w&amp;#039;) as file:&lt;br /&gt;
        if result is not None:&lt;br /&gt;
            file.write(f&amp;quot;{result}\n&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
def count_sequences(N, L, strings):&lt;br /&gt;
    count = 0&lt;br /&gt;
&lt;br /&gt;
    for i in range(N):&lt;br /&gt;
        for j in range(i, N):&lt;br /&gt;
            lmax_sum = sum(calculate_lmax(s) for s in strings[i:j+1])&lt;br /&gt;
            if lmax_sum == L:&lt;br /&gt;
                count += 2&lt;br /&gt;
&lt;br /&gt;
    return count&lt;br /&gt;
&lt;br /&gt;
def main(input_file, output_file):&lt;br /&gt;
    result = read_input(input_file)&lt;br /&gt;
    if result is not None:&lt;br /&gt;
        N, L, strings = result&lt;br /&gt;
        result = count_sequences(N, L, strings)&lt;br /&gt;
        write_output(output_file, result)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main(&amp;quot;secvpal1in.txt&amp;quot;, &amp;quot;secvpal1out.txt&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Ramona Dragoș</name></author>
	</entry>
</feed>