結果

問題 No.1994 Confusing Name
ユーザー shoshoshom
提出日時 2022-07-01 23:49:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 877 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 205,236 KB
最終ジャッジ日時 2025-01-30 03:37:41
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

static inline void solve() {
  int n;
  cin >> n;
  vector<string> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }
  unordered_map<string, int> count;
  for (string &s : S) {
    int m = s.size();
    string t = s;
    for (int j = 0; j < m; j++) {
      t[j] = '.';
      count[t]++;
      t[j] = s[j];
    }
  }
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    string& s = S[i];
    int m = s.size();
    string t = s;
    for (int j = 0; j < m; j++) {
      t[j] = '.';
      ans[i] += count[t] - 1;
      t[j] = s[j];
    }
  }

  for (int a: ans) {
    cout << a << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
#ifdef LOCAL
  int T;
  cin >> T;
  for (int tc = 1; tc <= T; tc++) {
    cout << "Case" << tc << ":" << '\n';
    solve();
  }
#else
  solve();
#endif
  return 0;
}
0