QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#289568#7940. Impossible Numberskilo_tobo_tarjenTL 1165ms3936kbC++203.9kb2023-12-23 18:44:322023-12-23 18:44:32

Judging History

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

  • [2023-12-23 18:44:32]
  • 评测
  • 测评结果:TL
  • 用时:1165ms
  • 内存:3936kb
  • [2023-12-23 18:44:32]
  • 提交

answer

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

struct Graph
{
    int num, n, tot, match;
    int head[150], nxt[2000000], to[2000000], cap[2000000], ban[2000000];
    int g[150], dis[150];
    vector<int> edge[10];
    void add(int x, int y, int z)
    {
        to[tot] = y, nxt[tot] = head[x], cap[tot] = z, head[x] = tot++;
        to[tot] = x, nxt[tot] = head[y], cap[tot] = 0, head[y] = tot++;
    }
    void init(int _n, vector<vector<int>> &a)
    {
        num = _n;
        n = num + 11;
        tot = match = 0;
        memset(head, -1, sizeof(head));
        for (int i = 1; i <= _n; i++)
            add(0, i, 1);
        for (int i = 0; i < _n; i++)
            for (int j : a[i])
                add(i + 1, num + j + 1, 1);
    }
    bool bfs(int s, int t)
    {
        for (int i = 0; i <= n; i++)
            dis[i] = -1;
        queue<int> que;
        que.push(s);
        dis[s] = 0;
        while (!que.empty())
        {
            int cur = que.front();
            que.pop();
            g[cur] = head[cur];
            for (int p = head[cur]; ~p; p = nxt[p])
            {
                if (!ban[p] && dis[to[p]] == -1 && cap[p])
                {
                    dis[to[p]] = dis[cur] + 1;
                    que.push(to[p]);
                }
            }
        }
        return dis[t] != -1;
    }
    int dfs(int cur, int t, int flow)
    {
        if (cur == t)
            return flow;
        int used = 0;
        for (int &p = g[cur]; ~p; p = nxt[p])
        {
            if (!ban[p] && dis[to[p]] == dis[cur] + 1 && cap[p])
            {
                int k = dfs(to[p], t, min(flow - used, cap[p]));
                used += k;
                cap[p] -= k, cap[p ^ 1] += k;
                if (used == flow)
                    return used;
            }
        }
        return used;
    }
    int dinic(int s, int t)
    {
        int res = 0;
        while (bfs(s, t))
            res += dfs(s, t, 1e9);
        return res;
    }
    void add(int x)
    {
        edge[x].push_back(tot);
        add(num + x + 1, n, 1);
        if (bfs(0, n))
            match += dfs(0, n, 1);
    }
    void del(int x)
    {
        int cur = edge[x].back();
        edge[x].pop_back();
        ban[cur] = 1;
        if (!cap[cur])
        {
            bfs(num + x + 1, 0);
            dfs(num + x + 1, 0, 1);
            match--;
        }
    }
    void print()
    {
        for (int i = 0; i <= 9; i++)
            cout << i << ' ' << edge[i].size() << '\n';
    }
} G;

string now;
int k, n;
bool check(int ad, int all)
{
    bool flag = true;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < ad; j++)
            G.add(i);
        if (G.match != all)
            flag = false;
        for (int j = 0; j < ad; j++)
            G.del(i);
        if (!flag)
            return true;
    }
    return false;
}
void dfs(int i, int p)
{
    // cout << "i=" << i << " p=" << p << " now=" << now << "\n";
    // G.print();
    if (i == -1)
    {
        if (now.empty())
            return;
        cout << now << " ";
        k--;
        if (k == 0)
            exit(0);
        return;
    }
    for (int x = p; x <= 9; x++)
    {
        now.push_back(char(x + '0'));
        G.add(x);
        if (check(i, (int)now.size() + i))
        {
            dfs(i - 1, 0);
        }
        G.del(x);
        now.pop_back();
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    vector<vector<int>> a;
    for (int i = 1; i <= n; i++)
    {
        int t = 6;
        vector<int> p(t);
        for (int j = 0; j < t; j++)
            cin >> p[j];
        a.push_back(p);
    }
    G.init(n, a);
    // cout<<G.match<<"\n" ;
    for (int l = 1; l <= 100; l++)
    {
        dfs(l - 1, 1);
    }
    assert(false);
}

详细

Test #1:

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

input:

2 3
1 8 7 0 6 2
1 2 5 4 9 3

output:

33 34 35 

result:

ok single line: '33 34 35 '

Test #2:

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

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 10 11 12 13 14 15 

result:

ok single line: '3 7 8 9 10 11 12 13 14 15 '

Test #3:

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

input:

4 10
1 5 7 1 2 4
0 1 5 8 9 4
3 5 2 2 7 8
6 1 7 0 2 2

output:

33 66 99 133 166 199 233 266 299 303 

result:

ok single line: '33 66 99 133 166 199 233 266 299 303 '

Test #4:

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

input:

5 10
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4

output:

7 17 27 37 47 55 57 67 70 71 

result:

ok single line: '7 17 27 37 47 55 57 67 70 71 '

Test #5:

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

input:

5 10
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3

output:

66 88 166 188 222 226 262 266 288 366 

result:

ok single line: '66 88 166 188 222 226 262 266 288 366 '

Test #6:

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

input:

5 10
6 8 7 7 0 0
0 5 1 9 4 1
5 9 6 9 5 4
0 4 6 9 1 6
2 8 7 4 4 0

output:

3 13 22 23 30 31 32 33 34 35 

result:

ok single line: '3 13 22 23 30 31 32 33 34 35 '

Test #7:

score: 0
Accepted
time: 1165ms
memory: 3936kb

input:

5 1000
0 4 1 3 9 6
9 6 2 1 8 6
5 3 0 7 7 3
0 2 8 0 8 4
2 4 1 2 9 7

output:

55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 575 577 585 595 655 666 755 757 775 777 855 888 955 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556...

result:

ok single line: '55 155 255 333 335 353 355 455... 10053 10055 10111 10116 10119 '

Test #8:

score: -100
Time Limit Exceeded

input:

5 10000
1 4 7 5 6 0
2 3 8 4 9 0
1 2 8 8 3 0
7 9 9 7 2 9
4 7 1 9 3 6

output:

55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 566 575 585 595 655 656 665 666 755 855 888 955 1055 1111 1115 1116 1151 1155 1156 1161 1165 1166 1255 1355 1455 1505 1511 1515 1516 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1561 1565 1566 1575...

result: