47842023-03-31 12:20:11EyusieLeghosszabb béke (75 pont)cpp17Időlimit túllépés 71/75204ms4424 KiB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 100000

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

inline void fastscan(int &number)
{
    //variable to indicate sign of input number
    register int c;

    number = 0;

    // extract current character from buffer
    c = getchar();

    // Keep on extracting characters if they are integers
    // i.e ASCII Value lies from '0'(48) to '9' (57)
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
}

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

    //register bool x, ag1, ag2, neg_x;

    fastscan(n);
    fastscan(k);
    for(; i < k; ++i)
    {
        fastscan(m);
        fastscan(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);
        neg_x = !x;
        indmx = ag2*indmx + ag1*(indmx*neg_x + indcur*x);
        mx = ag2*mx + ag1*(mx*neg_x + counter*x);
        indcur = ag2*(indcur*neg_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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base71/75
1Elfogadva0/03ms1776 KiB
2Elfogadva0/019ms2196 KiB
3Elfogadva3/33ms2264 KiB
4Elfogadva3/32ms2340 KiB
5Elfogadva3/33ms2420 KiB
6Elfogadva3/33ms2576 KiB
7Elfogadva3/32ms2656 KiB
8Elfogadva4/42ms2660 KiB
9Elfogadva4/43ms2804 KiB
10Elfogadva4/43ms3128 KiB
11Elfogadva4/43ms3340 KiB
12Elfogadva4/44ms3452 KiB
13Elfogadva4/43ms3648 KiB
14Elfogadva4/43ms3728 KiB
15Elfogadva4/44ms3604 KiB
16Elfogadva4/44ms3624 KiB
17Elfogadva4/44ms3888 KiB
18Elfogadva4/49ms4196 KiB
19Elfogadva4/428ms4196 KiB
20Elfogadva4/4146ms4360 KiB
21Időlimit túllépés0/4204ms4316 KiB
22Elfogadva4/4149ms4424 KiB