QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373823#2046. Confusing Login NamesKKT890 0ms0kbC++173.1kb2024-04-02 07:51:172024-04-02 07:51:18

Judging History

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

  • [2024-04-02 07:51:18]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-04-02 07:51:17]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while(cin >> n,n){
        int d; cin >> d;
        vector<string> s(n);
        for(int i=0;i<n;i++){
            cin >> s[i];
        }
        vector<vector<string>> v(n);
        for(int i=0;i<n;i++){
            // delete
            int m = s[i].size();
            for(int j=0;j<m;j++){
                v[i].push_back(s[i].substr(0,j)+s[i].substr(j+1));
            }
            // insert
            for(char c='a';c<='z';c++){
                string t = ""; t += c;
                for(int j=0;j<=m;j++){
                    v[i].push_back(s[i].substr(0,j)+t+s[i].substr(j));
                }
            }
            // replace
            for(char c='a';c<='z';c++){
                for(int j=0;j<m;j++){
                    char cc = s[i][j];
                    s[i][j] = c;
                    v[i].push_back(s[i]);
                    s[i][j] = cc;
                }
            }
            // swap
            for(int j=0;j+1<m;j++){
                swap(s[i][j],s[i][j+1]);
                v[i].push_back(s[i]);
                swap(s[i][j],s[i][j+1]);
            }
            sort(v[i].begin(), v[i].end());
            v[i].erase(unique(v[i].begin(), v[i].end()),v[i].end());
        }

        vector<pair<string,string>> res;
        // find pair
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                auto it = lower_bound(v[i].begin(), v[i].end(), s[j]);
                if(it != v[i].end() and *it == s[j]){
                    res.push_back({s[i],s[j]});
                }
                else if(d == 2){
                    for(auto &p:v[j]){
                        it = lower_bound(v[i].begin(), v[i].end(), p);
                        if(it != v[i].end() and *it == p){
                            res.push_back({s[i],s[j]});
                            break;
                        }
                    }
                }
            }
        }

        // output
        for(auto &p:res){
            if(p.first > p.second) swap(p.first,p.second);
        }
        sort(res.begin(), res.end());
        for(auto &p:res){
            cout << p.first << "," << p.second << "\n";
        }
        cout << res.size() << "\n";
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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:


result: