Submission #925074

# Submission time Handle Problem Language Result Execution time Memory
925074 2024-02-10T17:00:58 Z Zygno Stove (JOI18_stove) C++17
50 / 100
1000 ms 2908 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

struct guest
{    
    int start;
    int end;
};

struct breakLength
{
    int start;
    int length;
};

int main()
{
    int n; // Number of guests
    int k; // Number of matches

    cin >> n >> k;

    vector<guest> guests(n);    
    vector<breakLength> breaks(n-1);
    for (int i = 0; i < n; i++)
    {
        int temp = 0;
        cin >> temp;
        guests[i].start = temp;
        guests[i].end = temp+1;
        if (i > 0)
        {
            breaks[i-1].start = guests[i].start;
            breaks[i-1].length = guests[i].start - guests[i-1].end; //Length of break between guests
        }
    }

    //Combine guests until there are k guests
    //Order breaks by length
    sort(breaks.begin(), breaks.end(), [](breakLength a, breakLength b) { return a.length < b.length; });

    int i = 0;
    while(n - i > k)
    {
        for(int j = 0; j < n; j++)
        {            
            if(breaks[i].start == guests[j].start)
            {
                int x = 1;
                while(guests[j-x].end == -1)
                {
                    x++;
                }
                guests[j-x].end = guests[j].end;
                guests[j].end = -1;
                break;
            }        
        }
        i++;
    }

    for(int i = n-1; i >= 0; i--)
    {
        if(guests[i].end == -1)
        {
            guests.erase(guests.begin() + i);
        }        
    }

    int stove = 0;
    n = guests.size();
    for(int i = 0; i < n; i++)
    {
        stove += guests[i].end - guests[i].start;
    }

    cout << stove << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 400 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 444 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 596 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 436 KB Output is correct
9 Correct 0 ms 400 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 444 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Execution timed out 1066 ms 2908 KB Time limit exceeded
17 Halted 0 ms 0 KB -