27952023-01-25 11:11:41CWMVideójátékcpp11Hibás válasz 10/100186ms8940 KiB
// Videogame.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
//#define int long long
int T;
int lastPlayedGlobal;
struct interval {
    int beginning;
    int end;
};
char intersectionType(interval Me, interval Hano) {
    if (Me.beginning <= Hano.beginning && Me.end >= Hano.beginning) return 'M'; //Intersection when I start playing first
    if (Me.beginning >= Hano.beginning && Hano.end >= Me.beginning) return 'H'; //Intersection when Hano starts playing first
    return 'N'; //No intersection
}
int calcPlayTime(interval Me, interval Hano) {
    char iType = intersectionType(Me, Hano);
    if (iType == 'N') return 0;
    if (iType == 'H') return min(Hano.end, Me.end) - Me.beginning + 1;
    if (iType == 'M') {
        if (lastPlayedGlobal + T + 1 >= Hano.beginning && lastPlayedGlobal!=Me.end) {
            return min(Hano.end, Me.end) - Hano.beginning + 1;
        }
        else {
            lastPlayedGlobal = Me.end;
            return 0;
        }
    }
}
signed main()
{
    cin >> T;
    int meIntervalCount, hanoIntervalCount;
    cin >> meIntervalCount;
    vector<interval> meIntervals;
    vector<interval> hanoIntervals;
    for (size_t i = 0; i < meIntervalCount; i++)
    {
        int a, b;
        cin >> a >> b;
        meIntervals.push_back({ a,b });
    }
    cin >> hanoIntervalCount;
    for (size_t i = 0; i < hanoIntervalCount; i++)
    {
        int a, b;
        cin >> a >> b;
        hanoIntervals.push_back({ a,b });
    }
    int hanoIntervalIndex = 0;
    int meIntervalIndex = 0;
    lastPlayedGlobal = meIntervals[0].beginning;
    int MaxPlayTime = 0;
    while (true) {
        MaxPlayTime+=calcPlayTime(meIntervals[meIntervalIndex], hanoIntervals[hanoIntervalIndex]);
        if (meIntervals[meIntervalIndex].end >= hanoIntervals[hanoIntervalIndex].end) {
            if(lastPlayedGlobal<hanoIntervals[hanoIntervalIndex].end)lastPlayedGlobal = hanoIntervals[hanoIntervalIndex].end;
            hanoIntervalIndex++;
            if (hanoIntervalIndex == hanoIntervalCount) {
                cout << MaxPlayTime << "\n";
                return 0;
            }
        }
        else {
            meIntervalIndex++;
            if (meIntervalIndex == meIntervalCount) {
                cout << MaxPlayTime << "\n";
                return 0;
            }
            else lastPlayedGlobal = meIntervals[meIntervalIndex].beginning-1;
        }
    }
}

// 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
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Hibás válasz3ms1680 KiB
2Elfogadva2ms1884 KiB
subtask210/10
3Elfogadva2ms2080 KiB
4Elfogadva2ms2336 KiB
5Elfogadva2ms2576 KiB
6Elfogadva2ms2776 KiB
7Elfogadva2ms3024 KiB
8Elfogadva2ms3052 KiB
9Elfogadva2ms3268 KiB
10Elfogadva2ms3216 KiB
11Elfogadva2ms3368 KiB
subtask30/20
12Elfogadva2ms3288 KiB
13Elfogadva2ms3376 KiB
14Elfogadva2ms3460 KiB
15Elfogadva2ms3456 KiB
16Elfogadva2ms3464 KiB
17Elfogadva3ms3468 KiB
18Elfogadva3ms3476 KiB
19Elfogadva4ms3748 KiB
20Hibás válasz3ms3616 KiB
21Hibás válasz3ms3684 KiB
22Hibás válasz2ms3768 KiB
subtask40/30
23Elfogadva14ms4368 KiB
24Elfogadva50ms5268 KiB
25Elfogadva123ms8152 KiB
26Elfogadva136ms8284 KiB
27Elfogadva136ms8284 KiB
28Elfogadva54ms6016 KiB
29Hibás válasz10ms4280 KiB
30Hibás válasz10ms4228 KiB
31Hibás válasz6ms4152 KiB
subtask50/40
32Elfogadva16ms4488 KiB
33Elfogadva59ms5688 KiB
34Elfogadva115ms7112 KiB
35Elfogadva164ms8676 KiB
36Elfogadva186ms8860 KiB
37Elfogadva185ms8940 KiB
38Hibás válasz94ms6884 KiB
39Hibás válasz115ms8580 KiB
40Hibás válasz28ms5556 KiB
41Hibás válasz43ms5616 KiB