47802023-03-31 12:14:26EyusieLeghosszabb béke (75 pont)cpp17Time limit exceeded 71/75215ms4324 KiB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 100000

int n, k, m, l, mx, counter, indmx, indcur;
bool x, ag1, ag2;
bool a[MAXN + 1];
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/03ms1904 KiB
2Accepted0/032ms2320 KiB
3Accepted3/32ms2200 KiB
4Accepted3/32ms2196 KiB
5Accepted3/33ms2420 KiB
6Accepted3/33ms2548 KiB
7Accepted3/33ms2912 KiB
8Accepted4/42ms2784 KiB
9Accepted4/43ms2932 KiB
10Accepted4/43ms2908 KiB
11Accepted4/44ms3228 KiB
12Accepted4/44ms3192 KiB
13Accepted4/44ms3492 KiB
14Accepted4/44ms3848 KiB
15Accepted4/44ms3648 KiB
16Accepted4/44ms3700 KiB
17Accepted4/46ms3924 KiB
18Accepted4/410ms4036 KiB
19Accepted4/437ms4048 KiB
20Accepted4/4159ms4036 KiB
21Time limit exceeded0/4215ms4324 KiB
22Accepted4/4163ms4288 KiB