UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213983#2400. 椅子stawalr35553ms9852kbC++112.5kb2024-11-14 21:12:312024-11-14 23:07:21

answer

#include<bits/stdc++.h>
using namespace std;
const int mn=2e3+5,mm=3e6+5;
int n,m;
int hd[mn],nxt[mm],to[mm],w[mm],cnt=2;
int dep[mn],thd[mn];
queue<int> q;
void add(int x,int y,int z)
{
    nxt[cnt]=hd[x];
    to[cnt]=y;
    w[cnt]=z;
    hd[x]=cnt++;
}
bool bfs()
{
    bool f=0;
    for(int i=1;i<=n+m+2;i++)
    {
        dep[i]=0;
    }
    q.push(n+m+1);
    dep[n+m+1]=1;
    while(!q.empty())
    {
        int t=q.front();
        q.pop();
        if(t==n+m+2)f=1;
        for(int i=hd[t];i;i=nxt[i])
        {
            int u=to[i];
            if(dep[u]==0 && w[i])
            {
                dep[u]=dep[t]+1;
                q.push(u);
            }
        }
    }
    return f;
}
int dfs(int x,int y)
{
    if(x==n+m+2)return y;
    int res=0;
    for(int i=hd[x];i;i=nxt[i])
    {
        hd[x]=i;
        int u=to[i];
        if(dep[u]==dep[x]+1 && w[i])
        {
            int tmp=dfs(u,min(w[i],y-res));
            w[i]-=tmp;
            w[i^1]+=tmp;
            res+=tmp;
            if(y==res)return res;
        }
    }
    return res;
}
int dinic()
{
    int res=0;
    for(int i=1;i<=n+m+2;i++)
    {
        thd[i]=hd[i];
    }
    while(bfs())
    {
        res+=dfs(n+m+1,0x3f3f3f3f);
        for(int i=1;i<=n+m+2;i++)
        {
            hd[i]=thd[i];
        }
    }
    return res;
}
void sol1()
{
    int x,y;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x,&y);
        // cerr<<i<<"!!";
        for(int j=1;j<=x;j++)
        {
            // cerr<<j;
            add(i,j+n,1);
            add(j+n,i,0);
        }
        for(int j=y;j<=m;j++)
        {
            // cerr<<j;
            add(i,j+n,1);
            add(j+n,i,0);
        }
        // cerr<<'\n';
    }
    for(int i=1;i<=n;i++)
    {
        add(m+n+1,i,1);
        add(i,m+n+1,0);
    }
    for(int i=1;i<=m;i++)
    {
        add(m+n+2,i+n,0);
        add(i+n,m+n+2,1);
    }
    printf("%d",n-dinic());
}
void sol2()
{
    // int x;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&cnt,&w[i]);
    }
    sort(w+1,w+n+1);
    cnt=1;
    for(int i=1;i<=n;i++)
    {
        if(w[i]>m)
        {
            printf("%d",i);
            return;
        }
        nxt[max(cnt,w[i])]=1;
        cnt=max(cnt,w[i]+1);
        if(cnt>m)
        {
            printf("%d",i);
            return;
        }
    }
}
int main()
{
    scanf("%d%d",&n,&m);
    if(n<=1e3 && m<=1e3)sol1();
    else sol2();
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 0ms
memory: 1260kb

input:

8 8
1 8
1 5
2 8
0 5
0 3
2 6
2 6
2 6

output:

1

result:

ok single line: '1'

Test #2:

score: 5
Accepted
time: 0ms
memory: 1260kb

input:

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

output:

2

result:

ok single line: '2'

Test #3:

score: 5
Accepted
time: 0ms
memory: 1260kb

input:

20 20
4 16
2 11
3 19
6 12
7 18
1 14
4 10
5 20
6 14
8 17
1 12
2 11
7 18
7 15
0 15
1 12
2 19
7 13
4 10...

output:

1

result:

ok single line: '1'

Test #4:

score: 5
Accepted
time: 0ms
memory: 1352kb

input:

96 93
2 67
5 61
4 74
15 68
3 63
40 91
14 58
6 66
9 57
18 85
13 63
40 85
17 89
16 73
10 72
15 74
15 6...

output:

7

result:

ok single line: '7'

Test #5:

score: 5
Accepted
time: 0ms
memory: 1364kb

input:

100 100
29 70
17 68
25 77
13 74
9 79
42 90
34 99
18 100
3 80
21 71
26 63
6 54
43 89
41 78
19 78
13 9...

output:

2

result:

ok single line: '2'

Test #6:

score: 5
Accepted
time: 128ms
memory: 9220kb

input:

952 954
182 871
114 769
110 694
91 741
22 509
53 841
124 858
16 465
160 789
24 720
96 939
56 689
313...

output:

64

result:

ok single line: '64'

Test #7:

score: 5
Accepted
time: 128ms
memory: 9852kb

input:

1000 1000
74 795
175 641
39 618
19 971
162 873
93 731
480 989
357 932
4 693
266 965
89 581
47 560
27...

output:

74

result:

ok single line: '74'

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 1280kb

input:

4516 4690
665 4024
1062 3765
1573 4200
1035 4155
441 2678
31 3472
87 3450
146 2286
310 4267
1231 450...

output:

4514

result:

wrong answer 1st lines differ - expected: '69', found: '4514'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 1284kb

input:

5000 5000
62 4476
1146 3647
531 4569
1042 3464
2044 4817
2186 4584
2223 4892
1224 4761
1154 4943
147...

output:

4998

result:

wrong answer 1st lines differ - expected: '250', found: '4998'

Test #10:

score: 0
Wrong Answer
time: 3ms
memory: 1308kb

input:

10000 5000
1106 4454
1138 4746
926 4805
609 4507
259 4543
1435 4211
790 3399
528 3426
38 4665
87 404...

output:

9994

result:

wrong answer 1st lines differ - expected: '5347', found: '9994'

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 1316kb

input:

10000 10000
2224 8599
3697 9779
1264 7760
266 8474
601 9386
5276 9907
4231 9619
2206 8589
3306 9731
...

output:

9997

result:

wrong answer 1st lines differ - expected: '574', found: '9997'

Test #12:

score: 0
Wrong Answer
time: 19ms
memory: 1936kb

input:

93875 99655
0 25859
0 30798
0 89053
0 29230
0 93483
0 83280
0 47502
0 39669
0 69861
0 64184
0 35067
...

output:

93875

result:

wrong answer 1st lines differ - expected: '14154', found: '93875'

Test #13:

score: 0
Wrong Answer
time: 15ms
memory: 1944kb

input:

100000 100000
0 50602
0 56129
0 65965
0 75241
0 71832
0 26413
0 79671
0 73842
0 78772
0 94149
0 3483...

output:

99998

result:

wrong answer 1st lines differ - expected: '25000', found: '99998'

Test #14:

score: 0
Wrong Answer
time: 15ms
memory: 1816kb

input:

91057 96847
21419 89318
2406 89095
2941 51033
14888 77083
28023 74840
18260 62296
6297 51346
7735 88...

output:

91052

result:

wrong answer 1st lines differ - expected: '134', found: '91052'

Test #15:

score: 0
Wrong Answer
time: 20ms
memory: 1860kb

input:

100000 100000
16723 78322
7205 66894
9839 72285
7661 85725
38680 93140
6182 88375
30785 99006
38538 ...

output:

99999

result:

wrong answer 1st lines differ - expected: '5118', found: '99999'

Test #16:

score: 0
Wrong Answer
time: 47ms
memory: 2452kb

input:

198495 197435
63738 165927
17757 117506
9207 170263
50748 141346
18132 120887
49285 188664
25304 190...

output:

198493

result:

wrong answer 1st lines differ - expected: '11098', found: '198493'

Test #17:

score: 0
Wrong Answer
time: 36ms
memory: 2444kb

input:

199260 192470
22818 156104
9228 171776
43025 139453
39938 135662
18272 171006
68109 171295
28220 116...

output:

199257

result:

wrong answer 1st lines differ - expected: '15568', found: '199257'

Test #18:

score: 0
Wrong Answer
time: 45ms
memory: 2464kb

input:

200000 200000
75002 167675
8656 181873
54606 156991
48075 167451
74414 194621
55633 180796
4565 1657...

output:

199993

result:

wrong answer 1st lines differ - expected: '10484', found: '199993'

Test #19:

score: 0
Wrong Answer
time: 38ms
memory: 2468kb

input:

200000 200000
59298 170956
2760 194028
35447 153792
1945 163425
73195 176225
62065 185526
85886 1916...

output:

199999

result:

wrong answer 1st lines differ - expected: '10543', found: '199999'

Test #20:

score: 0
Wrong Answer
time: 59ms
memory: 2468kb

input:

200000 200000
67496 171474
36806 170296
86759 193181
7951 171117
85324 184470
8949 171983
10465 1547...

output:

199990

result:

wrong answer 1st lines differ - expected: '10575', found: '199990'