답안 #152676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152676 2019-09-09T06:55:11 Z toloraia Calvinball championship (CEOI15_teams) C++14
100 / 100
242 ms 760 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
//#pragma comment(linker, "/STACK: 20000000005")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

const ll N = 1e4 + 5, MOD = 1e6 + 7;

int n;
ll a[N];

ll A[N], B[N];

ll ans;
ll dp[N];

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ll mx = 1;
    ans = a[n];
    for (int i = 2; i < n; i++){
        if (a[i] == 1)
            continue;
        A[n - i] = mx;
        B[n - i] = a[i] - 1;
        mx = max (mx, a[i]);
    }
    for (int i = 0; i <= n; i++)
        dp[i] = 1;
    for (int i = 1; i <= n; i++){
        for (ll j = 0; j <= n; j++)
            dp[j] = (dp[j + 1] + j * dp[j]) % MOD;
        ans = (ans + B[i] * dp[A[i]]) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Compilation message

teams.cpp:17:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
teams.cpp:18:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
teams.cpp:31:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# 결과 실행 시간 메모리 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 376 KB Output is correct
6 Correct 3 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 8 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 Correct 2 ms 348 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 Correct 3 ms 380 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 220 ms 704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 556 KB Output is correct
2 Correct 53 ms 504 KB Output is correct
3 Correct 53 ms 572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 688 KB Output is correct
2 Correct 242 ms 760 KB Output is correct
3 Correct 205 ms 744 KB Output is correct