結果

問題 No.1994 Confusing Name
コンテスト
ユーザー t98slider
提出日時 2026-10-24 19:38:56
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 266 ms / 2,000 ms
+ 747µs
コード長 751 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,727 ms
コンパイル使用メモリ 361,960 KB
実行使用メモリ 22,576 KB
最終ジャッジ日時 2026-10-24 19:39:05
合計ジャッジ時間 8,475 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<string> a(n), b;
	b.reserve(10 * n);
	for(auto &&s : a){
		cin >> s;
		for(int j = 0; j < (int)s.size(); j++){
			char org = s[j];
			s[j] = '?';
			b.emplace_back(s);
			s[j] = org;
		}
	}
	sort(b.begin(), b.end());
	vector<int> cnt(b.size());
	for(int i = 0; i < b.size(); ){
		int p = i++;
		while(i < b.size() && b[i] == b[p]) i++;
		cnt[p] = i - p;
	}
	for(auto &&s : a){
		int ans = -s.size();
		for(int j = 0; j < (int)s.size(); j++){
			char org = s[j];
			s[j] = '?';
			int p = lower_bound(b.begin(), b.end(), s) - b.begin();
			ans += cnt[p];
			s[j] = org;
		}
		cout << ans << '\n';
	}
}
0