Kick Start 2018 Round D Candies

First posted a big dataset can not pass code can be added later through one of:

#include<bits/stdc++.h>
#define INF 9223372036854775807

int main()
{
    using namespace std;
    int T;
    cin >>T;
    int co = 1;
    while(T--)
    {
        long long D;
        int N,O;
        long long x[50005];
        int A,B,C,M,L;
        cin >> N >> O >>D;
        cin >> x[0] >> x[1] >> A >> B >>C >> M >>L;
        for(int i = 2;i < N;i++)
        {
            x[i] = (A * x[i-1] + B * x[i-2] + C) % M;
            x[i - 2] += L;
        }
        x[N-1] += L;
        x[N-2] += L;                                                 //
        
        long long ss = -INF;
        int o = 0;
        long long d;
        for(int i = 0;i < N;i ++)
        {
            d = 0;
            o = 0;
            for(int k = 0;o <= O && d < D && i + k < N;k ++)
            {
                d += x[i + k];                                       //应使用前缀和 
                o += x[i + k]%2;
                if(d <= D && d > ss && o <= O)                       //
                {
                    ss = d;
                }
            }
        }
        cout << "Case #" << co ++ << ": ";
        if(ss == -INF)
        {
            cout << "IMPOSSIBLE" << endl;
        }
        else cout << ss << endl;
    }
}

 

Guess you like

Origin www.cnblogs.com/my-growth/p/12518346.html