Submission #1121674

#TimeUsernameProblemLanguageResultExecution timeMemory
1121674vjudge1Calvinball championship (CEOI15_teams)C++17
0 / 100
1058 ms1616 KiB
#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
const ll INF =1e18, mod = 1e9 + 7, N = 1e5 + 5;
ll f[N];
ll modpow(ll a,ll b){
    ll ans = 1;
    while(b>0){
        if(b%2==1){
            ans*=a;
            ans%=mod;
        }
        a*=a;
        a%=mod;
        b/=2;
    }
    return ans;
}
 
ll inv(ll a){
    return (modpow(a,mod-2)) % mod;
}
ll C(ll a,ll b){
     return(f[a] * inv(f[b] * f[a-b] % mod)) % mod;
}
void solve(){
    ll n;
    cin >> n;
    ll a[n];
    set<ll>s;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s.in(a[i]);
    }
    ll ans = 1;
    ll now = n - 1;
    for(int i = 2; i <= n; i++){
        if(i != n){
            for(int j = 1; j <= now; j++){
                ans += C(n - 1, j) % mod;
                ans %= mod;
            }
           now--;
        }
        else{
            ans++;
        }
    }
    cout << ans << endl;
}
int main(){
    fast;
    ll t = 1;
    //cin >> t;
    f[0] = 1;
    f[1] = 1; 
    for(int i = 2; i <= N; i++){
        f[i] = f[i - 1] * i;
    }
    while(t--){
        solve();
    }
    return 0;
}

Compilation message (stderr)

teams.cpp: In function 'int main()':
teams.cpp:67:14: warning: iteration 100003 invokes undefined behavior [-Waggressive-loop-optimizations]
   67 |         f[i] = f[i - 1] * i;
      |         ~~~~~^~~~~~~~~~~~~~
teams.cpp:66:22: note: within this loop
   66 |     for(int i = 2; i <= N; i++){
      |                    ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...