27942023-01-25 11:03:20CWMVideójátékcpp11Wrong answer 10/100188ms8792 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-1;
            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
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer3ms1808 KiB
2Accepted2ms2056 KiB
subtask210/10
3Accepted2ms2244 KiB
4Accepted2ms2496 KiB
5Accepted2ms2572 KiB
6Accepted2ms2680 KiB
7Accepted2ms2876 KiB
8Accepted2ms3032 KiB
9Accepted2ms3108 KiB
10Accepted2ms3268 KiB
11Accepted2ms3128 KiB
subtask30/20
12Accepted2ms3240 KiB
13Wrong answer2ms3480 KiB
14Wrong answer2ms3688 KiB
15Accepted2ms3652 KiB
16Accepted2ms3536 KiB
17Wrong answer3ms3432 KiB
18Wrong answer3ms3432 KiB
19Accepted4ms3436 KiB
20Wrong answer3ms3432 KiB
21Wrong answer3ms3564 KiB
22Wrong answer2ms3632 KiB
subtask40/30
23Accepted14ms4284 KiB
24Accepted50ms5516 KiB
25Accepted123ms8180 KiB
26Accepted136ms8408 KiB
27Accepted136ms8732 KiB
28Accepted54ms6136 KiB
29Wrong answer10ms4376 KiB
30Wrong answer10ms4352 KiB
31Wrong answer6ms4200 KiB
subtask50/40
32Wrong answer16ms4668 KiB
33Accepted61ms5756 KiB
34Accepted115ms7232 KiB
35Accepted164ms8792 KiB
36Accepted185ms8720 KiB
37Accepted188ms8724 KiB
38Wrong answer94ms6648 KiB
39Wrong answer115ms8324 KiB
40Wrong answer28ms5340 KiB
41Wrong answer43ms5284 KiB