29922023-02-07 12:52:55bzsofiaVideójátékcpp11Wrong answer 10/100186ms11080 KiB
// Videogames.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct adat
{
    long long beg, ends;
};

long long i, n, m, t, j, sum;

bool comp (adat a, adat b)
{
    if (a.beg==b.beg) return a.ends<b.ends;
    return a.beg<b.beg;
}

int main()
{
    cin >> t >> n;
    vector <adat> x(n + 1);

    for (i = 1; i <= n; ++i)
    {
        cin >> x[i].beg >> x[i].ends;
    }

    cin >> m;
    vector <adat> y(m + 1);
    for (i = 1; i <= m; ++i)
    {
        cin >> y[i].beg >> y[i].ends;
    }

    i=1;
    j=1;
    while (i<=n && j<=m)
    {
        if (x[i].ends<y[j].beg) ++i;
        else if (y[j].ends<x[i].beg) ++j;
        else if (x[i].ends==y[j].ends && x[i].beg==y[j].ends)
        {
            ++i;
            ++j;
            sum+=x[i].ends-x[i].beg+1;
        }else if (x[i].beg<y[j].beg)
        {
            if (y[j].beg-x[i].beg<t)
            {
                if (y[j].ends>x[i].ends)
                {
                    if (x[i].ends==y[j].beg)
                    {
                        sum+=1;
                        ++i;
                    }
                    else
                    {
                        sum+=x[i].ends-y[j].beg+1;
                        ++i;
                    }
                }else if (y[j].ends==x[i].ends)
                {
                    sum+=y[j].ends-y[j].beg+1;
                    ++i;
                    ++j;
                }else
                {
                    sum+=y[j].ends-y[j].beg+1;
                    x[i].beg=y[j].ends+1;
                    ++j;
                }
            }
            else
            {
                if (y[j].ends<=x[i].ends) ++j;
                ++i;
            }
        }else if (x[i].beg==y[j].beg)
        {
            if (x[i].ends<y[j].ends)
            {
                sum+=x[i].ends-x[i].beg+1;
                ++i;
            }else
            {
                sum+=y[j].ends-y[j].beg+1;
                x[i].beg=y[j].ends+1;
                ++j;
            }
        }
        else
        {
            if (x[i].beg==y[j].ends)
            {
                sum+=1;
                ++x[i].beg;
                ++j;
            }
            else if (x[i].ends<y[j].ends)
            {
                sum+=x[i].ends-x[i].beg+1;
                ++i;
            }else if (x[i].ends == y[j].ends)
            {
                sum+=x[i].ends-x[i].beg+1;
                ++i;
                ++j;
            }else
            {
                sum+=y[j].ends-x[i].beg+1;
                x[i].beg=y[j].ends+1;
                ++j;
            }
        }
    }

    cout << sum;

    return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2060 KiB
subtask210/10
3Accepted3ms2304 KiB
4Accepted3ms2512 KiB
5Accepted3ms2728 KiB
6Accepted3ms2976 KiB
7Accepted3ms3020 KiB
8Accepted3ms3264 KiB
9Accepted3ms3392 KiB
10Accepted3ms3608 KiB
11Accepted3ms3696 KiB
subtask30/20
12Accepted3ms3784 KiB
13Accepted3ms3784 KiB
14Accepted3ms3792 KiB
15Accepted3ms3908 KiB
16Accepted3ms3908 KiB
17Accepted4ms4032 KiB
18Accepted4ms4032 KiB
19Accepted4ms4044 KiB
20Wrong answer4ms4312 KiB
21Wrong answer3ms4456 KiB
22Wrong answer3ms4440 KiB
subtask40/30
23Accepted14ms4892 KiB
24Accepted50ms6252 KiB
25Accepted123ms10068 KiB
26Accepted137ms10676 KiB
27Accepted136ms10668 KiB
28Accepted54ms7152 KiB
29Wrong answer12ms5192 KiB
30Wrong answer10ms5184 KiB
31Wrong answer7ms5000 KiB
subtask50/40
32Wrong answer17ms5364 KiB
33Accepted61ms7244 KiB
34Accepted115ms8972 KiB
35Accepted164ms10408 KiB
36Accepted186ms11080 KiB
37Accepted185ms11080 KiB
38Wrong answer94ms8768 KiB
39Wrong answer114ms9416 KiB
40Wrong answer29ms5924 KiB
41Wrong answer45ms6688 KiB