QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373825#2046. Confusing Login NamesKKT89100 ✓213ms3816kbC++172.4kb2024-04-02 07:52:202024-04-02 07:52:20

Judging History

你现在查看的是最新测评结果

  • [2024-04-02 07:52:20]
  • 评测
  • 测评结果:100
  • 用时:213ms
  • 内存:3816kb
  • [2024-04-02 07:52:20]
  • 提交

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