結果

問題 No.1994 Confusing Name
ユーザー shoshoshomshoshoshom
提出日時 2022-07-01 22:23:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,005 bytes
コンパイル時間 2,674 ms
コンパイル使用メモリ 213,660 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-05-04 16:44:02
合計ジャッジ時間 6,302 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

static inline void solve() {
  int n;
  cin >> n;
  vector<pair<string, int>> S(n);
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    S[i] = {s, i};
  }
  sort(S.begin(), S.end());
  vector<int> ans(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (S[i].first.size() == S[j].first.size()) {
        string& a = S[i].first, b = S[j].first;
        int m = a.size();
        int diffs = 0;
        for (int k = 0; diffs < 2 && k < m; k++) {
          diffs += a[k] != b[k];
        }
        int add = diffs == 1 ? 1 : 0;
        ans[S[i].second] += add;
        ans[S[j].second] += add;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " \n"[i == n - 1];
  }
}

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