QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625862#7011. Rikka with Sorting Networksucup-team5071#TL 837ms3612kbC++201.6kb2024-10-09 21:29:022024-10-09 21:29:03

Judging History

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

  • [2024-10-09 21:29:03]
  • 评测
  • 测评结果:TL
  • 用时:837ms
  • 内存:3612kb
  • [2024-10-09 21:29:02]
  • 提交

answer

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

int solve()
{
    int n,k,mod;cin>>n>>k>>mod;
    vector<pair<int,int>> p(k);
    for(int i=0;i<k;i++)cin>>p[i].first>>p[i].second;
    auto count = [&](vector<int>&a,int op){
        for(int i=k-1;i>=0;i--){
            if((a[p[i].first]>a[p[i].second])){
                for(int j=i+1;j<k;j++)if(op>>j&1)swap(a[p[j].first],a[p[j].second]);
                return 0;
            }
            if(op>>i&1)swap(a[p[i].first],a[p[i].second]);
        }
        // for(auto it:a)cout<<it<<" ";;cout<<" op="<<op<<endl;
        for(int j=0;j<k;j++)if(op>>j&1)swap(a[p[j].first],a[p[j].second]);
        return 1;
    };
    int ans=0;
    auto add = [&](int &x,int y){
        if((x+=y)>=mod)x-=mod;
    };
    for(int i=1;i<=n;i++){
        vector<int> a(n+1);iota(a.begin(),a.end(),0);
        for(int j=i+1;j<=n;j++){
            swap(a[j-1],a[j]);
            for(int z=0;z<(1<<k);z++)add(ans,count(a,z));
        }
    }
    for(int i=1;i<=n;i++){
        vector<int> a(n+1);iota(a.begin(),a.end(),0);
        if(i>1)swap(a[i],a[i-1]);
        for(int j=i-2;j>=1;j--){
            swap(a[j+1],a[j]);
            for(int z=0;z<(1<<k);z++)add(ans,count(a,z));
        }
    }
    vector<int>a(n+1);iota(a.begin(),a.end(),0);
    for(int z=0;z<(1<<k);z++)add(ans,count(a,z));
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;
    while(T--)cout<<solve()<<"\n";
}

/*

4
4 0 998244353
4 1 998244353
1 2
4 3 998244353
1 2
2 3
1 2
4 6 998244353
1 2
2 3
1 2
3 4
2 3
1 2

*/

詳細信息

Test #1:

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

input:

4
4 0 998244353
4 1 998244353
1 2
4 3 998244353
1 2
2 3
1 2
4 6 998244353
1 2
2 3
1 2
3 4
2 3
1 2

output:

10
14
24
24

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 837ms
memory: 3612kb

input:

100
14 0 332974091
7 0 860384617
38 0 721801273
20 0 905563207
15 0 665595113
19 0 315971339
37 10 381449743
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
20 25
33 7 891399043
7 17
6 16
25 32
25 31
16 25
25 32
17 30
35 0 134186387
43 4 344440849
14 26
26 29
14 26
14 29
44 3 520502371
5 8
5 8...

output:

170
37
1370
362
197
325
2528
72288
1157
10152
3616
12260
2478
2540
785
5496
1426
7062
628
31548
2532
256192
4194
8850
53072
842
12240
7928
1530
362
948
1988
4176
27700
9636
10294
1765
9396
31680
4314
3466
9304
218624
1766
22170
3990
52466
79104
8696
8264
1342
36080
3478
6914
3484
848
2210
1888
326
1...

result:

ok 100 lines

Test #3:

score: -100
Time Limit Exceeded

input:

100
50 10 846279443
4 46
1 4
35 37
48 49
33 41
8 14
21 34
12 35
12 41
49 50
50 10 280666103
4 48
26 44
40 44
30 36
32 40
22 28
26 28
31 37
6 26
42 46
50 10 100827031
29 34
9 48
12 14
30 45
39 48
33 44
7 20
26 50
39 48
35 40
50 10 245870137
39 45
37 47
11 42
39 42
43 48
20 29
44 49
16 17
34 40
3 47
5...

output:


result: