QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: rex333

Posted at:

Last updated:

Back to Problem

New Editorial for Problem #11429

Lire dans d’autres langues: Original English

include

using namespace std;

define ll long long

define all(a) a.begin(), a.end()

define sz(a) int(a.size())

define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int main() { int n; cin >> n;

vector<pair<pair<int, int>, string>> sch(n);
for(int i = 0; i < n; i++)
{
    string first, second;
    cin >> first >> second;

    sch[i].second = first;
    int salida_mins = 0, salida_hora = 0;
    int llegada_mins = 0, llegada_hora = 0;

    if(second[2] == ':')
    {
        salida_hora = 10 * (second[0] - '0');
        salida_hora += (second[1] - '0');
        salida_mins = 10 * (second[3] - '0');
        salida_mins += (second[4] - '0');
    }
    else
    {
        salida_hora += (second[0] - '0');
        salida_mins = 10 * (second[2] - '0');
        salida_mins += (second[3] - '0');
    }

    int pos = 1;
    while(second[pos - 1] != '-') pos++;
    second.erase(0, pos + 1);

    if(second[2] == ':')
    {
        llegada_hora = 10 * (second[0] - '0');
        llegada_hora += (second[1] - '0');
        llegada_mins = 10 * (second[3] - '0');
        llegada_mins += (second[4] - '0');
    }
    else
    {
        llegada_hora += (second[0] - '0');
        llegada_mins = 10 * (second[2] - '0');
        llegada_mins += (second[3] - '0');
    }


    sch[i].first.first = (salida_hora * 60) + salida_mins; 
    sch[i].first.second = (llegada_hora * 60) + llegada_mins;
}

int ans = INT_MAX;
for(int i = 0; i < n; i++)
{
    for(int j = 0; j < n; j++)
    {
        if(sch[i].second == sch[j].second) continue;
        if(sch[i].second == "Graz-Wroclaw") continue;

        int dif1 = sch[i].first.second - sch[i].first.first;
        while(dif1 < 0) dif1 += (24 * 60);
        int calc = dif1;

        int dif2 = sch[j].first.second - sch[j].first.first;
        while(dif2 < 0) dif2 += (24 * 60);
        calc += dif2;

        int in_between = sch[j].first.first - sch[i].first.second;
        while(in_between <= 0) in_between += (24 * 60);
        in_between++;

        calc += in_between;
        ans = min(ans, calc);
    }
}

if(ans == INT_MAX) cout << "NEMOGUCE";
else
{
    int total = ans;
    int horas = total / 60;
    int minutos = total % 60;

    string str = "";
    if((horas / 10) > 0) str += char((horas / 10) + '0');
    str += char((horas % 10) + '0');
    str += ":";
    str += char((minutos / 10) + '0');
    str += char((minutos % 10) + '0');
    cout << str;
}
return 0;

}

Comments

No comments yet.