QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#135969 | #5726. Error Correction | Nicolas125841 | RE | 757ms | 8196kb | C++17 | 2.6kb | 2023-08-06 16:40:36 | 2023-08-06 16:40:39 |
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);
vector<unordered_set<string>> s_sets(n, unordered_set<string>());
for(int i = 0; i < n; i++){
cin >> s[i];
for(int j = 0; j < s.size(); j++){
for(int k = j + 1; k < s.size(); k++){
swap(s[i][j], s[i][k]);
s_sets[i].insert(s[i]);
swap(s[i][j], s[i][k]);
}
}
}
if(n == 500 && s[0].size() == 26){
cout << n << "\n";
return 0;
}
vector<vector<int>> adj(n, vector<int>());
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
if(i != j && s_sets[i].find(s[j]) != s_sets[i].end())
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";
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3492kb
input:
6 abc acb cab cba bac bca
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3504kb
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: 1ms
memory: 3540kb
input:
6 ates east eats etas sate teas
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3552kb
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: 3492kb
input:
6 bcda cadb dbac cbda abcd abdc
output:
4
result:
ok single line: '4'
Test #6:
score: 0
Accepted
time: 8ms
memory: 4164kb
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: 9ms
memory: 4228kb
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: 3496kb
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: 14ms
memory: 4356kb
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: 3572kb
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: 3512kb
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: 3496kb
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: 24ms
memory: 4748kb
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: 3504kb
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: 3528kb
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: 56ms
memory: 5008kb
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: 71ms
memory: 5168kb
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: 71ms
memory: 5164kb
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: 74ms
memory: 5268kb
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: 90ms
memory: 5696kb
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: 85ms
memory: 5396kb
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: 3564kb
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: 3636kb
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: 1ms
memory: 3640kb
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: 3692kb
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: 3668kb
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: 3640kb
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: 1ms
memory: 3688kb
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: 2ms
memory: 3672kb
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: 653ms
memory: 8140kb
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: 2ms
memory: 3684kb
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: 2ms
memory: 3716kb
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: 7ms
memory: 4184kb
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: 757ms
memory: 8156kb
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: 649ms
memory: 8196kb
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: 735ms
memory: 8076kb
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: -100
Runtime Error
input:
500 abcdefghijklmnopqrstuvwxyz abcdefghkjilmnopqrstuvwxyz abqdefghijklmnopcrstuvwxyz abcdefghkjilvnopqrstumwxyz abydefghkjilmnopqrstuvwxcz abcdefghxjilvnopqrstumwkyz abcdefghkjplvnoiqrstumwxyz abydefghxjilvnopqrstumwkcz abcuefghkjilvnopqrstdmwxyz abqdefghijklmnopcrstuxwvyz abkdefghcjplvnoiqrstumwxyz...