QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#135974 | #5726. Error Correction | Nicolas125841 | AC ✓ | 4ms | 3640kb | C++17 | 2.4kb | 2023-08-06 16:46:26 | 2023-08-06 16:47:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
bool find(int j, vector<vi>& g, vi& btoa, vi& vis) {
if (btoa[j] == -1) return 1;
vis[j] = 1; int di = btoa[j];
for (int e : g[di]) {
if (!vis[e] && find(e, g, btoa, vis)) {
btoa[e] = di;
return 1;
}
}
return 0;
}
int dfsMatching(vector<vi>& g, vi& btoa) {
vi vis;
rep(i,0,sz(g)) {
vis.assign(sz(btoa), 0);
for (int j : g[i]) {
if (find(j, g, btoa, vis)) {
btoa[j] = i;
break;
}
}
}
return sz(btoa) - (int)count(all(btoa), -1);
}
void c_graph(vector<vector<int>> &adj, vector<int> &color, int n, int col){
if(color[n] != -1){
assert(color[n] == col);
}else{
color[n] = col;
for(const int &v : adj[n])
c_graph(adj, color, v, 1 - col);
}
}
int main(){
cin.tie(NULL)->sync_with_stdio(false);
int n;
cin >> n;
vector<string> s(n);
for(int i = 0; i < n; i++)
cin >> s[i];
vector<vector<int>> adj(n, vector<int>());
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(i != j){
int diffs = 0;
for(int k = 0; k < s[i].size(); k++)
if(s[i][k] != s[j][k])
diffs++;
if(diffs == 2)
adj[i].push_back(j);
}
}
}
vector<int> color(n, -1);
for(int i = 0; i < n; i++)
if(color[i] == -1)
c_graph(adj, color, i, 0);
int r_part = 0;
unordered_map<int, int> b_mapping;
for(int i = 0; i < n; i++)
if(color[i])
b_mapping[i] = r_part++;
int ind = 0;
vector<vector<int>> b_adj(n - r_part, vector<int>());
for(int i = 0; i < n; i++){
if(!color[i]){
for(const int &v : adj[i])
b_adj[ind].push_back(b_mapping[v]);
ind++;
}
}
if(r_part == 0){
cout << n << "\n";
}else{
vector<int> btoa(r_part, -1);
cout << n - dfsMatching(b_adj, btoa) << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3472kb
input:
6 abc acb cab cba bac bca
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
11 alerts alters artels estral laster ratels salter slater staler stelar talers
output:
8
result:
ok single line: '8'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
6 ates east eats etas sate teas
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
11 cedab acbde adbce badce ecbda bdace dbaec cbdea abdce adecb cabde
output:
8
result:
ok single line: '8'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
6 bcda cadb dbac cbda abcd abdc
output:
4
result:
ok single line: '4'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
103 abcdefg abfdecg afbdecg afgdecb agbdecf abfcedg abdfecg ebdfacg abfedcg abdfceg abfdceg dbfeacg cbfdeag gbdfeca afcdegb agbdefc abcfedg bfcdega dbfceag dbcaefg afedcgb cbdfaeg dbfgace cbdaefg afedgcb egdfacb aecdbfg afcgedb cbeadfg aebdcfg cbegdfa fbdgace afdcegb afcbedg abdgfce abdcefg abefcdg ...
output:
58
result:
ok single line: '58'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
106 abcdefg abcedfg abedcfg fbcdeag abedgfc abcdgfe dbceafg bdceafg abcdfeg cbadfeg abdecfg abdgcfe fgcdeab abcefdg abcgfde cbafdeg baedgfc fcgdeab abdcgfe fbcgade fdcbeag abdgcef dbaecfg facgbde abedcgf fbcaedg abedfgc adcbfeg abfdcge aefdcgb facbgde abfdgce cdafbeg ebcdfag ebcdafg fbdaecg fcdgeab ...
output:
58
result:
ok single line: '58'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
11 abcd bacd dbca dbac dacb bdca bcad cbda cbad dabc bcda
output:
6
result:
ok single line: '6'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
129 abcdefg abgdefc abgcefd afgdebc fbcdeag agbdefc abcfedg cbafedg cbagedf abcfdeg bacfdeg cbgaedf bfgdeac gbcfeda afcbedg agedbfc fbgcead ebagcdf cbadegf dbcfeag gbfcead afcbdeg egabcdf ebfgcda abgfedc abcgefd dbagecf cbdfeag agedcfb cbadfge gbafedc agcbefd gbcefda cdabegf gbceadf ceafbdg acgbefd ...
output:
68
result:
ok single line: '68'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3488kb
input:
13 abcde acbde bcade acedb cabde dceab cadbe bcdae bacde badce dcbae acdbe aecdb
output:
7
result:
ok single line: '7'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
14 abcde abced cbade aecbd aecdb decba adcbe decab edcba bcade dbcae ebcad becad ebadc
output:
8
result:
ok single line: '8'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
15 abcde dbcae ebcad bdcae becad aecbd abdce decba dbace bdcea eacbd cbade edcba dacbe baced
output:
8
result:
ok single line: '8'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
155 abcdefg abcdfeg afcdbeg abgdfec gbcdfea gbcdaef gbadfec ebcdagf acbdefg ecbdafg ecfdabg gbcdefa acbgefd egbdafc abcdgef abcedfg edbgafc ebcdfga afgdbec abedfcg abfdceg abedcfg acbdegf agedfcb acedfbg ecbgafd dcbgefa ecfadbg afcdgeb dbcagef ebcagdf gbedacf gfadbec aebgcfd edcgafb fcbdaeg dfgabec ...
output:
81
result:
ok single line: '81'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
16 abcd bacd badc bdac cadb bcad acbd abdc dbac dcba cbda adcb adbc dabc cbad bdca
output:
8
result:
ok single line: '8'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
19 abcde cbade ebadc beadc bcade abced ceadb edabc aecdb acbde edacb acbed cdaeb cbaed abedc bdaec dcabe aebdc adbec
output:
10
result:
ok single line: '10'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
218 abcdef aecdbf abfdec ebfdac ebdfac aecfbd cbadef dbcaef afcebd cdabef aebfcd adcfbe dbeacf cdaebf afcedb cbedaf cdafbe aefcbd decfba ebdafc aefbcd ceadbf cdfbea fecabd febacd fbadec aebcfd befacd bfceda afcdbe bdcaef fdacbe aefdbc adcbef ceabdf cdefba fdbcae ceafbd adbfce abedcf abdefc feabdc ce...
output:
116
result:
ok single line: '116'
Test #17:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
231 abcdef abfdec abcfed cbadef abcedf aecdbf abedfc abecdf cbfdea ebacdf dbcaef aecfbd abdfec ebcadf dbacef cabdef abcfde dfaceb abcdfe afecdb dbcafe abfedc adcebf ebadcf fbcade cbdafe faecdb cbafed bacdef acebdf badcef cadbfe facedb fbceda dfaecb fbecda bacedf baedcf bfceda abefdc adcfbe ecabdf ef...
output:
117
result:
ok single line: '117'
Test #18:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
236 abcdef cbadef dbcaef fbcdea abcdfe fbcdae fbcade acbdfe fdcabe fecdba facdeb dcbaef abedcf cbadfe afcdeb acbdef dcbafe debacf fecdab fdcbea ecbdaf bacdef dacbef bcadfe deabcf cbfdea adcbef fecbad fbceda debafc adbcef cbfade dbacef bacdfe cbfdae badcef fbcaed fedcba dcabef fbcead deacbf dbceaf ac...
output:
122
result:
ok single line: '122'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
241 abcdef abedcf abfdce aefdcb adfbce edfbca aefbcd eafbcd eabfcd ecfbda bdfeca efbacd abdecf bafecd dafbce ebfacd dacbfe efbcad bacefd efdcab aedbcf efbcda fbadce abedfc acfdbe befdca bdaecf efacbd fadbce abecdf acfbde adbecf ecfbad aefcdb fdaecb aefbdc dcfbea bcfead becafd bcaefd acfbed afbced ef...
output:
123
result:
ok single line: '123'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
253 abcdefg abcdfeg fbcdaeg abfdecg abcgefd cbadefg abcdgef agfdecb aecdbfg abcgdfe abfgecd abcgdef abcdgfe fbgdaec cgfdeab cgfaedb aecdbgf ebgdafc decabfg adcbgfe gbfdaec ebgadfc abcfdeg ebcdafg eacdbgf abcgedf abfegcd cbafedg cabdefg ebgadcf adcebfg abgedcf cgfedab agfdebc abfdceg dbgeafc abcegdf ...
output:
129
result:
ok single line: '129'
Test #21:
score: 0
Accepted
time: 2ms
memory: 3532kb
input:
255 abcdef cbadef dbcaef fbcdea abcdfe fbcdae fbcade acbdfe fdcabe fecdba facdeb dcbaef abedcf cbadfe afcdeb acbdef dcbafe debacf fecdab fdcbea ecbdaf bacdef dacbef bcadfe deabcf cbfdea adcbef fecbad fbceda debafc adbcef cbfade dbacef bacdfe cbfdae badcef fbcaed fedcba dcabef fbcead deacbf dbceaf ac...
output:
131
result:
ok single line: '131'
Test #22:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
27 abcde abedc abdce dbace ebadc acdbe ebcda adcbe baedc bceda dabce dbcae beadc dacbe dcbae bcdae aebdc aebcd bacde bedac bdcae dceab ebdac cbdae bcade badce acedb
output:
14
result:
ok single line: '14'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
29 abcde aecdb aecbd abced dbcea acbde ebcda decab dcbea aebdc adbec cdbea abdec adceb cdaeb aebcd adbce debca acdeb bdaec dceab acbed ebadc cdabe dabce cbaed beadc cbade adcbe
output:
15
result:
ok single line: '15'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
31 abcde adcbe ebcda ebcad adebc ebadc dbaec abced edcba bdcea aecdb eacbd adceb adecb abedc cbeda baced dacbe dbcea caedb cadbe daceb edcab acedb becda cdeab cbdae cdeba aecbd decab acdeb
output:
16
result:
ok single line: '16'
Test #25:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
36 abcdef abedcf ebadcf adcbef dbcaef acedbf acdbef abcfed afcbed adcbfe abcedf cbdaef cbadef ebafcd abfced dfcaeb fbceda bfcaed abfdec bcdaef ecadbf dfceab dbeacf aecfbd dbfcea decfab abdcef cbfaed abcfde cbfdea cbaedf fcadbe acbfde bacdef acbedf adcfbe
output:
19
result:
ok single line: '19'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3480kb
input:
37 abcde adcbe acdbe adceb ebcda acbde edcba ebdca bacde adbce adbec dabce ebacd aecdb eacdb acbed edbca dacbe cbade adebc becda eabcd daceb abced edabc cabde baced ebadc abdce cadbe eadcb abecd ebcad beadc edbac cbaed edacb
output:
20
result:
ok single line: '20'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
38 abcde ebcda abdce abecd dbeca dbeac debca abedc bdeac acdbe daecb debac deacb dceab aedbc dcaeb cbeda bedac badec dbcea ebdac bedca decba baedc adcbe caedb badce eadbc dbace acbde bdcae dcabe edcba ebdca aebcd aebdc cbead dcbea
output:
20
result:
ok single line: '20'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
41 abcde cbade ceadb dbace abdce adcbe acbde aecbd adbce edcba adebc ebcda ebadc cebda cdeba adecb cdbea aebdc bdace cedab dbcea acdbe dcabe aebcd abced aedbc aecdb ebcad abedc baedc abdec dcbae edcab acbed beadc deabc cbeda edacb deacb edabc dbcae
output:
21
result:
ok single line: '21'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
45 abcdef adcbef cdabef adebcf abcedf acdbef bacedf afdbec cfdbea dacebf dcaebf abdecf baecdf eacdbf badcef dabcef cdebaf cedbfa dcebaf afdbce cdbaef acbdef dafceb decbfa daecbf bdcaef edcabf dfcbea afbdec edcbaf becadf adcebf bdceaf afbdce dfbaec adebfc afdebc decbaf adbecf fecbda aecbfd afbced fec...
output:
24
result:
ok single line: '24'
Test #30:
score: 0
Accepted
time: 3ms
memory: 3560kb
input:
500 abcdefg ebcdafg ebgdafc ebgdcfa egbdcfa egbcdfa edbgcfa agbcdfe ebfdagc dbcaefg abgcdfe egfcdba decabfg begdafc edbcgfa gebdcfa fecabdg begdcfa fdbgcea bagdefc begdfca dacebfg gebcdfa ebgcdfa fbgdcea edbcgaf fbcdgea acbgdfe dacfbeg eacdbfg ebfcdga edgcbfa cbfdage badgefc abgdefc agdcbfe begdacf ...
output:
260
result:
ok single line: '260'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
54 abcde aecdb adceb adbec aecbd abced abdec acbed becda adcbe decba bacde bedca ebcda acedb cedba bcdea cbdea beadc eacdb bedac dacbe aebcd decab cdbea daceb abecd cdaeb bcdae cbeda cbade cdeab baced acdeb cabde dcaeb cdbae aedbc ebadc acbde dbcea cdabe debca cadeb ceabd bdcea cebda badce ecbad bde...
output:
28
result:
ok single line: '28'
Test #32:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
58 abcde adcbe dacbe daceb abdce bacde aedcb eadcb decba badce cdabe adbce dbcae ebcad baedc daecb ebdca cedab dabec aedbc cdeab daebc aebcd bedca dabce ebcda cadeb cebad aebdc eadbc ecdab aecdb cbdea decab baecd adecb dcbea becda ebdac ecadb ecdba edcba dbcea dceab bedac ceadb cebda caedb dceba bea...
output:
31
result:
ok single line: '31'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
97 abcdefg abfdecg fbcdeag ebcdfag adcbefg becdfag ebfdcag ebcdafg ebfdacg adfbecg adcfebg cbadefg bacdfeg adgbecf agfbecd abfedcg ebfdgca egfdcab ecfdbag fgcdeab bfcdeag agbfecd ebfacdg fgdceab fgcaedb cdfbeag efcdbag ebfadcg acfdebg ebcdgaf abfcedg afgbecd adcfbeg begdfac dbfaceg befdacg acfdgbe b...
output:
51
result:
ok single line: '51'
Test #34:
score: 0
Accepted
time: 3ms
memory: 3580kb
input:
500 abcdefg abfdecg dbfaecg dbcaefg cbdaefg cbadefg fbdaecg fbadecg dbacefg abdcefg abdfecg dbafecg abcfedg fbcaedg abfcedg cbfaedg fbacedg cbafedg dbfceag cbfdeag dbcfeag cbdfeag fbdceag fbcdeag abfcegd abfgecd fbagecd fbacegd fbcaegd fbgaecd abcfegd abgfecd fbcgead fbgcead abcgefd abgcefd cbfgead ...
output:
250
result:
ok single line: '250'
Test #35:
score: 0
Accepted
time: 3ms
memory: 3616kb
input:
500 abcdefg abgdefc adgbefc abgdfec agdbefc gadbefc gbdaefc adgcefb eadbgfc edgcafb gedabfc dagcefb agbdefc gbcdefa adfcegb acgbefd cbgdefa afgbedc adbcegf aebcdgf dbgafec gabdefc edfcagb abgedfc abgfdec fbcdeag edbcafg fdacegb acbedgf gdacefb gbdfeac debcafg debcfag acgbedf gfabedc cfabedg adcgefb ...
output:
264
result:
ok single line: '264'
Test #36:
score: 0
Accepted
time: 3ms
memory: 3552kb
input:
500 abcdefg agcdefb acgdefb gacdefb acgfedb agcedfb adcgefb agcdebf adegcfb abdcefg aedgcfb abcfedg bacdefg agedcbf gadcefb gbcdefa abdcegf adefcgb gcadefb adgcefb gcbdefa gacedfb abgcedf facdegb adbgcfe adbgcef gadecfb dabgcef abgdefc dacbefg afcdebg bacdegf fcgaedb abdcfge gafcedb agdcebf adcgbfe ...
output:
260
result:
ok single line: '260'
Test #37:
score: 0
Accepted
time: 4ms
memory: 3640kb
input:
500 abcdefghijklmnopqrstuvwxyz abcdefghkjilmnopqrstuvwxyz abqdefghijklmnopcrstuvwxyz abcdefghkjilvnopqrstumwxyz abydefghkjilmnopqrstuvwxcz abcdefghxjilvnopqrstumwkyz abcdefghkjplvnoiqrstumwxyz abydefghxjilvnopqrstumwkcz abcuefghkjilvnopqrstdmwxyz abqdefghijklmnopcrstuxwvyz abkdefghcjplvnoiqrstumwxyz...
output:
299
result:
ok single line: '299'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
46 dtyxpmfskh dtyxpmhsfk dtkxpmysfh htyxpmksfd dytxpmksfh dtpxymksfh ktyxpmdsfh dtxypmksfh xtydpmksfh dxytpmksfh dtypxmksfh dtyxpfksmh dtyspmkxfh tdyxpmksfh dtyxhmksfp dtyxfmksph styxpmkdfh dkyxpmtsfh dtyxpmksfh dtyxmpksfh dtfxpmksyh dtmxpyksfh dsyxpmktfh dhyxpmksft dpyxtmksfh dthxpmksfy dtyfpmksxh ...
output:
45
result:
ok single line: '45'
Test #39:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
326 zgmkhqbujleaydncsixprfwtov zgmklqbujheaytncsixprfwdov zgmklqbujhaeydncsixprfwtov zgmkbqlujheaydncsixprfwtov zgmklqbujheaydncstxprfwiov zgmksqbujheaydnclixprfwtov zgmkiqbujheaydncslxprfwtov zgmkltbujheaydncsixprfwqov zgmklbqujheaydncsixprfwtov zgmklqbujheaydtcsixprfwnov zgmklqbujweaydncsixprfhtov...
output:
325
result:
ok single line: '325'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
3 abc cab bca
output:
3
result:
ok single line: '3'
Test #41:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
12 cbad bdac dabc dbca bacd cadb cdba acbd adcb dcab abdc bcda
output:
12
result:
ok single line: '12'
Test #42:
score: 0
Accepted
time: 1ms
memory: 3540kb
input:
60 dcabe deacb edabc bceda daebc badec beadc dbcae debac abdce dceab cbdea becad eabdc ecdba ceabd eacbd dcbea eadcb bcaed baecd dbaec bacde bdcea ecbad aecdb adbec dabce cdeba ebcda daceb ebdac cadbe edbca cebda adcbe cbade abced bdace edcab acebd aebcd aedbc acbde bcdae decba cedab acdeb cdaeb cdb...
output:
60
result:
ok single line: '60'
Test #43:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
1 z
output:
1
result:
ok single line: '1'
Test #44:
score: 0
Accepted
time: 4ms
memory: 3604kb
input:
500 ptjidlcorhnveyzuqbsmwkgfax dpsgxbnctoeuwqymlajvzfrkih xjuaohrdtesgicymwbkzqplvfn bcjdzmilagkrphoqvfuxwtysen fwevdaintrojmsplukyzgxcqbh tldjepqmrzkbyixncfsuwohvga holunparwvcsdxgqtkyimezfjb anivbfpcstozmlguykxrhqwjde daljvpbzhgcorwfysxmqkuiten fazbidpxnhygojcversmukwtlq adexbizrkmfnoqcjwyhugtspvl...
output:
500
result:
ok single line: '500'
Test #45:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
8 edbac abedc acedb dbeac cadeb acebd ecadb baedc
output:
6
result:
ok single line: '6'