提出 #66942948


ソースコード 拡げる

#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mk make_pair
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define bi __int128_t
#define lb(x) ((x)&(-(x)))
#define gp(i,j) (((i)>>(j-1))&1)
#define ppc __builtin_popcount
using namespace std;
const int N=25,MS=1.2e6,mod=998244353;
const ll inf=1e18+10;
void Add(int &a,int b){a+=b;if(a>=mod) a-=mod;}
void Sub(int &a,int b){a-=b;if(a<0) a+=mod;}
void Mul(int &a,int b){a=1ll*a*b%mod;}
int qp(int a,int b){
    int x=1;
    while(b){
        if(b&1) Mul(x,a);
        Mul(a,a);b>>=1;
    }return x;
}
int e[N][N];
int f[N][MS];
int n,m;
void slv(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        e[u][v]++;e[v][u]++;
    }
    for(int i=1;i<=n;i++) f[i][1<<(i-1)]=1;
    int U=(1<<n)-1;int ans=0;
    for(int i=1;i<=U;i++){
        for(int j=1;j<=n;j++){
            if(!f[j][i]) continue;
            for(int k=1;k<=n;k++){
                if((1<<(k-1))==lb(i)){
                    Add(ans,1ll*f[j][i]*e[j][__builtin_ctz(i)+1]%mod);
                    //cout<<i<<' '<<j<<' '<<k<<' '<<f[j][i]<<endl;
                }
                if((i>>(k-1))&1) continue;
                if((1<<(k-1))<lb(i)) continue;
                //cout<<(i|(1<<(k-1)))<<' '<<f[j][i]<<endl;
                Add(f[k][i|(1<<(k-1))],1ll*f[j][i]*e[j][k]%mod);
            }
        }
    }
    //cout<<ans<<endl;
    Sub(ans,m);Mul(ans,(mod+1)/2);
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;//cin>>t;
    while(t--) slv();
    cout.flush();
    return 0;
}

提出情報

提出日時
問題 G - Count Cycles
ユーザ LYLAKIOIAKIOI
言語 C++ 20 (gcc 12.2)
得点 600
コード長 1714 Byte
結果 AC
実行時間 665 ms
メモリ 65076 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 40
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 02_random2_06.txt, 02_random2_07.txt, 03_random3_00.txt, 03_random3_01.txt, 03_random3_02.txt, 03_random3_03.txt, 04_random4_00.txt, 04_random4_01.txt, 05_random5_00.txt, 05_random5_01.txt, 06_random6_00.txt, 06_random6_01.txt, 06_random6_02.txt, 06_random6_03.txt, 07_handmade_00.txt, 07_handmade_01.txt, 07_handmade_02.txt, 07_handmade_03.txt, 07_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3468 KiB
00_sample_01.txt AC 1 ms 3416 KiB
00_sample_02.txt AC 1 ms 3540 KiB
01_random_00.txt AC 143 ms 17776 KiB
01_random_01.txt AC 9 ms 3544 KiB
01_random_02.txt AC 16 ms 5028 KiB
01_random_03.txt AC 23 ms 3972 KiB
01_random_04.txt AC 297 ms 65060 KiB
01_random_05.txt AC 182 ms 49856 KiB
01_random_06.txt AC 654 ms 64988 KiB
01_random_07.txt AC 654 ms 64940 KiB
01_random_08.txt AC 665 ms 64872 KiB
01_random_09.txt AC 665 ms 64884 KiB
01_random_10.txt AC 664 ms 64948 KiB
01_random_11.txt AC 665 ms 64884 KiB
02_random2_00.txt AC 33 ms 3712 KiB
02_random2_01.txt AC 37 ms 8920 KiB
02_random2_02.txt AC 75 ms 61880 KiB
02_random2_03.txt AC 350 ms 64720 KiB
02_random2_04.txt AC 520 ms 64600 KiB
02_random2_05.txt AC 625 ms 65068 KiB
02_random2_06.txt AC 660 ms 64892 KiB
02_random2_07.txt AC 663 ms 64940 KiB
03_random3_00.txt AC 39 ms 9964 KiB
03_random3_01.txt AC 36 ms 5936 KiB
03_random3_02.txt AC 36 ms 5292 KiB
03_random3_03.txt AC 35 ms 3920 KiB
04_random4_00.txt AC 36 ms 4784 KiB
04_random4_01.txt AC 35 ms 5148 KiB
05_random5_00.txt AC 36 ms 5404 KiB
05_random5_01.txt AC 36 ms 5568 KiB
06_random6_00.txt AC 48 ms 50392 KiB
06_random6_01.txt AC 549 ms 65076 KiB
06_random6_02.txt AC 652 ms 64860 KiB
06_random6_03.txt AC 650 ms 64928 KiB
07_handmade_00.txt AC 1 ms 3464 KiB
07_handmade_01.txt AC 12 ms 3332 KiB
07_handmade_02.txt AC 23 ms 3664 KiB
07_handmade_03.txt AC 33 ms 3860 KiB
07_handmade_04.txt AC 664 ms 65000 KiB