QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#522648#7923. Ferris WheelCSQRE 0ms0kbC++142.2kb2024-08-17 10:05:572024-08-17 10:05:58

Judging History

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

  • [2024-08-17 10:05:58]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-17 10:05:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
const int MAXN = (1<<24);
int sub[MAXN],sup[MAXN],dp[(1<<24)];
const int MOD = 998244353;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        c--;

        int x = (1<<b) + (1<<c);
        int y = (1<<b) + (1<<a);
        int z = x+y - (1<<b);
        sup[x]++;
        sup[y]++;
        sup[z]--;
        int full = (1<<n)-1;
        sub[x ^ full]++;
        sub[y ^ full]++;
        sub[z ^ full]--;
    }
    for(int i=0;i<n;i++){
        for(int j=(1<<n)-1;j>=0;j--){
            if(j & (1<<i))sup[j] += sup[j - (1<<i)];
        }
        for(int j=0;j<(1<<n);j++){
            if(!(j & (1<<i)))sub[j] += sub[j + (1<<i)];
        }
    }
    dp[0] = 1;
    for(int i=1;i<(1<<n);i++){
        if(sup[i] + sub[i] != m)continue;
        for(int j=0;j<n;j++){
            if(i & (1<<j))dp[i] += dp[i - (1<<j)];
            if(dp[i]>=MOD)dp[i]-=MOD;
        }
    }
    cout<<dp[(1<<n)-1];
}
/*
5 4
1 2 4
2 3 5
3 2 4
1 3 2

4 2
3 1 4
1 4 3
*/

/*notes:

a permutation is good if for every 1<=L<n
There is no triplet (a,b,c) st one of these are true - (1)
b <= L and a,c > L
a,c <= L and b > L

so some masks are just inherently bad, what I did is for every mask S compute how many triplets
does NOT violate the condition in (1) when L = |S|. SOS dp is enough

eg
supermasks of 2^b + 2^c or 2^b + 2^a are goods
then 2^a + 2^b + 2^c decrement one to avoid overcounting.
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

3 2

output:


result: