제출 #1290840

#제출 시각아이디문제언어결과실행 시간메모리
1290840ecen303개의 봉우리 (IOI25_triples)C++20
0.90 / 100
13 ms2364 KiB
//testing AI Code #include "triples.h" #include <bits/stdc++.h> using namespace std; // PART I — Count mythical triples (O(N)) long long count_triples(vector<int> H) { int N = H.size(); long long ans = 0; for (int i = 0; i < N; i++) { int d = H[i]; // k - i must equal H[i] int k = i + d; if (k >= N) continue; int hk = H[k]; // Case 1: x = hk int x1 = hk; if (x1 > 0 && x1 < d) { int j = i + x1; if (j > i && j < k) { if (H[j] == d - x1) ans++; } } // Case 2: x = d - hk int x2 = d - hk; if (x2 > 0 && x2 < d) { int j = i + x2; if (j > i && j < k) { if (H[j] == hk) ans++; } } } return ans; } // ============================================================ // PART II — Construct range with ≥ K mythical triples // ============================================================ // // Strategy: // Use largest-N arithmetic slope shape. // H[i] = min(i, N-1) // This generates ~C(N,3) mythical triples. // // Choose N = smallest s.t. C(N,3) ≥ K. // ============================================================ vector<int> construct_range(int M, int K) { // Find smallest N such that C(N,3) >= K long long target = K; int N = 3; while (N < M) { long long triples = 1LL * N * (N - 1) * (N - 2) / 6; if (triples >= target) break; N++; } if (N > M) N = M; // if K is huge, just use max size vector<int> H(N); for (int i = 0; i < N; i++) { H[i] = min(i, N - 1); // valid: between 1 and N-1 if (H[i] == 0) H[i] = 1; } return H; }
#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...