답안 #148310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148310 2019-08-31T23:54:25 Z 12tqian Calvinball championship (CEOI15_teams) C++14
20 / 100
884 ms 1176 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const double PI = 4 * atan(1);

#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
  cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const int MAX = 1e4 + 5;
const ll MOD = 1e9 + 7;
ll fact[MAX];
ll inv[MAX];

long long modInverse(long long b){
    long long ex = MOD - 2;
    if (b==1){
        return 1;
    }
    long long r = 1;
    while (ex ){
        if (ex&1){
            r=(r * b)%MOD;
        }
        ex = ex >> 1;
        b = (b * b)%MOD;
    }
    return r;
}
ll choose(ll x, ll y){
    ll res = fact[x] * inv[y];
    res%= MOD;
    res*= inv[x-y];
    res%= MOD;
    return res;
}
vi a;
map<pii, int> need;
pair<ll, ll>  val[MAX];
ll ans[MAX];
ll sum[MAX];
int n;
void compute(){
    f1r(i, 1, n+1){
        vi cur;
        cur.eb(0);
        if(i == 1){
            f1r(j, 1, i+1){
                ll res = 0;
                if(i == 1){
                    res = 1;
                }
                if(i == j) res = 1;
                sum[i] += res;
                cur.eb(res);
            }
            //continue;
        }
        else{
            f1r(j, 1, i+1){
                ll res = choose(i-1, j-1);
                res *= sum[i-j];
                res %= MOD;
                if(i == j) res = 1;
                sum[i] += res;
                cur.eb(res);
            }
        }
        ll ret = 0;
        ll mx = val[i].f;
        ll differ = val[i].s;
        ll prod = 1;
        f1r(it, 1, sz(cur)){
            ll toAdd = cur[it]*(differ-1);
            toAdd %= MOD;
            toAdd *= prod;
            toAdd %= MOD;
            ret += toAdd;
            ret %= MOD;
            prod *= mx;
            prod %= MOD;
        }
        ans[i] = ret;
       ///cout << cur << endl;
    }

}
int main(){
    fast_io();
    cin >> n;
    f0r(i, n){
        int ai;
        cin >> ai;
        a.eb(ai);
    }
    f0r(i, n){
        if(i == 0) fact[i] = 1;
        else{
            fact[i] = fact[i-1]*i;
            fact[i] %= MOD;
        }
    }
    f0r(i, n){
        inv[i] = modInverse(fact[i]);
    }
    int mx = 1;
    f0r(i, n){

        val[n-i] = mp(mx, a[i]);

      // cout << n -i << " " << mx << " " << a[i] << endl;
        mx = max(mx, a[i]);
    }
    compute();
    ll fin = 0;
    f1r(i, 1, n+1){
        fin += ans[i];
        //cout << i << " answers " << ans[i] << endl;
        fin %= MOD;
    }
    cout << fin +1<< endl;
    return 0;
}

Compilation message

teams.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
teams.cpp: In function 'void io(std::__cxx11::string)':
teams.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
teams.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 857 ms 1176 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 225 ms 788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 884 ms 1172 KB Output isn't correct
2 Halted 0 ms 0 KB -