結果

問題 No.2761 Substitute and Search
ユーザー KudeKude
提出日時 2024-05-17 22:12:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,976 bytes
コンパイル時間 3,961 ms
コンパイル使用メモリ 283,172 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-17 22:12:37
合計ジャッジ時間 12,926 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

int conv[3010][26];
int inv[3010][26];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, l, q;
  cin >> n >> l >> q;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(all(s));
  rep(j, l) rep(c, 26) conv[j][c] = inv[j][c] = c;
  rep(_, q) {
    int type;
    cin >> type;
    if (type == 1) {
      int k;
      char c, d;
      cin >> k >> c >> d;
      k--;
      int ci = c - 'a', di = d - 'a';
      if (inv[k][ci] == -1) continue;
      if (inv[k][di] == -1) {
        int x = inv[k][ci];
        inv[k][ci] = -1;
        inv[k][di] = x;
        conv[k][x] = di;
      } else {
        int x = inv[k][ci];
        int y = inv[k][di];
        rep(i, n) if (s[i][k] - 'a' == x) s[i][k] = 'a' + y;
        sort(all(s));
        conv[k][x] = inv[k][ci] = -1;
      }
    } else {
      string t;
      cin >> t;
      bool ok = true;
      rep(j, ssize(t)) {
        if (inv[j][t[j] - 'a'] == -1) {
          ok = false;
          break;
        }
        t[j] = 'a' + inv[j][t[j] - 'a'];
      }
      if (!ok) {
        cout << 0 << '\n';
      } else {
        auto from = lower_bound(all(s), t);
        t.back()++;
        auto to = lower_bound(all(s), t);
        cout << to - from << '\n';
      }
    }
  }
}
0