QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373825 | #2046. Confusing Login Names | KKT89 | 100 ✓ | 213ms | 3816kb | C++17 | 2.4kb | 2024-04-02 07:52:20 | 2024-04-02 07:52:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
template <class T>
bool chmax(T &a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
constexpr int INF = 1e9;
int memo[20][20];
void init_memo() {
rep(i, 0, 20) rep(j, 0, 20) memo[i][j] = INF;
}
int distance(string &s, string &t, int i, int j) {
auto &MEMO = memo[i][j];
if (MEMO != INF) return MEMO;
if (i >= s.size() && j >= t.size()) return MEMO = 0;
if (i >= s.size()) return MEMO = (int)t.size() - j;
if (j >= t.size()) return MEMO = (int)s.size() - i;
int ret = INF;
if (s[i] == t[j]) {
chmin(ret, distance(s, t, i + 1, j + 1));
} else {
chmin(ret, distance(s, t, i + 1, j ) + 1);
chmin(ret, distance(s, t, i , j + 1) + 1);
chmin(ret, distance(s, t, i + 1, j + 1) + 1);
}
rep(k, j + 1, t.size()) {
if (s[i] == t[k] && s[i + 1] == t[j]) {
chmin(ret, distance(s, t, i + 2, k + 1) + 1 + abs(k - (j + 1)));
}
}
rep(k, i + 1, s.size()) {
if (s[i] == t[j + 1] && s[k] == t[j]) {
chmin(ret, distance(s, t, k + 1, j + 2) + 1 + abs(k - (i + 1)));
}
}
return MEMO = ret;
}
signed main_() {
string s, t;
cin >> s >> t;
init_memo();
cout << distance(s, t, 0, 0) << endl;
}
signed main() {
while (1) {
int n, d;
cin >> n;
if (n == 0) break;
cin >> d;
vector<string> S(n);
rep(i, 0, n) {
cin >> S[i];
}
sort(S.begin(), S.end());
vector<pair<string, string>> ans;
rep(i, 0, n) {
rep(j, i + 1, n) {
init_memo();
// cerr << i << ", " << j << " = " << distance(S[i], S[j], 0, 0) << endl;
if (distance(S[i], S[j], 0, 0) <= d) {
ans.push_back({S[i], S[j]});
}
}
}
sort(ans.begin(), ans.end());
for (auto &x : ans) {
cout << x.first << "," << x.second << endl;
}
cout << ans.size() << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 213ms
memory: 3816kb
input:
5 1 tasaka tanka tanaka taniaka tanaak 19 2 fujimune gajimkure fakiure fojimrue ufajimore fajimure fiajimuore fakjiure fzajmiure fjimuro fajmurpa fjimre fiajiomre fajmrue fjaimuze fjmuire fajmiukre fjaimur fajmirue 200 1 kabe niikawa katsunuma nishikubo etsunari horayama kamishima chidu nakaya koshi...
output:
tanaak,tanaka tanaka,taniaka tanaka,tanka tanaka,tasaka 4 fajimure,fajmirue fajimure,fajmiukre fajimure,fajmrue fajimure,fakiure fajimure,fakjiure fajimure,fiajimuore fajimure,fjaimur fajimure,fjaimuze fajimure,fjimre fajimure,fjimuro fajimure,fojimrue fajimure,fujimune fajimure,fzajmiure fajimure,g...
result:
ok 570 lines