2991 | 2023-02-07 12:52:16 | bzsofia | Videójáték | cpp11 | Wrong answer 10/100 | 186ms | 10336 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
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1816 KiB | ||||
2 | Accepted | 3ms | 2004 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 3ms | 2216 KiB | ||||
4 | Accepted | 3ms | 2456 KiB | ||||
5 | Accepted | 3ms | 2672 KiB | ||||
6 | Accepted | 3ms | 2752 KiB | ||||
7 | Accepted | 3ms | 2968 KiB | ||||
8 | Accepted | 3ms | 3220 KiB | ||||
9 | Accepted | 3ms | 3300 KiB | ||||
10 | Accepted | 3ms | 3308 KiB | ||||
11 | Accepted | 3ms | 3392 KiB | ||||
subtask3 | 0/20 | ||||||
12 | Accepted | 3ms | 3636 KiB | ||||
13 | Accepted | 3ms | 3480 KiB | ||||
14 | Accepted | 3ms | 3624 KiB | ||||
15 | Accepted | 3ms | 3696 KiB | ||||
16 | Accepted | 3ms | 3692 KiB | ||||
17 | Accepted | 3ms | 3836 KiB | ||||
18 | Accepted | 4ms | 3924 KiB | ||||
19 | Accepted | 4ms | 3816 KiB | ||||
20 | Wrong answer | 3ms | 3888 KiB | ||||
21 | Wrong answer | 4ms | 3936 KiB | ||||
22 | Accepted | 3ms | 4000 KiB | ||||
subtask4 | 0/30 | ||||||
23 | Accepted | 14ms | 4392 KiB | ||||
24 | Accepted | 50ms | 5872 KiB | ||||
25 | Accepted | 123ms | 9380 KiB | ||||
26 | Accepted | 136ms | 10032 KiB | ||||
27 | Accepted | 137ms | 10032 KiB | ||||
28 | Accepted | 54ms | 6408 KiB | ||||
29 | Accepted | 10ms | 4360 KiB | ||||
30 | Accepted | 10ms | 4328 KiB | ||||
31 | Wrong answer | 7ms | 4100 KiB | ||||
subtask5 | 0/40 | ||||||
32 | Accepted | 17ms | 4396 KiB | ||||
33 | Accepted | 63ms | 6412 KiB | ||||
34 | Accepted | 115ms | 8056 KiB | ||||
35 | Accepted | 163ms | 9492 KiB | ||||
36 | Accepted | 186ms | 10156 KiB | ||||
37 | Accepted | 186ms | 10336 KiB | ||||
38 | Accepted | 94ms | 8000 KiB | ||||
39 | Accepted | 114ms | 8472 KiB | ||||
40 | Wrong answer | 28ms | 4828 KiB | ||||
41 | Wrong answer | 43ms | 5744 KiB |