제출 #1249829

#제출 시각아이디문제언어결과실행 시간메모리
1249829kduckp3개의 봉우리 (IOI25_triples)C++20
14.17 / 100
2095 ms1972 KiB
#include "triples.h"
#include <vector>
#include <algorithm>
using namespace std;

tuple<int, int, int> sort3(int a, int b, int c) {
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    return {a, b, c};
}

long long count_triples(vector<int> H) {
    int n = H.size();
    long long res = 0;

    if (n <= 2000) {
        for (int i = 0; i < n; i++)
            for (int j = i + 1; j < n; j++)
                for (int k = j + 1; k < n; k++) {
                    auto [h1, h2, h3] = sort3(H[i], H[j], H[k]);
                    int d1 = j - i, d2 = k - i, d3 = k - j;
                    auto [x1, x2, x3] = sort3(d1, d2, d3);
                    if (h1 == x1 && h2 == x2 && h3 == x3)
                        res++;
                }
        return res;
    }

    bool small_value = true;
    for (int h : H)
        if (h > 10) {
            small_value = false;
            break;
        }

    if (small_value) {
        for (int i = 0; i < n; ++i)
            for (int j = i + 1; j < min(n, i + 11); ++j)
                for (int k = j + 1; k < min(n, i + 22); ++k) {
                    auto [h1, h2, h3] = sort3(H[i], H[j], H[k]);
                    int d1 = j - i, d2 = k - i, d3 = k - j;
                    auto [x1, x2, x3] = sort3(d1, d2, d3);
                    if (h1 == x1 && h2 == x2 && h3 == x3)
                        res++;
                }
        return res;
    }

    return 0;
}

vector<int> construct_range(int M, int K) {
    return {1, 1, 2};
}
#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...