UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207169#3734. 凯南开大Soulmate100219ms11792kbC++111.3kb2024-07-27 18:34:292024-07-27 20:09:58

answer

#include <bits/stdc++.h>

using namespace std;
int main() 
{

    int R,C,K,N;
    cin>>R>>C>>K>>N;

    vector<int> r(R+1,0);
    vector<int> c(C+1,0);
    unordered_map<int, unordered_map<int,int>> m;

    for (int i=0;i<N;++i) 
    {
        int x,y;
        cin>>x>>y;
        r[x]++;
        c[y]++;
        m[x][y]++;
    }

    unordered_map<int, int> rcm;
    unordered_map<int, int> ccm;

    for (int i=1;i<=R;++i) 
    {
        rcm[r[i]]++;
    }

    for (int i=1;i<=C;++i) 
    {
        ccm[c[i]]++;
    }

    long long res=0;

    for (auto& y:rcm) 
    {
        int rc=y.first;
        int r=y.second;

        for (auto& p:ccm) 
        {
            int cc=p.first;
            int co=p.second;

            if (rc+cc==K) 
            {
                res+=static_cast<long long>(r)*co;
            }
        }
    }

    for (auto& rp:m) 
    {
        int x=rp.first;
        for (auto& cp:rp.second) 
        {
            int y=cp.first;
            int cnt=cp.second;

            if (r[x]+c[y]==K) 
            {
                res--;
            } 
            else if (r[x]+c[y]-cnt==K) 
            {
                res++;
            }
        }
    }

    cout<<res<<endl;
    return 0;
}

Details

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 1256kb

input:

81 85 2
91
31 69
4 34
53 85
73 1
14 29
59 25
16 72
8 64
78 58
68 20
80 48
15 82
50 65
27 57
56 70
11...

output:

1803

result:

ok 1 number(s): "1803"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1248kb

input:

61 61 0
27
37 1
26 6
8 60
29 3
14 21
29 11
39 1
6 27
50 49
54 17
38 4
58 12
35 7
8 25
8 57
33 48
49 ...

output:

1560

result:

ok 1 number(s): "1560"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1384kb

input:

2385 1664 0
664
1779 8
878 1209
204 1530
1950 701
231 223
1080 12
125 1220
1116 1315
1954 1011
641 8...

output:

2016185

result:

ok 1 number(s): "2016185"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1656kb

input:

2709 2450 2
2728
1039 412
2486 560
422 930
1726 2322
719 1204
57 1832
2211 2360
932 613
1331 514
269...

output:

1821925

result:

ok 1 number(s): "1821925"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1268kb

input:

2181 2455 0
47
1884 2379
328 1465
1946 170
1868 1674
1965 1831
1911 459
625 2342
713 194
1282 1019
2...

output:

5143215

result:

ok 1 number(s): "5143215"

Test #6:

score: 10
Accepted
time: 53ms
memory: 11076kb

input:

83801 58202 1
57566
28407 57592
57156 34586
875 53926
74360 34983
27009 34578
41941 4280
13959 9903
...

output:

1533165599

result:

ok 1 number(s): "1533165599"

Test #7:

score: 10
Accepted
time: 15ms
memory: 4496kb

input:

96247 75710 0
13709
40610 5580
33278 68267
6526 65877
93151 56278
77725 18789
88475 23955
12099 6274...

output:

5274189090

result:

ok 1 number(s): "5274189090"

Test #8:

score: 10
Accepted
time: 3ms
memory: 3440kb

input:

56595 75750 0
8401
40689 67559
50238 64229
30225 40693
26195 69324
7040 787
3045 7253
9713 10474
459...

output:

3308154615

result:

ok 1 number(s): "3308154615"

Test #9:

score: 10
Accepted
time: 76ms
memory: 11564kb

input:

56243 93280 2
74158
35957 26122
47375 39597
7804 12937
45128 26864
24236 2128
25175 62939
33069 1221...

output:

1414053026

result:

ok 1 number(s): "1414053026"

Test #10:

score: 10
Accepted
time: 72ms
memory: 11792kb

input:

62576 96600 1
72226
12939 42717
56190 78484
37132 68808
44159 58020
57767 41498
23820 60150
41745 81...

output:

1717246754

result:

ok 1 number(s): "1717246754"