码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card

时间:2018-06-24 19:28:04      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:bit   size   space   ret   pre   clu   pair   ems   for   

D - Travel Card

思路:dp,类似于单调队列优化。

其实可以写的更简单。。。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int>

using namespace std;

const int N = 1e5 + 7;
const int M = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 +7;

int n, t[N], dp[N][3], mn[N], a[N];
int st1[N], st2[N], head1, head2, rear1, rear2;

int main() {
    memset(dp, inf, sizeof(dp));
    memset(mn, inf, sizeof(mn));
    mn[0] = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &t[i]);
    }

    dp[1][0] = 20;
    dp[1][1] = 50;
    dp[1][2] = 120;

    st1[rear1++] = 1;
    st2[rear2++] = 1;

    for(int i = 2; i <= n; i++) {
        for(int j = 0; j < 3; j++) mn[i - 1] = min(mn[i - 1], dp[i - 1][j]);
        dp[i][1] = mn[i - 1] + 50;
        dp[i][2] = mn[i - 1] + 120;
        dp[i][0] = mn[i - 1] + 20;
        while(head1 < rear1 && t[i] - t[st1[head1]] >= 90) head1++;
        while(head2 < rear2 && t[i] - t[st2[head2]] >= 1440) head2++;

        if(head1 < rear1) dp[i][0] = min(dp[i][0], dp[st1[head1]][1]);
        if(head2 < rear2) dp[i][0] = min(dp[i][0], dp[st2[head2]][2]);

        while(head1 < rear1 && dp[i][1] < dp[st1[rear1 - 1]][1]) rear1--;
        while(head2 < rear2 && dp[i][2] < dp[st2[rear2 - 1]][1]) rear2--;

        st1[rear1++] = i;
        st2[rear2++] = i;
    }

    for(int j = 0; j < 3; j++) {
        mn[n] = min(mn[n], dp[n][j]);
    }

    for(int i = 1; i <= n; i++) {
        printf("%d\n", mn[i] - mn[i - 1]);
    }
    return 0;
}
/*
*/

 

Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) D - Travel Card

标签:bit   size   space   ret   pre   clu   pair   ems   for   

原文地址:https://www.cnblogs.com/CJLHY/p/9221161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!