QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759749#9558. The DevilIllusionaryDominanceRE 1464ms440356kbC++204.2kb2024-11-18 11:46:542024-11-18 11:47:01

Judging History

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

  • [2024-11-18 11:47:01]
  • 评测
  • 测评结果:RE
  • 用时:1464ms
  • 内存:440356kb
  • [2024-11-18 11:46:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef vector <int> vi;

const int MAX_N = 130;
const int MAX_M = 1 << 21;
const int MAX_V = 1 << 15;
const int MAX_E = 1 << 17;
const int INF32 = 0x3f3f3f3f;

int N, s, t;
struct TrieNode{
    int son[52], dep;
}node[MAX_M];
int tot, cur[MAX_N], cnt, idx[MAX_M], w[MAX_V], M;
struct Edge{
    int y, prev, cap, cost;
}e[MAX_E];
int elast[MAX_V], ecnt = 1;
int dis[MAX_V], pre[MAX_V], flow;
char inq[MAX_V], vis[MAX_M];
string ans[MAX_N], pat[MAX_V];

void Build(int x, int y, int z, int c) {
    ecnt ++;
    e[ecnt].y = y;
    e[ecnt].cap = z;
    e[ecnt].cost = c;
    e[ecnt].prev = elast[x];
    elast[x] = ecnt;
}

void add_edge(int x, int y, int z, int c) {
    Build(x, y, z, c); Build(y, x, 0, -c);
}

bool spfa() {
	queue <int> q;
	memset(dis, 0x3f, sizeof(int) * (t + 1));
	q.push(s); dis[s] = 0;
	while (!q.empty()) {
		int u = q.front(); q.pop(); inq[u] = 0;
		for (int i = elast[u]; i; i = e[i].prev) {
			int v = e[i].y;
			if (e[i].cap && dis[u] + e[i].cost < dis[v]) {
                pre[v] = i;
				dis[v] = dis[u] + e[i].cost;
				if (!inq[v]) {
					inq[v] = 1; q.push(v);
				}
			}
		}
	}
    if (dis[t] >= INF32) return false;
    int f = N;
    for (int v = t; v != s; v = e[pre[v] ^ 1].y) f = min(f, e[pre[v]].cap);
    for (int v = t; v != s; v = e[pre[v] ^ 1].y) {
        e[pre[v]].cap -= f;
        e[pre[v] ^ 1].cap += f;
    }
    flow += f;
    return true;
}

vi ins(const vi &s, int u, const vi &a) {
    vi c(0);
    for (auto i = a.begin(), j = s.begin(); (int)c.size() < N; ) {
        while (i != a.end() && vis[*i]) i ++;
        if (i == a.end() && j == s.end()) break;
        if (j == s.end() || (i != a.end() && node[*i].dep <= node[u].dep + 1)) {
            c.push_back(*(i ++));
        }else {
            int &v = node[u].son[*(j ++)];
            if (!v) {
                v = ++ tot;
                node[v].dep = node[u].dep + 1;
            }
            u = v;
            if (!vis[v]) {
                c.push_back(v);
            }
        }
        vis[c.back()] = 1;
    }
    for (auto x : c) vis[x] = 0;
    return c;
}

void ins(const vi &s) {
    vi a(0);
    for (int i = 1; i <= cnt; i ++) {
        a = ins(s, cur[i], a);
    }
    cnt = a.size();
    for (int i = 1; i <= cnt; i ++) {
        cur[i] = a[i - 1];
    }
}

void dfs(int u, string &s) {
    if (idx[u]) {
        pat[idx[u]] = s;
    }
    for (int i = 0; i < 52; i ++) {
        if (node[u].son[i]) {
            s.push_back((char)(i < 26 ? i + 'A' : i - 26 + 'a'));
            dfs(node[u].son[i], s);
            s.pop_back();
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    cin >> N;
    string trash;
    getline(cin, trash);
    for (int i = 1; i <= N; i ++) {
        vi s;
        string t;
        getline(cin, t);
        cur[cnt = 1] = 0;
        for (int j = 0, k; j < (int)t.size(); j ++) {
            for (k = j; k < (int)t.size() && t[k] != ' '; k ++);
            s.resize(k - j);
            auto it = s.begin();
            while (j < k) {
                *it = t[j] <= 'Z' ? t[j] - 'A' : t[j] - 'a' + 26;
                j ++; it ++;
            }
            assert(it == s.end());
            ins(s);
        }
        assert(cnt <= N);
        for (int j = 1; j <= cnt; j ++) {
            if (!idx[cur[j]]) {
                idx[cur[j]] = ++ M;
                w[M] = node[cur[j]].dep;
            }
            add_edge(i, N + idx[cur[j]], 1, 0);
        }
    }
    string sta;
    dfs(0, sta);
    s = M + N + 1; t = s + 1;
    for (int i = 1; i <= N; i ++) {
        add_edge(s, i, 1, 0);
    }
    for (int i = 1; i <= M; i ++) {
        add_edge(i + N, t, 1, w[i]);
    }
    while (spfa());
    if (flow < N) {
        cout << "no solution\n";
        return 0;
    }
    for (int i = 2; i <= ecnt; i += 2) {
        auto [y, trash1, cap, trash2] = e[i];
        auto [x, trash3, rcap, trash4] = e[i ^ 1];
        if (x <= N && rcap) {
            ans[x] = pat[y - N];
        }
    }
    for (int i = 1; i <= N; i ++) {
        cout << ans[i] << '\n';
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9012kb

input:

5
automated teller machine
active teller machine
active trouble maker
always telling misinformation
American Teller Machinery

output:

autm
atem
actm
atm
ATM

result:

ok len=18

Test #2:

score: 0
Accepted
time: 0ms
memory: 10768kb

input:

5
Forest Conservation Committee Forum
Fuming Corruption Collusion Federation
Fulsome Cash Concealment Foundation
Funky Crony Capitalism Facilitator
Funny Cocky Cocky Funny

output:

FoCCF
FCoCF
FCaCF
FuCCF
FCCF

result:

ok len=24

Test #3:

score: 0
Accepted
time: 1ms
memory: 9920kb

input:

3
A AA
AA A
A A A

output:

no solution

result:

ok len=-1

Test #4:

score: 0
Accepted
time: 1ms
memory: 8716kb

input:

2
QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnmertyuiop
Q W E R T Y U I O P A S D F G H J K L Z X C V B N M q w e r t y u i o p a s d f g h j k l z x c v b n m j k l z x c v b n m

output:

Q
QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnmjklzxcvbnm

result:

ok len=63

Test #5:

score: 0
Accepted
time: 1ms
memory: 8768kb

input:

10
aaa aaa aaa aaa aaa aaa
aab aaa aaa aaa aaa aaa
aaa aab aaa aaa aaa aaa
aab aab aaa aaa aaa aaa
a a a a a a
ab ab a a a a a a
ab ab b a a a a a a
aw a a a a a
az az a a a a
az a a a a a

output:

aaaaaaaaa
aabaaaaa
aaabaaaa
aaaaaaa
aaaaaa
aaaaaaaa
aabaaaaaa
awaaaaa
aazaaaa
azaaaaa

result:

ok len=76

Test #6:

score: 0
Accepted
time: 1464ms
memory: 9368kb

input:

128
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

result:

ok len=24512

Test #7:

score: 0
Accepted
time: 1455ms
memory: 17556kb

input:

128
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaae aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccccccccccc...

result:

ok len=16534

Test #8:

score: 0
Accepted
time: 1077ms
memory: 10572kb

input:

128
zAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
zAzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
zAAzzzzzzzzz...

result:

ok len=17624

Test #9:

score: 0
Accepted
time: 816ms
memory: 440356kb

input:

128
abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a...

output:

abaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bcbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cdcccccccccccccccccccccccccccccccccccccc...

result:

ok len=16460

Test #10:

score: 0
Accepted
time: 1304ms
memory: 49164kb

input:

128
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccc...

result:

ok len=16384

Test #11:

score: 0
Accepted
time: 4ms
memory: 12464kb

input:

10
AoenrfWTxhAiSipaV cJGloMoCBombqBsVuorNWL gqrmsIZGthdBIvNPWjTGgssBfbctzPCvCmMJWN MDYvQBZCaCmwSFnvQOmolkTmwWgysKuVmByj EOwjzBEgECXizqAZukRFAxdvrRhsGcIzQsFUMcXw mVNxPkaPPKUZEpswrhOqJerzhvfVwcNoDceNZPaskxTEhlGCMIoSqvAg JCPAAkYZoGOxpFNCj tsNvJHyeVCZqOHKzVsLoMnprENEmGSSxFGDDOafIIMVAbUtUIkAqmnrXUnWWfkAl...

output:

AcgMEmJtQnptFcoksenMLQXoWgmMEMuxBJYTcICgaVNaTfoyuAvDOAnedNDDPPPwIGaDOnjIlUvbJTVVQFLk
HvApbVGYRBPuNjNkipYlWgO
ScgzHNitvtRoLuUisITjuWCLGelWKqYoIAnAmIWTLOeMVHndqytXTd
UBSuhtoimhfhdKivdyCqJxSbtnocRCEKicArQJKnRagqrJfNHY
WqlPqHsSnpHcIfqCalIrqubIpBXqTVRBOYYQqRCQqJzyHRbbSCLzxsXOzNxSxSXcPhfHkNKClKWBJbg
iLqfr...

result:

ok len=660

Test #12:

score: 0
Accepted
time: 122ms
memory: 181360kb

input:

64
AQLPmEKRHtLKaVeVgUBkYfECFrvhbsXorapjINwkXhyCmkexRIVAZTsXaOihheHjstls AiIegrwbTMbBFdDQHGMgyOahunXRrySnKEmfKXQkpWdtNpGdgdBtPGfdcdnUvEqkfmvmSRzevtZkhPzjhDhTVLQCbaozNEXlqUgHeRshchY SFwbzOhRAEybYCGswuldoWkKloHghqiDybxtJPdzAWjmqxw mcRhokiMnxgAucSnasFcEXpZdEGEGzEGaEBAfGNEQAgQSTFKrMvxoUZTDKQMHksaciHoYXih...

output:

AASmGWIMEJjHHnPlYRcjfOMPuKTjbyRxHmnMcJSXFigHUqxClyINhlMPJgLAZRXFEOGWcCIQvqaYBIhOPkeUVWKHJYow
CJenkhWcPeucbfOFBHxSdYqLgftApMsctvFlfKkZmavIfqWYNZpZKJKYPwMSuvaSubelMSQKFIymAZoMLIOqoHGlIbOAp
CejoeafHpVdTXKhgDGCAFivwKoSTwwBUDBdXYMWNlUBUttHXemMOHwlBiaqRUwYTIPqJvpowUFTSkqyAywInGlWgMfYXuFrw
DkivKkaYITyXOOVF...

result:

ok len=3658

Test #13:

score: -100
Runtime Error

input:

128
kfiaaudafulirmameczaaaaaaaaaaaaaaaaaaaaaaaaagaaaajaaaaaalaaqoaaa f i a a u d a f u l i r m a m e c z a a a a a a a a a a a a a a a a a a a a a a a a a g a a a a j a a a a a a l a a q o a a a
aaaoqaalaaaaaajaaaagaaaaaaaaaaaaaaaaaaaaaaaaazcemamrilufaduaaifk a a o q a a l a a a a a a j a a a a g a ...

output:


result: