답안 #211468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211468 2020-03-20T12:50:29 Z mayhoubsaleh Visiting Singapore (NOI20_visitingsingapore) C++14
100 / 100
502 ms 892 KB
/*#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
const int inf=1e9+10;
const int maxn=1e6+100;

int n,s,k;
int nxt[maxn][20],pos[maxn],pre[maxn];
int sh[maxn];
int main()
{
    IOS
    cin>>n>>s>>k;
    pos[1]=0;
    for(int i=2;i<=n;i++){
        cin>>pos[i];
        pos[i]+=pos[i-1];
    }
    for(int i=1;i<=n;i++){
        cin>>pre[i];
        pre[i]+=pre[i-1];
        //cout<<pre[i]<<' ';
    }
    pre[n+1]=pre[n];
    for(int i=1;i<=n;i++){
        int id=upper_bound(pos+i,pos+n+1,pos[i]+k)-pos;
        id--;
        sh[i]=id;
        nxt[i][0]=upper_bound(pos+id,pos+n+1,pos[id]+k)-pos;
        //cout<<nxt[i][0]<<' ';
    }

    for(int i=1;i<20;i++){
        for(int id=1;id<=n;id++){
            nxt[id][i]=nxt[nxt[id][i-1]][i-1];
            if(!nxt[id][i])nxt[id][i]=n+1;
        }
    }
    pair<int,int>mx={-1,-1};
    for(int l=1;l<=n;l++){
        int r=l;
        for(int i=0;i<20;i++){
            if(((1<<i)&s))r=nxt[r][i];
        }
        //cout<<l<<' '<<r<<endl;
        mx=max(mx,{pre[r-1]-pre[l-1],l});
    }
    vector<int>ans;
    int l=mx.second;
    while(l<=n&&s){
        ans.pb(sh[l]);
        l=nxt[l][0];
        s--;
    }

    cout<<ans.size()<<endl;
    for(auto x:ans)cout<<x<<' ';cout<<endl;
    return 0;
}
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;
const ll inf=1e9+10;
const ll maxn=10050;
ll n,m,k,a,b;
ll s[maxn],val[maxn],t[maxn];
ll dp[maxn][2][2][2];
bool vis[maxn][maxn][2][2];
ll solve(ll day,ll sc,ll f1,ll f2){
    if(vis[day][sc][f1][f2])return dp[day][sc][f1][f2];
    vis[day][sc][f1][f2]=1;
    ll &ans=dp[day][sc][f1][f2];
    ans=-1e9;
    if(sc==m)return ans=0;
    if(day==n)return ans=solve(day,sc+1,f1,0)-b-a*f2;
    ans=max(ans,solve(day,sc+1,f1,0)-b-a*f2);
    ans=max(ans,solve(day+1,sc,0,f2)-b-a*f1);
    if(s[day]==t[sc])ans=max(ans,val[s[day]]+solve(day+1,sc+1,1,1));
    return ans;
}
int main()
{
    IOS
    cin>>k>>n>>m>>a>>b;
    for(ll i=1;i<=k;i++)cin>>val[i];
    for(ll i=0;i<n;i++)cin>>s[i];
    for(ll i=0;i<m;i++)cin>>t[i];
    a=-a;
    b=-b;

    for(ll i=0;i<n+10;i++){
        for(ll j=0;j<2;j++){
            for(ll k=0;k<2;k++){
                for(ll l=0;l<2;l++){
                    dp[i][j][k][l]=-1e9;
                }
            }
        }
    }
    int cur=0;
    for(ll day=0;day<n+10;day++){
        for(ll f1=0;f1<2;f1++){
            for(ll f2=0;f2<2;f2++){
                dp[day][cur][f1][f2]=0;
            }
        }
    }

    for(ll sc=m-1;sc>=0;sc--){
        cur=1-cur;
        for(ll day=n;day>=0;day--){
            for(ll f1=0;f1<2;f1++){
                for(ll f2=0;f2<2;f2++){
                    ll &ans=dp[day][cur][f1][f2];
                    ans=-1e9;
                    if(day==n){ans=dp[day][1-cur][f1][0]-b-a*f2;continue;}
                    ans=max(ans,dp[day][1-cur][f1][0]-b-a*f2);
                    ans=max(ans,dp[day+1][cur][0][f2]-b-a*f1);
                    if(s[day]==t[sc])ans=max(ans,dp[day+1][1-cur][1][1]+val[s[day]]);
                }
            }
        }
    }
    ll ans=-a-b*m;
    for(ll i=0;i<=n;i++){
        ans=max(ans,dp[i][cur][1][1]);
    }
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 20 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 13 ms 384 KB Output is correct
10 Correct 23 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 9 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 13 ms 384 KB Output is correct
7 Correct 13 ms 384 KB Output is correct
8 Correct 17 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 23 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 512 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 125 ms 640 KB Output is correct
4 Correct 301 ms 756 KB Output is correct
5 Correct 90 ms 512 KB Output is correct
6 Correct 128 ms 512 KB Output is correct
7 Correct 241 ms 888 KB Output is correct
8 Correct 80 ms 640 KB Output is correct
9 Correct 157 ms 640 KB Output is correct
10 Correct 367 ms 768 KB Output is correct
11 Correct 370 ms 768 KB Output is correct
12 Correct 369 ms 768 KB Output is correct
13 Correct 370 ms 888 KB Output is correct
14 Correct 467 ms 768 KB Output is correct
15 Correct 459 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 512 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 125 ms 640 KB Output is correct
4 Correct 301 ms 756 KB Output is correct
5 Correct 90 ms 512 KB Output is correct
6 Correct 128 ms 512 KB Output is correct
7 Correct 241 ms 888 KB Output is correct
8 Correct 80 ms 640 KB Output is correct
9 Correct 157 ms 640 KB Output is correct
10 Correct 367 ms 768 KB Output is correct
11 Correct 370 ms 768 KB Output is correct
12 Correct 369 ms 768 KB Output is correct
13 Correct 370 ms 888 KB Output is correct
14 Correct 467 ms 768 KB Output is correct
15 Correct 459 ms 888 KB Output is correct
16 Correct 217 ms 640 KB Output is correct
17 Correct 245 ms 888 KB Output is correct
18 Correct 205 ms 768 KB Output is correct
19 Correct 46 ms 512 KB Output is correct
20 Correct 161 ms 704 KB Output is correct
21 Correct 14 ms 512 KB Output is correct
22 Correct 51 ms 512 KB Output is correct
23 Correct 95 ms 512 KB Output is correct
24 Correct 37 ms 632 KB Output is correct
25 Correct 371 ms 888 KB Output is correct
26 Correct 372 ms 828 KB Output is correct
27 Correct 397 ms 888 KB Output is correct
28 Correct 365 ms 768 KB Output is correct
29 Correct 502 ms 808 KB Output is correct
30 Correct 457 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 512 KB Output is correct
2 Correct 19 ms 512 KB Output is correct
3 Correct 125 ms 640 KB Output is correct
4 Correct 301 ms 756 KB Output is correct
5 Correct 90 ms 512 KB Output is correct
6 Correct 128 ms 512 KB Output is correct
7 Correct 241 ms 888 KB Output is correct
8 Correct 80 ms 640 KB Output is correct
9 Correct 157 ms 640 KB Output is correct
10 Correct 367 ms 768 KB Output is correct
11 Correct 370 ms 768 KB Output is correct
12 Correct 369 ms 768 KB Output is correct
13 Correct 370 ms 888 KB Output is correct
14 Correct 467 ms 768 KB Output is correct
15 Correct 459 ms 888 KB Output is correct
16 Correct 326 ms 768 KB Output is correct
17 Correct 157 ms 640 KB Output is correct
18 Correct 47 ms 512 KB Output is correct
19 Correct 15 ms 384 KB Output is correct
20 Correct 10 ms 384 KB Output is correct
21 Correct 13 ms 384 KB Output is correct
22 Correct 148 ms 660 KB Output is correct
23 Correct 31 ms 512 KB Output is correct
24 Correct 254 ms 768 KB Output is correct
25 Correct 372 ms 768 KB Output is correct
26 Correct 383 ms 824 KB Output is correct
27 Correct 405 ms 768 KB Output is correct
28 Correct 366 ms 768 KB Output is correct
29 Correct 445 ms 768 KB Output is correct
30 Correct 450 ms 892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 20 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 6 ms 384 KB Output is correct
9 Correct 13 ms 384 KB Output is correct
10 Correct 23 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 256 KB Output is correct
13 Correct 9 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 13 ms 384 KB Output is correct
17 Correct 13 ms 384 KB Output is correct
18 Correct 17 ms 384 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 23 ms 384 KB Output is correct
21 Correct 40 ms 512 KB Output is correct
22 Correct 19 ms 512 KB Output is correct
23 Correct 125 ms 640 KB Output is correct
24 Correct 301 ms 756 KB Output is correct
25 Correct 90 ms 512 KB Output is correct
26 Correct 128 ms 512 KB Output is correct
27 Correct 241 ms 888 KB Output is correct
28 Correct 80 ms 640 KB Output is correct
29 Correct 157 ms 640 KB Output is correct
30 Correct 367 ms 768 KB Output is correct
31 Correct 370 ms 768 KB Output is correct
32 Correct 369 ms 768 KB Output is correct
33 Correct 370 ms 888 KB Output is correct
34 Correct 467 ms 768 KB Output is correct
35 Correct 459 ms 888 KB Output is correct
36 Correct 217 ms 640 KB Output is correct
37 Correct 245 ms 888 KB Output is correct
38 Correct 205 ms 768 KB Output is correct
39 Correct 46 ms 512 KB Output is correct
40 Correct 161 ms 704 KB Output is correct
41 Correct 14 ms 512 KB Output is correct
42 Correct 51 ms 512 KB Output is correct
43 Correct 95 ms 512 KB Output is correct
44 Correct 37 ms 632 KB Output is correct
45 Correct 371 ms 888 KB Output is correct
46 Correct 372 ms 828 KB Output is correct
47 Correct 397 ms 888 KB Output is correct
48 Correct 365 ms 768 KB Output is correct
49 Correct 502 ms 808 KB Output is correct
50 Correct 457 ms 768 KB Output is correct
51 Correct 326 ms 768 KB Output is correct
52 Correct 157 ms 640 KB Output is correct
53 Correct 47 ms 512 KB Output is correct
54 Correct 15 ms 384 KB Output is correct
55 Correct 10 ms 384 KB Output is correct
56 Correct 13 ms 384 KB Output is correct
57 Correct 148 ms 660 KB Output is correct
58 Correct 31 ms 512 KB Output is correct
59 Correct 254 ms 768 KB Output is correct
60 Correct 372 ms 768 KB Output is correct
61 Correct 383 ms 824 KB Output is correct
62 Correct 405 ms 768 KB Output is correct
63 Correct 366 ms 768 KB Output is correct
64 Correct 445 ms 768 KB Output is correct
65 Correct 450 ms 892 KB Output is correct
66 Correct 4 ms 384 KB Output is correct
67 Correct 4 ms 384 KB Output is correct
68 Correct 5 ms 384 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 4 ms 384 KB Output is correct
71 Correct 4 ms 384 KB Output is correct
72 Correct 4 ms 384 KB Output is correct
73 Correct 4 ms 384 KB Output is correct
74 Correct 4 ms 384 KB Output is correct
75 Correct 5 ms 384 KB Output is correct
76 Correct 5 ms 384 KB Output is correct
77 Correct 4 ms 384 KB Output is correct
78 Correct 5 ms 384 KB Output is correct
79 Correct 5 ms 384 KB Output is correct
80 Correct 5 ms 432 KB Output is correct
81 Correct 294 ms 768 KB Output is correct
82 Correct 71 ms 640 KB Output is correct
83 Correct 135 ms 640 KB Output is correct
84 Correct 73 ms 512 KB Output is correct
85 Correct 119 ms 640 KB Output is correct
86 Correct 103 ms 640 KB Output is correct
87 Correct 21 ms 384 KB Output is correct
88 Correct 15 ms 384 KB Output is correct
89 Correct 45 ms 512 KB Output is correct
90 Correct 414 ms 768 KB Output is correct
91 Correct 367 ms 888 KB Output is correct
92 Correct 364 ms 768 KB Output is correct
93 Correct 364 ms 768 KB Output is correct
94 Correct 372 ms 768 KB Output is correct
95 Correct 370 ms 892 KB Output is correct
96 Correct 367 ms 768 KB Output is correct
97 Correct 376 ms 888 KB Output is correct
98 Correct 444 ms 768 KB Output is correct
99 Correct 456 ms 888 KB Output is correct
100 Correct 457 ms 768 KB Output is correct