Language: C++

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <complex>
#include <assert.h>
#include <limits.h>
//#include <bits/stdc++.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp

//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,ll>pil;
typedef pair<ll,ll> pll;
//const double INF=1e20;
const int INF=0x3f3f3f3f;
//const int INF= 0x7fffffff;
//const ll INF=0x3f3f3f3f3f3f3f3fll;
const ll INFF=0x3f3f3f3f3f3f3fll;
//const ll INFF=1e14+5;
const int MAX=2e5+5;
//const ll MAXN=2e8;
//const int MAX_N=MAX;
//const ll MOD=1e9+7;
const ll MOD=998244353;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
//#define double long double
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
//const long double eps=-1.0;
//clock_t t1 = clock();
//fprintf(stderr, "%ld ms\n", clock() - t1);
void open()
{
    freopen("in2.txt","r",stdin);
    freopen("out2.txt","w",stdout);
}
char s[MAX];
int c[MAX];
ll dp[MAX][4][4][3];//lo summod3 last3  adj=
char CH='a';
int tot;
bool adj;
ll an;
bool vi[305];
int len;
void dfs()
{
    int now=0;
    for(int i=1;i<=len;i++)
        now=now*3+c[i];
    if(vi[now])return;
    else ++an;
    for(int j=1;j<=len-1;j++)
        if(c[j]!=c[j+1])
        {
            int x=c[j],y=c[j+1];
            for(int t=0;t<3;t++)
                if(t!=c[j]&&t!=c[j+1])
                    {c[j]=c[j+1]=t;break;}
            dfs();
            c[j]=x;c[j+1]=y;
        }
}
set em;
int main()
{
    scanf("%s",s+1);
    len=strlen(s+1);

    for(int i=1;i<=len;i++){c[i]=s[i]-'a';tot+=c[i];if(i>1&&c[i]==c[i-1])adj=1;em.insert(c[i]);}
    tot%=3;
    if(em.size()==1)
        return 0*printf("1\n");
    if(len<=3)
    {
        dfs();
        printf("%lld\n",an);
        return 0;
    }
    dp[1][0][0][0]=dp[1][1][1][0]=dp[1][2][2][0]=1;
    for(int i=2;i<=len;i++)
    {
        for(int j=0;j<3;j++)//this
            for(int k=0;k<3;k++)//presum
            {
                int sum=(j+k)%3;
                for(int p=0;p<3;p++)
                    if(p!=j)
                        (dp[i][sum][j][0]+=dp[i-1][k][p][0])%=MOD;
                    else
                        dp[i][sum][j][1]=dp[i-1][k][p][0];
                for(int p=0;p<3;p++)
                    (dp[i][sum][j][1]+=dp[i-1][k][p][1])%=MOD;

            }
    }
    for(int i=0;i<3;i++)
        an+=dp[len][tot][i][1];
    if(!adj)++an;
    printf("%lld\n",an);
}
/*

*/


Compiler output:
a.cc:110:5: error: class template argument deduction failed:
  110 | set em;
      |     ^~
a.cc:110:5: error: no matching function for call to 'set()'
In file included from /usr/include/c++/14/set:63,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_set.h:273:9: note: candidate: 'template<class _Key, class _Compare, class _Alloc, class _InputIterator> set(_InputIterator, _InputIterator, const _Alloc&)-> std::set<_Key, _Compare, _Alloc>'
  273 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:273:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:267:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(std::initializer_list<_Tp>, const _Alloc&)-> std::set<_Key, _Compare, _Alloc>'
  267 |       set(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:267:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:261:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(std::set<_Key, _Compare, _Allocator>&&, std::__type_identity_t<_Alloc>&)-> std::set<_Key, _Compare, _Alloc>'
  261 |       set(set&& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:261:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:257:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(const std::set<_Key, _Compare, _Allocator>&, std::__type_identity_t<_Alloc>&)-> std::set<_Key, _Compare, _Alloc>'
  257 |       set(const set& __x, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:257:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:253:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(const _Alloc&)-> std::set<_Key, _Compare, _Alloc>'
  253 |       set(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:253:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:245:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(std::initializer_list<_Tp>, const _Compare&, const _Alloc&)-> std::set<_Key, _Compare, _Alloc>'
  245 |       set(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:245:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:233:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(std::set<_Key, _Compare, _Allocator>&&)-> std::set<_Key, _Compare, _Alloc>'
  233 |       set(set&&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:233:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:225:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(const std::set<_Key, _Compare, _Allocator>&)-> std::set<_Key, _Compare, _Alloc>'
  225 |       set(const set&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:225:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:210:9: note: candidate: 'template<class _Key, class _Compare, class _Alloc, class _InputIterator> set(_InputIterator, _InputIterator, const _Compare&, const _Alloc&)-> std::set<_Key, _Compare, _Alloc>'
  210 |         set(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:210:9: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:193:9: note: candidate: 'template<class _Key, class _Compare, class _Alloc, class _InputIterator> set(_InputIterator, _InputIterator)-> std::set<_Key, _Compare, _Alloc>'
  193 |         set(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_set.h:193:9: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:178:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(const _Compare&, const _Alloc&)-> std::set<_Key, _Compare, _Alloc>'
  178 |       set(const _Compare& __comp,
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:178:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:169:7: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set()-> std::set<_Key, _Compare, _Alloc>'
  169 |       set() = default;
      |       ^~~
/usr/include/c++/14/bits/stl_set.h:169:7: note:   template argument deduction/substitution failed:
a.cc:110:5: note:   couldn't deduce template parameter '_Key'
  110 | set em;
      |     ^~
/usr/include/c++/14/bits/stl_set.h:96:11: note: candidate: 'template<class _Key, class _Compare, class _Alloc> set(std::set<_Key, _Compare, _Alloc>)-> std::set<_Key, _Compare, _Alloc>'
   96 |     class set
      |           ^~~
/usr/include/c++/14/bits/stl_set.h:96:11: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:970:5: note: candidate: 'template<class _Key, class _Allocator, class> std::set(initializer_list<_Tp>, _Allocator)-> set<_Key, less<_Key>, _Allocator>'
  970 |     set(initializer_list<_Key>, _Allocator)
      |     ^~~
/usr/include/c++/14/bits/stl_set.h:970:5: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:963:5: note: candidate: 'template<class _InputIterator, class _Allocator, class, class> std::set(_InputIterator, _InputIterator, _Allocator)-> set<typename iterator_traits<_Iter>::value_type, less<typename iterator_traits< <template-parameter-1-1> >::value_type>, _Allocator>'
  963 |     set(_InputIterator, _InputIterator, _Allocator)
      |     ^~~
/usr/include/c++/14/bits/stl_set.h:963:5: note:   candidate expects 3 arguments, 0 provided
/usr/include/c++/14/bits/stl_set.h:956:5: note: candidate: 'template<class _Key, class _Compare, class _Allocator, class, class> std::set(initializer_list<_Tp>, _Compare, _Allocator)-> set<_Key, _Compare, _Allocator>'
  956 |     set(initializer_list<_Key>,
      |     ^~~
/usr/include/c++/14/bits/stl_set.h:956:5: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/14/bits/stl_set.h:947:5: note: candidate: 'template<class _InputIterator, class _Compare, class _Allocator, class, class, class> std::set(_InputIterator, _InputIterator, _Compare, _Allocator)-> set<typename iterator_traits<_Iter>::value_type, _Compare, _Allocator>'
  947 |     set(_InputIterator, _InputIterator,
      |     ^~~
/usr/include/c++/14/bits/stl_set.h:947:5: note:   candidate expects 2 arguments, 0 provided