結果

問題 No.2761 Substitute and Search
ユーザー hamo21hamo21
提出日時 2024-05-17 21:54:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,586 bytes
コンパイル時間 4,370 ms
コンパイル使用メモリ 279,324 KB
実行使用メモリ 44,832 KB
最終ジャッジ日時 2024-05-17 21:54:57
合計ジャッジ時間 10,596 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef int64_t ll;
using mint=modint998244353;

typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
ll vx[4]={0,1,0,-1};
ll vy[4]={1,0,-1,0};
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    a=abs(a);
    b=abs(b);
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    if(gcdmin==0)return gcdmax;
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll pow(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=pow(N,P/2,M);
        return t*t%M;
    }
    else return N*pow(N,P-1,M)%M;
}
ll pow(ll N,ll P){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=pow(N,P/2);
        return t*t;
    }
    else return N*pow(N,P-1);
}

vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}


struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N,L,Q;
    cin>>N>>L>>Q;
    vector<string> S(N);
    rep(i,N)cin>>S[i];
    vector<vector<ll>> nS(N,vector<ll>(L));
    rep(i,N)rep(j,L)nS[i][j]=S[i][j]-'a'; 
    vector<vector<set<ll>>> sets(L,vector<set<ll>>(26));
    rep(i,L){
        rep(j,26){
            sets[i][j].insert(j);
        }
    }
    rep(q,Q){
        ll t;
        cin>>t;
        if(t==1){
            ll k;
            char c,d;
            cin>>k>>c>>d;
            ll nc=c-'a';
            ll nd=d-'a';
            k--;
            for(ll x:sets[k][nc])sets[k][nd].insert(x);
            sets[k][nc].clear();
        }
        else{
            string s;
            cin>>s;
            ll n=s.size();
            vector<ll> ns(n);
            rep(i,n)ns[i]=s[i]-'a';
            ll ans=0;
            rep(i,N){
                bool tf=true;
                rep(j,n){
                    if(!sets[j][ns[j]].count(nS[i][j])){
                        tf=false;
                        break;
                    }
                }
                if(tf)ans++;
            }
            cout<<ans<<endl;
        }
    }
}
0