Cod sursa(job #3232732)

Utilizator Ana_22Ana Petcu Ana_22 Data 1 iunie 2024 10:34:28
Problema Inundatii Scor 0
Compilator cpp-64 Status done
Runda Simulare E4 #1 Marime 0.82 kb
#include <iostream>
#include <fstream>
#define NMAX 50001

using namespace std;

ifstream fin( "inundatii.in" );
ofstream fout( "inundatii.out" );

struct str {
    int x, y, z;
} c[NMAX];

int absv( int a ) {
    return a > 0 ? a : 0;
}

int dist( str a, str b ) {
    return absv( a.x - b.x + 1 ) + absv( a.y - b.y + 1 ) + absv( a.z - b.z + 1 );
}

int main() {
    int n;
    long long s = 0;
    fin >> n;
    for( int i = 1; i <= n; i++ ) {
        fin >> c[i].x >> c[i].y >> c[i].z;
    }
    for( int i = 2; i <= n; i++ ) {
        int d = dist( c[i-1], c[i] );
        s += 1LL * d;
        c[i-1].x++; c[i-1].y++; c[i-1].z++;
        if( dist( c[i-1], c[i+1] ) < dist( c[i], c[i+1] ) ) {
            c[i].x = c[i-1].x;
            c[i].y = c[i-1].y;
            c[i].z = c[i-1].z;
        }
    }
    fout << s;
    return 0;
}