CSES - Aalto Competitive Programming 2024 - wk9 - Mon - Results
Submission details
Task:String padding
Sender:Rasse
Submission time:2024-11-04 22:05:59 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#10.00 sdetails
#20.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.01 sdetails
#70.01 sdetails
#80.01 sdetails
#90.01 sdetails
#100.01 sdetails
#11ACCEPTED0.00 sdetails
#120.00 sdetails
#13ACCEPTED0.00 sdetails
#140.01 sdetails
#150.01 sdetails
#160.00 sdetails
#17ACCEPTED0.00 sdetails
#180.01 sdetails

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:32:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
input/code.cpp:39:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             while (r < s.size() && s[l] == s[r])
      |                    ~~^~~~~~~~~~
input/code.cpp:58:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                 while (r < s.size() && s[l] == s[r])
      |                        ~~^~~~~~~~~~
input/code.cpp:68:25: warning: comparison of integer expressions of d...

Code

#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <climits>
#include <cmath>
#include <functional>
#include <type_traits>
#include <bitset>
#include <fstream>
 
#define int long long
using namespace std;

int mod = 10e9+7;

void solve() {
    int n;
    string s;
    cin >> n >> s;

    vector<int> zArr(s.size());
    vector<int> res;
 
    int l = 0, r = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (i > r)
        {
            // Use naive
            r = i;
            l = 0;
            while (r < s.size() && s[l] == s[r])
            {
                l++;
                r++;
            }
            r--;
            l = i;
            zArr[i] = r-i+1;
        }
        else
        {
            if (zArr[i-l] < r-i+1)
            {
                zArr[i] = zArr[i-l];
            }
            else
            {
                l = r-i+1;
                r = r+1;
                while (r < s.size() && s[l] == s[r])
                {
                    l++;
                    r++;
                }
                l = i;
                r--;
                zArr[i] = r-l+1;
            }
        }
        if (zArr[i] + i == s.size())
            res.push_back(zArr[i]);
    }
    for (int i = res.size()-1; i >= 0; i--)
    {
        cout << res[i] << " ";
    }

    vector<int> mult(n);
    mult[0] = 1;
    for (int i = 1; i < mult.size(); i++)
        mult[i] = (mult[i-1] * 26) % mod;

    vector<int> dp(n);
    for (int i = 0; i < s.size(); i++)
    {
        dp[i] = 0;
    }
    dp[s.size()-1] = 1;


    for (int i = s.size(); i < dp.size(); i++)
    {
        dp[i] = mult[i-s.size()+1];

        for (int j = 0; j < res.size(); j++)
        {
            dp[i] = (dp[i] - dp[i-s.size()+res[j]]) % mod;
        }
        for (int j = 0; j <= i-s.size(); j++)
            dp[i] = (dp[i] - dp[j]) % mod;
        
        dp[i] = (dp[i] + mod) % mod;

        cout << i << ": " << dp[i] << endl;
    }

    int result = 0;
    int multiple = 1;
    for (int i = n-1; i >= 0; i--)
    {
        result += dp[i] * multiple;
        multiple *= 26;

        multiple %= mod;
        result %= mod;
    }
 
    cout << result;

}
 
signed main() {
    //cin.tie(0);
    //ios_base::sync_with_stdio(false);
    int t = 1;
    //ifstream f("testcase.txt");
    //cin.rdbuf(f.rdbuf());
    //cin >> t;
    while (t--) { solve(); }
}

Test details

Test 1

Verdict:

input
100
YWANYWAZYWANYWA

correct output
134837038

user output
3 7 15: 26
16: 676
17: 17576
18: 456976
19: 11881376
...
Truncated

Test 2

Verdict:

input
100
EDMXEDVNEDMXED

correct output
642715950

user output
2 6 14: 26
15: 676
16: 17576
17: 456976
18: 11881376
...
Truncated

Test 3

Verdict:

input
100
SDARSDAWVSDARSDA

correct output
748728234

user output
3 7 16: 26
17: 676
18: 17576
19: 456976
20: 11881376
...
Truncated

Test 4

Verdict:

input
100
HBDHBSHBDHB

correct output
594110560

user output
2 5 11: 26
12: 676
13: 17576
14: 456976
15: 11881376
...
Truncated

Test 5

Verdict:

input
100
CUNXUYGNGNEROXVLASQB

correct output
675706202

user output
20: 26
21: 676
22: 17576
23: 456976
24: 11881376
...
Truncated

Test 6

Verdict:

input
1000
LZAOLRKGLZAOLXLZAOLRKGLZAOLTLZ...

correct output
318756627

user output
1 5 13 27 55: 26
56: 676
57: 17576
58: 456976
59: 11881376
...
Truncated

Test 7

Verdict:

input
1000
SUASJSUASSGDSUASJSUASGKSUASJSU...

correct output
367950233

user output
1 4 9 21 44 90: 26
91: 676
92: 17576
93: 456976
94: 11881376
...
Truncated

Test 8

Verdict:

input
1000
NHYGNHEWNHYGNHFSNHYGNHEWNHYGNH...

correct output
849646061

user output
2 6 14 30 63: 26
64: 676
65: 17576
66: 456976
67: 11881376
...
Truncated

Test 9

Verdict:

input
1000
ZOCUZOCGRFZOCUZOCOQZOCUZOCGRFZ...

correct output
32142571

user output
3 7 17 36 75: 26
76: 676
77: 17576
78: 456976
79: 11881376
...
Truncated

Test 10

Verdict:

input
1000
LJZMKDTECKBXBTQQUMLGADBDNGWGPY...

correct output
26128120

user output
100: 26
101: 676
102: 17576
103: 456976
104: 11881376
...
Truncated

Test 11

Verdict: ACCEPTED

input
1
A

correct output
1

user output
1

Test 12

Verdict:

input
100
AVXETIDRHKPAKRBEAAVHLOPFACULSE...

correct output
228794815

user output
42: 26
43: 676
44: 17576
45: 456976
46: 11881376
...
Truncated

Test 13

Verdict: ACCEPTED

input
3
ABC

correct output
1

user output
1

Test 14

Verdict:

input
745
RRQOVUJRQBIMIQK

correct output
504765084

user output
15: 26
16: 676
17: 17576
18: 456976
19: 11881376
...
Truncated

Test 15

Verdict:

input
666
ABCABCDABCABCX

correct output
920654188

user output
14: 26
15: 676
16: 17576
17: 456976
18: 11881376
...
Truncated

Test 16

Verdict:

input
6
AA

correct output
2212651

user output
1 2: 25
3: 650
4: 16900
5: 439400
2214576

Test 17

Verdict: ACCEPTED

input
1
B

correct output
1

user output
1

Test 18

Verdict:

input
1000
OMAKARAAA

correct output
408042378

user output
9: 26
10: 676
11: 17576
12: 456976
13: 11881376
...
Truncated