제출 #1255694

#제출 시각아이디문제언어결과실행 시간메모리
1255694madamadam33개의 봉우리 (IOI25_triples)C++20
0 / 100
771 ms2768 KiB
#include "triples.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pi = pair<int, int>;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define each(a, x) for (auto &a : x)
#define all(x) (x).begin(), (x).end()
#define bg(x) (x).begin()
#define en(x) (x).end()
#define rev(x) reverse(all(x))
#define sz(x) int((x).size())
#define srt(x) sort(all(x))
#define cnt(a, x) count(all(x), a)
#define trace(x) each(a, (x)) cout << a << " "
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

struct DSU {
  int n; vi par, siz;

  DSU() {};
  DSU(int N) {
    n = N; par.resize(n); siz.assign(n, 1);
    iota(all(par), 0);
  }

  int find(int v) {
    if (par[v] == v) return v;
    return par[v] = find(par[v]);
  }

  void unite(int a, int b) {
    a = find(a); b = find(b);
    if (a != b) {
      if (siz[a] < siz[b]) swap(a, b);
      par[b] = a;
      siz[a] += siz[b];
    }
  }
};

ll brute(vi h) {
  int n = sz(h);
  ll ans = 0;

  // cerr << "brute function: \n";
  FOR(i, 0, n) {
    FOR(j, i+1, i+12) {
      FOR(k, j+1, j+12) {
        vi d = {k - j, k - i, j - i}, f = {h[i], h[j], h[k]};
        srt(d); srt(f);
        bool valid = d[0] == f[0] && d[1] == f[1] && d[2] == f[2];
        if (!valid) continue;
        ans++;
        // cerr << i << " " << j << " " << k << "\n";
      }
    }
  }

  return ans;
}

ll count_triples(vi h) {
  int n = sz(h);
  return brute(h);
  
  // cerr << "smart function: \n";
  // ll ans = 0;
  // FOR(i, 0, n) {
  //   FOR(j, 0, i) {
  //     // for a given pair (i, j) the possible values for k are i - h[i], i - h[j], j+h[i], j+h[j]
  //     int dist = i - j;
  //     vi K = {i-h[i], i-h[j], j+h[i], j+h[j]};
  //     set<int> seen;

  //     each(k, K) {
  //       if (!(j < k && k < i)) continue;
  //       if (seen.count(k)) continue;
  //       seen.insert(k);

  //       vi d = {abs(i-j), abs(i-k), abs(j-k)}, f = {h[i], h[j], h[k]};
  //       srt(d); srt(f);
  //       bool valid = d[0] == f[0] && d[1] == f[1] && d[2] == f[2];
  //       if (!valid) continue;

  //       // cerr << i << " " << j << " " << k << "\n";
  //       ans++;
  //     }
  //   }
  // }
  // return ans;
}

vi construct_range(int M, int K) {
  return {1, 1, 1};
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...