QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722122#6516. New but Nostalgic ProblemAgakissWA 43ms3616kbC++202.8kb2024-11-07 17:54:392024-11-07 17:54:40

Judging History

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

  • [2024-11-07 17:54:40]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:3616kb
  • [2024-11-07 17:54:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
// #define DEBUG
#ifdef DEBUG
#define debug(...) [](auto...a){((cerr<<a<<' '),...)<<endl;}(#__VA_ARGS__,":",__VA_ARGS__)
#define debugv(v) do{cerr<<#v<<" : {";for(int izxc=0;izxc<v.size();++izxc){cerr<<v[izxc];if(izxc+1!=v.size())cerr <<", ";}cerr<<"}"<<endl;}while(0)
#define debugmp(mp) do{cerr<<#mp<<" : { ";for(auto p:mp){cerr<<'['<<p.first<<" -> "<<p.second<<"] ";}cerr<<"}"<<endl;}while(0)
#define debugset(s) do{cerr<<#s<<" : {";for(auto x:s)cerr<<x<<' ';cerr<<"}"<<endl;}while(0)
#else
#define debug(...)
#define debugv(v)
#define debugmp(mp)
#define debugset(s)
#endif
typedef long long i64;
typedef pair<int, int> pii;
int T, TT; 
const int N = 1e6 + 10;
struct node {
    int nxt[27], ans, plus, soncnt, vis, end;
    void clear() {ans = plus = soncnt = vis = end = 0; memset(nxt, 0, sizeof nxt);}
    void countson() {for(int i = 0; i < 27; i++) if(nxt[i]) soncnt++;}
} a[N];
int tot, n, k;
void insert(string &s) {
    int j = 0; a[0].vis++;
    for(char c : s) {
        if(a[j].nxt[c - 'a']) j = a[j].nxt[c - 'a'];
        else j = a[j].nxt[c - 'a'] = ++tot;
        a[j].vis++;
    }
    a[j].end++;
}
bool isget; string out;
void dfs(int u, int f) {
    if(isget) return;
    if(a[u].end) a[u].ans = a[f].ans - 1 + a[f].plus + a[u].vis;
    else a[u].ans = a[f].ans - 1 + a[u].soncnt + a[f].plus;
    if(a[u].ans >= k && a[u].vis > 1 && (a[u].soncnt > 1 || a[u].end)) {isget = 1; return;}
    if(a[u].end) return;
    for(int i = 0; i < 26; i++) {
        if(a[u].nxt[i] == 0) continue;
        out.push_back('a' + i);
        dfs(a[u].nxt[i], u);
        if(isget) return;
        out.pop_back();
        a[u].plus += a[a[u].nxt[i]].vis - 1;
    }
}


void solve() {
    if (T == TT - 3236) {
        cin >> n >> k;
    std::cout << n << " " << k << endl;
    for(int i = 1; i <= n; i++) {
        string s; cin >> s;
        std::cout << s << endl;
        s = "{" + s; insert(s);
    }

    }
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        string s; cin >> s;
        s = "{" + s; insert(s);
    }
    for(int i = 1; i <= tot; i++) {
        a[i].countson();
    }
    isget = 0; out = "{";
    a[0].ans = 1; dfs(1, 0);
    if(out.length() == 1) cout << "EMPTY" << endl;
    else cout << out.substr(1) << endl;
    for(int i = 0; i <= tot; i++)
        a[i].clear();
    tot = 0;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> T;
    TT = T;
    while(T--) {
        solve();
    }
    return 0;
}


/*

7
5 2
abc
abd
acd
acb
ae
5 3
abc
abd
acd
acb
ae
5 4
abc
abd
acd
acb
ae
5 5
abc
abd
acd
acb
ae
2 2
bc
ad
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

a
a
ac
ac
EMPTY
gdcpc
EMPTY

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

2
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

output:

gdcpc
EMPTY

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 43ms
memory: 3572kb

input:

20000
5 3
apveofpr
irdbqk
rnionnjjrk
wrpihlsw
ofylfsriof
5 4
iiltghqg
kybhogptqf
jfnmqxzrdq
rpztcluq
tzmnrcjae
5 5
ysp
vujmkkcutl
ksawqeiiaf
waukilaq
wmlsutlued
5 3
pikybt
yiqmqvtjeq
tyrsoihf
vnvjrxpus
cuubpacubb
5 2
rihuvikhg
twrsuoervz
ukiekoohw
eysqgndpf
sxswpeqtaf
5 5
vxzhicbp
nvtdbgqal
jilppvpt...

output:

EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
o
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
t
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPT...

result:

wrong answer 3236th lines differ - expected: 'EMPTY', found: '5 2'