CSES - Aalto Competitive Programming 2024 - wk9 - Mon - Results
Submission details
Task:String padding
Sender:Rasse
Submission time:2024-11-04 17:49:42 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void solve()':
input/code.cpp:31: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]
   31 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
input/code.cpp:38: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]
   38 |             while (r < s.size() && s[l] == s[r])
      |                    ~~^~~~~~~~~~
input/code.cpp:57: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]
   57 |                 while (r < s.size() && s[l] == s[r])
      |                        ~~^~~~~~~~~~
input/code.cpp:67: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;


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]);
    }

    int mult = 1;
    for (int i = s.size(); i < n; i++)
    {
        mult = (mult * 26) % 1000000007;
    }
    int res2 = 0;
    for (int i = 0; i < min(s.size()-res.size()+1, n-s.size()+1); i++)
    {
        res2 = (res2+ mult) % 1000000007;
    }
    cout << res2;

}
 
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(); }
}