Submission #1342089

#TimeUsernameProblemLanguageResultExecution timeMemory
1342089zeyruganRound words (IZhO13_rowords)C++20
Compilation error
0 ms0 KiB
//ROUND WORD
// so here we can merge b as B=B+B then any rotation of B is from B+B and then we can use LCS
//https://oj.uz/problem/view/IZhO13_rowords
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
using namespace std;

int lcs(const string &a,const string& window){
    int n=a.length();
    int m=window.length();

    vector<int> prev(m+1,0),curr(m+1,0);

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i-1]==window[j-1]){
                curr[j]=prev[j-1]+1;
            }
            else{
                curr[j]=max(prev[j],curr[j-1]);
            }
        }
        swap(prev,curr);
    }
    return prev[m];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    #ifndef ONLINE_JUDGE
    freopen("rowards.in","r",stdin);
    freopen("rowards.out","w",stdout);
    #endif
    
    string A,B;
    cin>>A>>B;

    if(B.length()>A.length()){
        swap(A,B);
    }

    string newB=B+B;
    
    int m=B.size();
    int lcslen=0;
    for(int i=0;i<m;i++){
        string window=newB.substr(i,m);
        lcslen=max(lcslen,lcs(A,window));
    }
    cout<<lcslen<<endl;
    return 0;
}

Compilation message (stderr)

rowords.cpp: In function 'int main()':
rowords.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("rowards.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
rowords.cpp:35:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     freopen("rowards.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from rowords.cpp:7:
/usr/include/c++/13/bits/allocator.h: In destructor 'constexpr std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()':
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'constexpr std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/string:54:
/usr/include/c++/13/bits/basic_string.h:181:14: note: called from here
  181 |       struct _Alloc_hider : allocator_type // TODO check __is_final
      |              ^~~~~~~~~~~~