제출 #1258266

#제출 시각아이디문제언어결과실행 시간메모리
1258266allin27x3개의 봉우리 (IOI25_triples)C++20
70 / 100
2096 ms23112 KiB
#include "triples.h" #include <bits/stdc++.h> using namespace std; #define int long long int ans = 0; int n; const int SQRT = 450; void count1(vector<signed> &h){ for (int idx = 0; idx<n; idx++){ int x = h[idx]; int idh = idx - x; if (idh < 0) continue; int y = h[idh] - x; if (y <= 0 || y==x) continue; int idy = idx + y; if (idy >= n) continue; if (h[idy] == y) ans++; } } void count2(vector<signed> &h){ for (int idx = 0; idx<n; idx++){ int x = h[idx]; int idy = idx + x; if (idy >= n) continue; int y = h[idy]; int idh = idx - y; if (idh < 0) continue; if (h[idh] == x + y) ans++; } } void count3(vector<signed> &h){ for (int idx = 0; idx<n; idx++){ int x = h[idx]; int idh = idx + x; if (idh >= n) continue; int y = h[idh] - x; if (y <= 0 || y==x) continue; int idy = idh + y; if (idy >= n) continue; if (h[idy] == y) ans++; } } void count4(vector<signed> &h){ vector<vector<int>> tl(3*n); for (int i=0; i<n; i++){ int j = i + h[i]; if (j >= 3*n) continue; tl[j].push_back(h[i]); } for (int idt = 0; idt<3*n; idt++){ if (tl[idt].size() > SQRT){ for (int idx = 0; idx < idt; idx++){ int x = h[idx]; int y = idt - idx; y -= x; if (y<=0 || (y&1)) continue; y/=2; int idy = idt - y; int idh = idt - x - y; if (h[idh] == x+y && h[idy] == y) ans++; } } else { for (int y: tl[idt]){ for (int hv: tl[idt]){ int x = hv - y; if (x<=0) continue; int idx = idt - hv - y; if (idx <0) continue; if (h[idx] == x) ans++; } } } } } long long count_triples(std::vector<signed> h) { n = h.size(); ans = 0; auto rh = h; reverse(rh.begin(), rh.end()); count1(h); count1(rh); count2(h); count2(rh); count3(h); count4(h); return ans; } int N = 1; int mexSum(vector<int> S){ int n = 2*S.back()+4; vector<int> pos(n, 0); for (int i=0; i<S.size(); i++){ for (int j=i+1; j<S.size(); j++){ pos[S[i] + S[j]] = 1; } } int s =0; for (int i=0; i<pos.size(); i++) s+=pos[i]; return s; } std::vector<signed> construct_range(signed n, signed K) { vector<signed> ans(3*n,0); N=n; vector<int> S = {0}; int cant = 0; while (cant < n){ int mx = cant, dg = -1; for (int i=S.back() + 1; i<=cant+2; i++){ S.push_back(i); int res = mexSum(S); if (res > mx) mx = res, dg = i; S.pop_back(); } S.push_back(dg); cant = mx; } for (int x: S) cout<<x<<' '; cout<<'\n'; for (int nw: S){ for (int ot: S){ if (ot>=nw) continue; if (ans[ot + nw]) continue; ans[ot + nw] = nw - ot; } } while ((int)ans.size()>n) ans.pop_back(); for (int i=0; i<n; i++) if (!ans[i]) ans[i] = 1; return ans; }
#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...