47782023-03-31 12:12:44EyusieLeghosszabb béke (75 pont)cpp17Time limit exceeded 71/75218ms4408 KiB
#include <bits/stdc++.h>

using namespace std;

#define MAXN (int)1e5

int n, k, m, l, mx, counter, indmx, indcur;
bool x, ag1, ag2;
bool a[MAXN + 1]{0};
int i;
int j = 1;

int main()
{
    iostream::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;
    for(; i < k; ++i)
    {
        cin >> m >> l;
        fill(a+m, a+l+1,1);
    }
    for(; j <= n; ++j)
    {
        /*
        if(a[j])
        {
            if(mx < counter)
            {
                indmx = indcur;
                mx = counter;
            }
            counter = 0;
        }
        else
        {
            if(counter == 0)
            {
                indcur = j;
                counter++;
            }
            else counter++;
        }*/

        ag1 = a[j];
        ag2 = !ag1;

        x = ag2*(counter == 0) + ag1*(mx < counter);
        indmx = ag2*indmx + ag1*(indmx*!x + indcur*x);
        mx = ag2*mx + ag1*(mx*!x + counter*x);
        indcur = ag2*(indcur*!x + j*x) + ag1*indcur;
        counter = ag2*(counter+1);

        //cout << ag1 << " " << ag2 << "\n";
        //cout << x << " " << indmx << " " << mx << " " << indcur << " " << counter << "\n";


    }

    if(mx < counter)
    {
        mx = counter;
        indmx = indcur;
    }


    if(mx == 0)
    {
        cout << "-1";
    }
    else cout << mx << " " << indmx;
}
SubtaskSumTestVerdictTimeMemory
base71/75
1Accepted0/03ms1900 KiB
2Accepted0/032ms2324 KiB
3Accepted3/33ms2304 KiB
4Accepted3/33ms2520 KiB
5Accepted3/33ms2736 KiB
6Accepted3/32ms2820 KiB
7Accepted3/33ms2972 KiB
8Accepted4/43ms2968 KiB
9Accepted4/43ms3076 KiB
10Accepted4/43ms3204 KiB
11Accepted4/44ms3416 KiB
12Accepted4/44ms3756 KiB
13Accepted4/44ms3708 KiB
14Accepted4/44ms3968 KiB
15Accepted4/44ms3924 KiB
16Accepted4/44ms3940 KiB
17Accepted4/46ms4076 KiB
18Accepted4/410ms4028 KiB
19Accepted4/439ms4356 KiB
20Accepted4/4162ms4356 KiB
21Time limit exceeded0/4218ms4408 KiB
22Accepted4/4163ms4276 KiB