QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625836#7003. Rikka with Minimum Spanning Treesucup-team5071#RE 0ms0kbC++201.3kb2024-10-09 21:20:312024-10-09 21:20:32

Judging History

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

  • [2024-10-09 21:20:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-09 21:20:31]
  • 提交

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((op>>i&1)^(a[p[i].first]<a[p[i].second]))return 0;
            if(op>>i&1)swap(a[p[i].first],a[p[i].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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

1
2 100000 123456789 987654321

output:


result: