Submission #148316

# Submission time Handle Problem Language Result Execution time Memory
148316 2019-09-01T00:13:18 Z 12tqian Calvinball championship (CEOI15_teams) C++14
80 / 100
1000 ms 1248 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 = 1e6 + 7;
vi a;
map<pii, int> need;
pair<ll, ll>  val[MAX];
ll ans[MAX];
ll sum[MAX];
vector<ll> bin1;
vector<ll> bin2;
int n;
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){
    return bin1[y];
}

void update(){
    bin2.eb(1);
    f0r(i, sz(bin1) - 1){
        ll ret = bin1[i] + bin1[i+1];
        if(ret>= MOD) ret-=MOD;
        //ret%= MOD;
        bin2.eb(ret);
    }
    bin2.eb(1);
    bin1.clear();
    for(auto x: bin2) bin1.eb(x);
    bin2.clear();
}
void compute(){
    f1r(i, 1, n+1){
        vi cur;
        cur.eb(0);
        if(i == 1) bin1.eb(1);
        if(i == 1){
            f1r(j, 1, i+1){
                ll res = 0;
                if(i == 1){
                    res = 1;
                }
                if(i == j) res = 1;
                sum[i] += res;
                if(sum[i]>= MOD) sum[i] -= MOD;
                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;
                if(sum[i] >= MOD) sum[i] -= MOD;
                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;
            if(ret>=MOD) ret-= MOD;
            prod *= mx;
            prod %= MOD;
        }
        ans[i] = ret;
       ///cout << cur << endl;
        update();
    }

}
int main(){
    fast_io();
   // cin >> n;
    scanf("%d", &n);
    f0r(i, n){
        int ai;
        //cin >> ai;
        scanf("%d", &ai);
        a.eb(ai);
    }
    int mx = 1;
    f0r(i, n){
        val[n-i] = mp(mx, a[i]);
        mx = max(mx, a[i]);
    }
    compute();
    ll fin = 0;
    f1r(i, 1, n+1){
        fin += ans[i];
        if(fin>=MOD) fin-= MOD;
        //fin %= MOD;
    }
    printf("%d\n", fin+1);
    //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 'int main()':
teams.cpp:169:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
     printf("%d\n", fin+1);
                    ~~~~~^
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);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
teams.cpp: In function 'int main()':
teams.cpp:150:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
teams.cpp:154:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ai);
         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory 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
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 632 KB Output is correct
2 Correct 14 ms 504 KB Output is correct
3 Correct 13 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1039 ms 1172 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 275 ms 848 KB Output is correct
2 Correct 275 ms 812 KB Output is correct
3 Correct 273 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1025 ms 1248 KB Time limit exceeded
2 Halted 0 ms 0 KB -