제출 #1261590

#제출 시각아이디문제언어결과실행 시간메모리
1261590am_aadvik3개의 봉우리 (IOI25_triples)C++20
54.05 / 100
2093 ms243928 KiB
#include <iostream> #include <vector> #include <algorithm> #include <unordered_set> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; int64_t pack(int i, int j, int k) { return ((int64_t)i << 40) | ((int64_t)j << 20) | ((int64_t)k); } void sort3(int &a0, int &a1, int &a2) { if (a0 > a1) swap(a0, a1); if (a1 > a2) swap(a1, a2); if (a0 > a1) swap(a0, a1); } void sort4(int& a0, int& a1, int& a2, int &a3) { if (a0 > a1) swap(a0, a1); if (a2 > a3) swap(a2, a3); if (a0 > a2) swap(a0, a2); if (a1 > a3) swap(a1, a3); if (a1 > a2) swap(a1, a2); } void check(int i, int j, int k, vector<int>&a \ , unordered_set<int64_t> &s) { vector<int> x = { j - i, k - i, k - j }; vector<int> y = { a[i], a[j], a[k] }; sort3(x[0], x[1], x[2]); sort3(y[0], y[1], y[2]); #pragma GCC unroll 3 for (int i = 0; i < 3; ++i) if (x[i] != y[i]) return; s.insert(pack(i, j, k)); } void findi(int j, int k, vector<int>&a \ , unordered_set<int64_t> &ms) { if ((k < 0) || ((k >= a.size()))) return; if ((j < 0) || ((j >= a.size()))) return; vector<int> op = { j - a[j], k - a[k], j - a[k], k - a[j] }; sort4(op[0], op[1], op[2], op[3]); op.erase(unique(op.begin(), op.end()), op.end()); for (auto i : op) if ((i >= 0) && (i < a.size())) if ((k + a[k]) == (j + a[j])) check(i, j, k, a, ms); } void findk(int i, int j, vector<int>& a \ , unordered_set<int64_t> &ms) { if ((j < 0) || ((j >= a.size()))) return; if ((i < 0) || ((i >= a.size()))) return; vector<int> op = { i + a[i], j + a[i], i + a[j], j + a[j] }; sort4(op[0], op[1], op[2], op[3]); op.erase(unique(op.begin(), op.end()), op.end()); for (auto k : op) if ((k >= 0) && (k < a.size())) if ((k + a[k]) == (j + a[j])) check(i, j, k, a, ms); } long long count_triples(vector<int> a) { unordered_set<int64_t> ans; int n = a.size(); ans.reserve(max(1, n * 2)); for (int x = 0; x < n; ++x) for (auto y : { x - a[x], x + a[x]}) if (!((y < 0) || ((y >= a.size())))) { vector<int> op = { x - a[x], x + a[x], y + a[y], y - a[y], y + a[x], y - a[x], x + a[y], x - a[y] }; sort(op.begin(), op.end()); op.erase(unique(op.begin(), op.end()), op.end()); for (auto z : op) { if ((z < 0) || ((z >= a.size()))) continue; vector<int> op = { x, y, z }; sort3(op[0], op[1], op[2]); check(op[0], op[1], op[2], a, ans); } } vector<vector<int>> x(n + n), y(n + n); for (int i = 0; i < n; ++i) x[a[i] - i + n].push_back(i); for (int i = 0; i < n; ++i) y[a[i] + i].push_back(i); for (int j = 0; j < n; ++j) { if (x[a[j] - j + n].size() < y[a[j] + j].size()) for (auto i : x[a[j] - j + n]) findk(i, j, a, ans); else for (auto k : y[a[j] + j]) findi(j, k, a, ans); } return (int)ans.size(); } vector<int> construct_range(int M, int K) { vector<int> a = { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }; return a; } //int main() { vector<int> a = { 4, 1, 4, 3, 2, 6, 1 }; cout << count_triples(a); }
#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...