QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#66569#5161. Last Guesskaruna#RE 3ms3520kbC++172.7kb2022-12-08 23:43:372022-12-08 23:43:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-08 23:43:38]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3520kb
  • [2022-12-08 23:43:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int L[30], R[30];
bool allowed[505][30];

struct edge {
    int u, v, c, r;
};
vector<edge> gph[1010];
void add_edge(int u, int v, int c) {
    gph[u].push_back({ u, v, c, (int)gph[v].size() });
    gph[v].push_back({ v, u, 0, (int)gph[u].size() - 1 });
}

int st[1010];
int dfs(int v, int f, int snk) {
    if (v == snk) return f;
    while (st[v] < gph[v].size()) {
        auto s = gph[v][st[v]++];
        auto t = gph[s.v][s.r];
        if (s.c == 0) continue;
        int g = dfs(s.v, min(f, s.c), snk);
        if (g) {
            gph[s.u][t.r].c -= g;
            gph[t.u][s.r].c += g;
            return g;
        }
    }
    return 0;
}
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    int g, l; cin >> g >> l;
    for (int i = 0; i < 30; i++) R[i] = l;
    for (int i = 0; i < l; i++) for (int j = 0; j < 30; j++) {
        allowed[i][j] = 1;
    }
    for (int i = 0; i < g - 1; i++) {
        string S, T; cin >> S >> T;

        int cnt[30]{}, y[30]{};
        for (int j = 0; j < l; j++) {
            cnt[S[j] - 'a']++;
            if (T[j] == 'G' || T[j] == 'Y') {
                y[S[j] - 'a']++;
            }
        }
        for (int j = 0; j < 30; j++) {
            if (cnt[j] == y[j]) {
                L[j] = max(L[j], y[j]);
            }
            else {
                L[j] = R[j] = y[j];
            }
        }
        for (int j = 0; j < l; j++) {
            if (T[j] != 'G') {
                allowed[j][S[j] - 'a'] = 0;
            }
            else {
                for (int k = 0; k < 30; k++) allowed[j][k] = 0;
                allowed[j][S[j] - 'a'] = 1;
            }
        }
    }

    int src = l + 30, snk = l + 31;
    int fsrc = l + 32, fsnk = l + 33;

    for (int i = 0; i < 30; i++) {
        add_edge(src, i, R[i] - L[i]);
        add_edge(fsrc, i, L[i]);
        add_edge(src, fsnk, L[i]);
    }
    for (int i = 0; i < l; i++) for (int j = 0; j < 30; j++) {
        if (allowed[i][j]) {
            add_edge(j, i + 30, 1);
        }
    }
    for (int i = 0; i < l; i++) {
        add_edge(i + 30, snk, 1);
    }
    add_edge(snk, src, 101010);

    int f = dfs(fsrc, 1e9, fsnk);
    while (f) {
        fill(st, st + 1010, 0);
        f = dfs(fsrc, 1e9, fsnk);
    }
    fill(st, st + 1010, 0);
    f = dfs(src, 1e9, snk);
    while (f) {
        fill(st, st + 1010, 0);
        f = dfs(src, 1e9, snk);
    }

    for (int i = 0; i < l; i++) {
        for (auto x : gph[i + 30]) {
            if (0 <= x.v && x.v < 30 && x.c != 0) {
                cout << (char)(x.v + 'a');
                break;
            }
        }
    }    
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3520kb

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

score: 0
Accepted
time: 2ms
memory: 3460kb

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabgcdabbded

result:

ok 

Test #3:

score: -100
Checker Dangerous Syscalls

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:

}~~|{~~zy~~xw~~vu~~ts~~rp~~nm~~lk~~ji~~hg~~fe~~dc~~bb~~cd~~ef~~gh~~ij~~kl~~mn~~rp~~ts~~vu~~xw~~zy~~oo~~oa~~a~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~...

result: