#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define int long long using namespace std; int n, a, ile[5009], wynik, cur, mod=1000000007, moz=1, sum; vector<int> v; int pot(int pod, int wyk){ if(wyk==0) return 1; else if(wyk%2==0){ long long wyn=(pot(pod, wyk/2))%mod; return (wyn*wyn)%mod; } else return (pod*pot(pod, wyk-1)%mod)%mod; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin>>n; for(int i=0; i<n; i++){ cin>>a; if(!ile[a]) v.pb(a); ile[a]++; } sort(v.begin(), v.end()); for(int u:v){ //cout<<u<<"\n"; if(sum+1<u){ cout<<"0\n"; return 0; } cur=(moz*((pot(2, ile[u])-1+mod))%mod)%mod; wynik=(wynik+cur)%mod; moz=(moz*((pot(2, ile[u])-1+mod))%mod)%mod; if(sum==u) moz+=ile[u]; sum+=u*ile[u]; } cout<<wynik<<"\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | #include<bits/stdc++.h> #define mp make_pair #define pb push_back #define int long long using namespace std; int n, a, ile[5009], wynik, cur, mod=1000000007, moz=1, sum; vector<int> v; int pot(int pod, int wyk){ if(wyk==0) return 1; else if(wyk%2==0){ long long wyn=(pot(pod, wyk/2))%mod; return (wyn*wyn)%mod; } else return (pod*pot(pod, wyk-1)%mod)%mod; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin>>n; for(int i=0; i<n; i++){ cin>>a; if(!ile[a]) v.pb(a); ile[a]++; } sort(v.begin(), v.end()); for(int u:v){ //cout<<u<<"\n"; if(sum+1<u){ cout<<"0\n"; return 0; } cur=(moz*((pot(2, ile[u])-1+mod))%mod)%mod; wynik=(wynik+cur)%mod; moz=(moz*((pot(2, ile[u])-1+mod))%mod)%mod; if(sum==u) moz+=ile[u]; sum+=u*ile[u]; } cout<<wynik<<"\n"; return 0; } |