Cod sursa(job #3232771)

Utilizator rockoanaOana Pasca rockoana Data 1 iunie 2024 12:33:22
Problema Inundatii Scor 0
Compilator cpp-64 Status done
Runda Simulare E4 #1 Marime 0.87 kb
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
using i64 = int64_t;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // #ifdef LOCAL
  ifstream cin{"inundatii.in"};
  ofstream cout{"inundatii.out"};
  // #endif

  i64 n;
  cin >> n;

  i64 res = 0;
  i64 x, y, z;
  vector<vector<i64>> v(n);
  for (i64 i = 0; i < n; i++) {
    cin >> x >> y >> z;
    v[i] = {x, y, z};
  }

  for (i64 j = 0; j < 3; j++) {
    for (i64 i = 0; i < n; i++) {
      if (i == 0) {
        if (i + 1 == n) {
          continue;
        }

        res += v[i][j] - v[i + 1][j] + 1;
        v[i][j] = v[i + 1][j] - 1;
      } else if (i < n / 2) {
        res += (i + 1) * (v[i][j] - v[i + 1][j]);
        v[i][j] = v[i + 1][j];
      } else {
        res += v[i - 1][j] - v[i][j] + 1;
        v[i][j] = v[i - 1][j] + 1;
      }
    }
  }

  cout << res;

  return 0;
}