제출 #1333182

#제출 시각아이디문제언어결과실행 시간메모리
1333182FaggiTriple Peaks (IOI25_triples)C++20
0 / 100
2094 ms21484 KiB
#include <bits/stdc++.h>
#define ll int
#define sz(x) int(x.size())
#define forn(i, n) for (i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fr first
#define se second
using namespace std;

vector<ll> h;
set<vector<ll>> ans;
void comp(ll i, ll j, ll k)
{
    vector<ll> v = {abs(i - j), abs(i - k), abs(j - k)}, v2 = {h[i], h[j], h[k]};
    sort(all(v));
    sort(all(v2));
    if (v == v2)
    {
        vector<ll> ret = {i, j, k};
        sort(all(ret));
        ans.insert(ret);
    }
}

vector<vector<ll>> ords = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
// 0: (i,j), 1: (i,k), 2:(j,k)
// 0: H[i], 1: H[j], 2: H[k]
long long count_triples(std::vector<int> H)
{
    for (auto k : H)
        h.pb(k);

    ll i, j, k, a, b, a2, b2, c, c2;
    auto calc = [&]()
    {
        b = a - h[a];
        if (b >= 0)
            comp(k, a, b);
        b2 = a + h[a];
        if (b2 < sz(h))
            comp(k, a, b2);
        c = k - h[a];
        if (c >= 0)
            comp(k, a, c);
        c = k + h[a];
        if (c < sz(h))
            comp(k, a, c);
    };
    for (k = 0; k < sz(h); k++)
    {
        a = k - h[k];
        if (a >= 0)
            calc();
        a2 = k + h[k];
        if (a2 < sz(h))
        {
            a=a2;
            calc();
        }
    }
    ll ag=0;
    for(i=0; i<sz(h); i++)
    {
        for(j=1; j<h[i]; j++)
        {
            if(i-j<0)
                break;
            if(h[i]-j+i>=sz(h))
                continue;
            if(h[i-j]==h[i]-j&&h[h[i]-j+i]==j)
                ag++;
        }
    }

    return ag+sz(ans);
}

std::vector<int> 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...