QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204457#5161. Last GuessMinhhoWA 2ms6536kbC++204.7kb2023-10-07 11:45:202023-10-07 11:45:20

Judging History

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

  • [2023-10-07 11:45:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6536kb
  • [2023-10-07 11:45:20]
  • 提交

answer

#define taskname "L"
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2005, oo = 1e9;
vector<int> adj[maxn];
int cap[30], dem[30], mn[30], fx[maxn], ban[maxn][30], cur[maxn], d[maxn], ans[maxn], fxl[30];
int tin[maxn], tout[maxn], cnt, n, m, s, t, _s, _t, cell, l;
string ds[maxn], dt[maxn];

struct edge {
    int u, v, de, f, c;
} e[maxn*maxn];

inline void add(int u, int v, int c, int de = 0)
{
    if (c == 0) return;
    if (v == t) assert(u >= cell+1 && u <= cell+l);
    if (u == s) assert(v == _t);
//    if ((u == s || v == t || true) && (c > 0))
//    cerr<<"ADD: "<<u<<" "<<v<<" "<<c<<" "<<de<<"\n";
    adj[u].emplace_back(cnt);
    e[cnt++] = {u, v, de, 0, c};
    tin[v] += de;
    tout[u] += de;
    adj[v].emplace_back(cnt);
    e[cnt++] = {v, u, 0, 0, 0};
}

inline bool BFS(int st = s, int ed = t)
{
    fill(d, d+ed+1, -1);
    d[st] = 0;
    queue<int> q;
    q.emplace(st);
    while (q.size())
    {
        int u = q.front(); q.pop();
        for (int id: adj[u])
        {
            auto [_, v, de, f, c] = e[id];
            if (d[v] == -1 && f < c) d[v] = d[u] + 1, q.emplace(v);
        }
    }
    return d[ed] != -1;
}

int DFS(int u = s, int flow = 1e9)
{
//    cerr<<"CUR: "<<u<<" "<<flow<<"\n";
    if (u == t) return flow;
    for (int &i=cur[u]; i<adj[u].size(); i++)
    {
        int id = adj[u][i];
        auto [_, v, de, f, c] = e[id];
        if (d[v] == d[u] + 1 && f < c)
        {
            int tmp = DFS(v, min(flow, c - f));
            if (tmp)
            {
                e[id].f += tmp;
                e[id^1].f -= tmp;
                return tmp;
            }
        }
    }
    return 0;
}

/**
s = 0
cells: 1 -> cell
letters: cell+1 -> cell+l
_s = cell+l+1;
_t = cell+l+2;
t = cell+l+3
**/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin>>m>>n;
    memset(fx, -1, sizeof fx);
    memset(ans, -1, sizeof ans);
    for (int i=0; i<26; i++) cap[i] = 1e9;
    for (int i=1; i<m; i++)
    {
        string s, t;
        cin>>t>>s;
        dt[i] = t;
        ds[i] = s;
        memset(dem, 0, sizeof dem);
        int tmp[30];
        memset(tmp, 0, sizeof tmp);
        vector<int> bn;
        for (int j=0; j<n; j++)
            if (s[j] == 'G') fx[j] = t[j] - 'a', ans[j] = t[j] - 'a', dem[t[j]-'a']++;
            else if (s[j] == 'Y') ban[j][t[j]-'a'] = 1, dem[t[j]-'a']++, tmp[t[j]-'a']++;
            else bn.emplace_back(t[j]-'a'), ban[j][t[j]-'a'] = 1;
        for (int j: bn) if (cap[j] == 1e9) cap[j] = dem[j]; else assert(cap[j] == dem[j]);
        for (int j=0; j<26; j++) mn[j] = max(mn[j], tmp[j]);
    }
    for (int i=0; i<n; i++) if (fx[i] != -1) fxl[fx[i]]++;
    for (int i=0; i<26; i++) if (cap[i] != 1e9) cap[i] -= fxl[i], mn[i] = cap[i];
    for (int i=0; i<26; i++) assert(mn[i] <= cap[i]);
    cell = 0;
    vector<int> ve;
    for (int i=0; i<n; i++) if (fx[i] == -1) ve.emplace_back(i);
    cell = ve.size();
    l = 26;
    s = 0;
    _s = cell+l+1;
    _t = _s+1;
    t = _t+1;
//    cerr<<"SS: "<<s<<" "<<t<<"\n";
    for (int i=1; i<=cell; i++)
    {
        add(_s, i, 1);
        for (int j=1; j<=26; j++) if (!ban[ve[i-1]][j-1]) add(i, cell+j, 1);
    }
    for (int i=1; i<=26; i++) add(cell+i, _t, cap[i-1], mn[i-1]);
    add(_t, _s, oo);
    for (int i=0; i<cnt; i++) e[i].c -= e[i].de;
    for (int i=1; i<t; i++) add(s, i, tin[i]), add(i, t, tout[i]);
    int anss = 0;
    while (BFS())
    {
        fill(cur, cur+t+1, 0);
        int x;
        while (x = DFS(s, cell)) anss += x;
    }
    int smn = accumulate(mn, mn+26, 0);
//    assert(cell >= smn);
//    assert(anss == smn);
//    cerr<<"LUONG: "<<anss<<"\n";
    for (int i=0; i<cnt; i++)
    {
        auto [u, v, de, f, c] = e[i];
        if (u >= 1 && u <= cell && v >= cell+1 && v <= cell+l)
        {
//            cerr<<"F & C: "<<f<<" "<<c<<"\n";
//            cerr<<"WUT: "<<u<<" "<<v<<" "<<d[u]<<" "<<d[v]<<"\n";
            if (f == c)
                ans[ve[u-1]] = v - (cell+1);//, cerr<<"ANS: "<<ve[u-1]<<" "<<(v-cell-1)<<"\n";
        }
    }
    string res="";
    for (int i=0; i<n; i++) res += (char)(ans[i]+'a');
    for (int i=1; i<m; i++)
    {
        for (int j=0; j<n; j++)
        {
            if (ds[i][j] == 'G')
            {
                if (res[j] != dt[i][j]) cout<<"WA ON TEST: "<<i<<" MUST BE: "<<dt[i][j]<<" AT: "<<j<<" FOUND: "<<res[j]<<"\n";
            }
            else
            {
                if (res[j] == dt[i][j]) cout<<"WA ON TEST: "<<i<<" MUST NOT BE: "<<dt[i][j]<<" AT: "<<j<<" FOUND: "<<res[j]<<"\n";
            }
        }
    }
    cout<<res;
}
/**

**/

詳細信息

Test #1:

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

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

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

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabdcbe`d```

result:

ok 

Test #3:

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

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:

abcdefghijklmnoooprstuvwxyz`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````...

result:

ok 

Test #4:

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

input:

24 500
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvuvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv...

output:

abcdefghijklmnoppqrstuwxyz``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````...

result:

ok 

Test #5:

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

input:

23 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqq...

output:

abcdefggghijklmnoprstuuuvwxyz```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````...

result:

ok 

Test #6:

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

input:

22 500
ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...

output:

abbbdefffghijklmnopqrstuvwxyz```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````...

result:

ok 

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3660kb

input:

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

output:

vavlabmpqravasaauavj

result:

FAIL Wrong answer: does not fit word 21