제출 #348573

#제출 시각아이디문제언어결과실행 시간메모리
348573arnold518Meandian (CEOI06_meandian)C++14
100 / 100
7 ms492 KiB
#include "libmean.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 100; int N, ans[MAXN+10]; map<vector<int>, int> M; int query(int a, int b, int c, int d) { vector<int> V={a, b, c, d}; sort(V.begin(), V.end()); if(M.find(V)!=M.end()) return M[V]; M[V]=Meandian(a, b, c, d)*2; return M[V]; } int main() { N=Init(); if(N==4) { for(int i=0; i<4; i++) ans[i]=-1; Solution(ans); return 0; } int a[5]={0, 1, 2, 3, 4}; for(int i=5; i<=N; i++) { int p=query(i, a[2], a[3], a[4]); int q=query(a[1], i, a[3], a[4]); int r=query(a[1], a[2], i, a[4]); int s=query(a[1], a[2], a[3], i); vector<pii> V; V.push_back({p, a[1]}); V.push_back({q, a[2]}); V.push_back({r, a[3]}); V.push_back({s, a[4]}); sort(V.begin(), V.end()); a[4]=V[0].second; a[3]=V[1].second; a[2]=V[2].second; a[1]=V[3].second; if(V[0].first==V[1].first && V[2].first==V[3].first) continue; if(V[0].first==V[1].first) { a[2]=i; } if(V[2].first==V[3].first) { a[3]=i; } } ans[a[1]]=-1; ans[a[2]]=-1; ans[a[3]]=-1; ans[a[4]]=-1; for(int i=1; i<=N; i++) { if(ans[i]==-1) continue; int p=query(i, a[2], a[3], a[4]); int q=query(a[1], i, a[3], a[4]); int r=query(a[1], a[2], i, a[4]); int s=query(a[1], a[2], a[3], i); vector<int> V={p, q, r, s}; sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end()); int u=V[0], v=query(a[1], a[2], a[3], a[4]), w=V[1]; ans[i]=(u+v+w)/2-v; } for(int i=1; i<=N; i++) ans[i-1]=ans[i]; Solution(ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...