Submission #954491

# Submission time Handle Problem Language Result Execution time Memory
954491 2024-03-28T03:57:51 Z vjudge1 Žarulje (COI15_zarulje) C++17
60 / 100
1000 ms 7252 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M=1e9+7,N=1<<18;
int H[N],fac[N],inv[N];
int pw(int x,int k){
    if(!k) return 1;
    int y=pw(x,k/2);
    y=y*y%M;
    if(k&1)y=y*x%M;
    return y;
}
int C(int a,int b){
    return fac[a+b]*inv[b]%M*inv[a]%M;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    fac[0]=1;
    for(int i=1;i<N;i++)
        fac[i]=fac[i-1]*i%M;
    inv[N-1]=pw(fac[N-1],M-2);
    for(int i=N;--i;)
        inv[i-1]=inv[i]*i%M;
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>H[i];
    while(k--){
        int x;
        cin>>x;
        stack<int>l,r;
        l.push(0),r.push(0);
        for(int i=1;i<x;l.push(H[i++]))
            while(l.top()>H[i])
                l.pop();
        for(int i=n;i>x;r.push(H[i--]))
            while(r.top()>H[i])
                r.pop();
        map<int,int> mp1,mp2;
        int res=1;
        while(l.size())
            mp1[l.top()]++,l.pop();
        while(r.size())
            mp2[r.top()]++,r.pop();
        mp1.erase(0);
        for(auto[i,j]:mp1)
            res=res*C(j,mp2[i])%M;
        cout<<res<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 20 ms 4700 KB Output is correct
4 Correct 18 ms 4700 KB Output is correct
5 Correct 12 ms 4700 KB Output is correct
6 Correct 19 ms 4764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 5724 KB Output is correct
2 Correct 24 ms 6632 KB Output is correct
3 Correct 23 ms 6540 KB Output is correct
4 Correct 22 ms 6700 KB Output is correct
5 Correct 24 ms 6996 KB Output is correct
6 Correct 25 ms 7252 KB Output is correct
7 Correct 27 ms 7252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4700 KB Output is correct
2 Correct 5 ms 4700 KB Output is correct
3 Correct 20 ms 4700 KB Output is correct
4 Correct 18 ms 4700 KB Output is correct
5 Correct 12 ms 4700 KB Output is correct
6 Correct 19 ms 4764 KB Output is correct
7 Correct 14 ms 5724 KB Output is correct
8 Correct 24 ms 6632 KB Output is correct
9 Correct 23 ms 6540 KB Output is correct
10 Correct 22 ms 6700 KB Output is correct
11 Correct 24 ms 6996 KB Output is correct
12 Correct 25 ms 7252 KB Output is correct
13 Correct 27 ms 7252 KB Output is correct
14 Correct 824 ms 4700 KB Output is correct
15 Execution timed out 1022 ms 5720 KB Time limit exceeded
16 Halted 0 ms 0 KB -