Educational Codeforces Round 45 (Rated for Div. 2) E - Post Lamps

E - Post Lamps

思路:一开始看错题,以为一个地方不能重复覆盖,我一想值这不是sb题吗,直接每个power check一下就好。。。。复杂度nlogn

然后发现不是,这样的话,对于每个power,假如我们覆盖到了x,那么我们要找到一个最大的 p <= x 且p 可以放灯,那么转移到的

为止为p + power,这样的话我想复杂度就变成了不是严格的nlogn,但是我写了一发还是过了,我感觉是复杂度接近nlogn,感觉没有

数据能把每个power的check都卡成n。

#include
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair
#define piii pair >

using namespace std;

const int N = 1e6 + 7;
const int M = 10 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;

int n, m, k, s[N], a[N], p[N];
bool b[N];
LL ans = -1;
int main() {
    scanf("%d%d%d", &n, &m, &k);

    for(int i = 1; i <= m; i++) {
        scanf("%d", &s[i]);
        b[s[i]] = true;
    }

    for(int i = 1; i <= k; i++) {
        scanf("%d", &a[i]);
    }

    if(b[0]) {
        puts("-1");
        return 0;
    }
    int pre = 0;
    for(int i = 0; i < n; i++) {
        if(!b[i]) pre = i;
        p[i] = pre;
    }

    for(int i = 1; i <= k; i++) {
        bool flag = true;
        LL ret = 0;
        int j = 0;
        while(j < n) {
            if(p[j] + i <= j) {
                flag = false;
                break;
            }
            j = p[j] + i;
            ret += a[i];
        }
        if(flag) {
            if(ans == -1 || ret < ans) {
                ans = ret;
            }
        }
    }

    printf("%lld\n", ans);
    return 0;
}
/*
*/

 

转载于:https://www.cnblogs.com/CJLHY/p/9166917.html

你可能感兴趣的:(Educational Codeforces Round 45 (Rated for Div. 2) E - Post Lamps)