QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206581#5161. Last Guesswillow#RE 2ms3736kbC++173.1kb2023-10-07 21:25:132023-10-07 21:25:13

Judging History

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

  • [2023-10-07 21:25:13]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3736kb
  • [2023-10-07 21:25:13]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int g, l, least[26], most[26], cnt[26], cant[505][26], id, match[505], vis[505], clk, must[505], to[505];
char word[505], op[505], ans[505], ch[1005];
vector<int> G[505], need;
int Dfs(int u) {
    for(auto v : G[u]) {
        if(vis[v] != clk) {
            vis[v] = clk;
            if(!match[v] || Dfs(match[v])) {
                match[v] = u;
                to[u] = v;
                return 1;
            }
        }
    }
    return 0;
}
int main() {
    scanf("%d%d", &g, &l);
    fill(most, most + 26, l + 1);
    for(int i = 1; i <= l; ++ i)
        ans[i] = ' ';
    for(int i = 1; i < g; ++ i) {
        scanf("%s%s", word + 1, op + 1);
        fill(cnt, cnt + 26, 0);
        for(int j = 1; j <= l; ++ j) {
            int c = word[j] - 'a';
            if(op[j] == 'G') {
                ++ cnt[c];
                ans[j] = word[j];
            }
        }
        for(int j = 1; j <= l; ++ j) {
            int c = word[j] - 'a';
            if(op[j] == 'Y') {
                ++ cnt[c];
                cant[j][c] = 1;
            }
            else if(op[j] == 'B') {
                most[c] = min(most[c], cnt[c]);
                cant[j][c] = 1;
            }
        }
        for(int j = 0; j < 26; ++ j)
            least[j] = max(least[j], cnt[j]);
    }
    for(int i = 1; i <= l; ++ i)
        if(ans[i] != ' ')
            -- least[ans[i] - 'a'], -- most[ans[i] - 'a'];
    for(int i = 1; i <= l; ++ i) {
        if(ans[i] == ' ') {
            must[i] = 1;
            for(int j = 0; j < 26; ++ j) {
                if(!cant[i][j] && least[j] < most[j]) {
                    must[i] = 0;
                    break;
                }
            }
            need.push_back(i);
        }
    }
    for(int i = 0; i < 26; ++ i) {
        assert(least[i] >= 0);
        for(int k = id + 1; k <= id + least[i]; ++ k) {
            ch[k] = i + 'a';
        }
        for(int j = 1; j <= l; ++ j) {
            if(ans[j] == ' ' && !cant[j][i]) {
                for(int k = id + 1; k <= id + least[i]; ++ k) {
                    // G[k].push_back(j);
                    G[j].push_back(k);
                }
            }
        }
        id += least[i];
    }
    sort(need.begin(), need.end(), [](int x, int y) {
        return must[x] > must[y];
    });
// cerr << id << endl;
// for(int i = 1; i <= id; ++ i)
//     cerr << ch[i] << " ";
// cerr << endl;
    int matcnt = 0;
    for(auto w : need) {
        ++ clk;
        // assert(Dfs(w));
        matcnt += Dfs(w);
    }
    assert(matcnt == id);
    for(int i = 1; i <= l; ++ i) {
        if(ans[i] == ' ') {
            if(to[i]) {
                ans[i] = ch[to[i]];
            }
            else {
                for(int j = 0; j < 26; ++ j) {
                    if(!cant[i][j] && least[j] < most[j]) {
                        ans[i] = j + 'a';
                        ++ least[j];
                        break;
                    }
                }
            }
        }
    }
    for(int i = 1; i <= l; ++ i)
        putchar(ans[i]);
    puts("");
}

詳細信息

Test #1:

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

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

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

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabdcdebaaaa

result:

ok 

Test #3:

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

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq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qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqq...

output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

result:

ok 

Test #6:

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

input:

22 500
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...

output:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

result:

ok 

Test #7:

score: -100
Runtime Error

input:

30 20
azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB
zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB
zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB
zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB
zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB
zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB
zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB
...

output:


result: