WORK #5

 avatar
unknown
c_cpp
2 years ago
1.1 kB
6
Indexable
#include <bits/stdc++.h>
using namespace std;

#define ll long long

int inf = 10000000;
int times[4][3];

vector<vector<vector<int>>> route = {
    {},
    {{1}, {0, 3, 2}},
    {{1, 2}, {0, 3}},
    {{0}, {1, 2, 3}}
};

int calc_route(vector<int> v) {
    int tm = 0;
    for (auto ind : v) {
        int r = times[ind][0], g = times[ind][1], w = times[ind][2];
        if(w > g) return inf;
        int tmp = tm % (r + g);
        if(tmp < r) {
            tm += max(r - tmp, g);
            tmp = r;
        }
        if(w > r + g - tmp) {
            tm += -tmp + r + g + r + w;
        }
        else tm += w;
    }
    return tm;
}


int main() {
    int ang; 
    cin >> ang;
    if(ang == 12) {
        cout << '0\n';
        return 0;
    }
    if(ang == 23) ang = 1;
    if(ang == 34) ang = 2;
    if(ang == 41) ang = 3;
    for(int i = 0; i < 4; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> times[i][j];
        }
    }
    int ans = inf;
    for(auto v : route[ang]) {
        ans = min(ans, calc_route(v));
    }
    cout << ans << '\n';
}
Editor is loading...