답안 #424528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424528 2021-06-12T04:33:51 Z cpp219 Calvinball championship (CEOI15_teams) C++14
100 / 100
238 ms 656 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e4 + 9;
const ll mod = 1e6 + 7;
typedef pair<ll,ll> LL;

ll n,x,ans = 1,a[N],prv[N],dp[N];

ll mx[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin>>n; memset(dp,-1,sizeof(dp));
    for (ll i = 1;i <= n;i++) cin>>a[i],mx[i] = max(mx[i - 1],a[i]);
    ans += a[n] - 1;
    for (ll i = 1;i <= n;i++) dp[i] = i;
    for (ll i = n - 1;i > 0;i--){
        for (ll i = 1;i <= n;i++) prv[i] = dp[i];
        for (ll i = 1;i <= n;i++) dp[i] = ((i - 1)*prv[i] + prv[i + 1])%mod;
        ll x = a[i],now = mx[i - 1];
        ans += (x - 1)*prv[now + 1]; ans %= mod;
        //cout<<(x - 1)*prv[now + 1]<<"x\n";
    }
    cout<<ans;
}

Compilation message

teams.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
teams.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
teams.cpp: In function 'int main()':
teams.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
teams.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 225 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 460 KB Output is correct
2 Correct 58 ms 460 KB Output is correct
3 Correct 60 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 233 ms 608 KB Output is correct
2 Correct 238 ms 640 KB Output is correct
3 Correct 230 ms 656 KB Output is correct