C++,luogu,P11681 [Algo Beat Contest 001 C] Creating a Queue

//luogu,P11681 [Algo Beat Contest 001 C] Creating a Queue
#include <iostream>
#include <set>
int main(){
    int N,M;std::cin>>N>>M;
    int countOfZero = 0;
    int usable = M;
    unsigned long long ans = 1;
    std::set<int> checkSame;
    for(int i = 0;i<N;++i){
        int temp;std::cin>>temp;
        if(temp!=0){
            if(checkSame.find(temp)!=checkSame.end()){
                ans = 0;
                break;
            }else{
                checkSame.insert(temp); 
            }
        }
        if(temp==0)++countOfZero;
        if(temp>=1&&temp<=M)--usable;
    }
    if(countOfZero>usable)ans = 0;
    if(ans==1){
        for(int i = usable;i>=usable-countOfZero+1;--i){
            ans=(ans*i)%1145141923;
        }
    }
    std::cout<<ans<<std::endl;
}
posted @ 2025-03-07 20:21  Kazuma_124  阅读(4)  评论(0)    收藏  举报