제출 #1249961

#제출 시각아이디문제언어결과실행 시간메모리
1249961Jakub_Wozniak3개의 봉우리 (IOI25_triples)C++20
39.89 / 100
2095 ms2736 KiB
#include "triples.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<vector <int> ,ll> pvl; #define st first #define nd second vector <int> rek(int N) { if(N == 0)return {}; if(N == 1)return {1}; if(N == 2)return {1,1}; if(N%3 != 2) { vector <int> temp = rek(N-1); temp.push_back(1); return temp; } vector <int > r; int s1 = N/3 ; int s2 = s1+N/3+1; vector <int> temp = rek((N/3)); for(auto p : temp)r.push_back(p); r.push_back(N/3+1); for(auto p : temp)r.push_back(N/3+1-p); r.push_back(N/3+1); for(auto p : temp)r.push_back(p); return r; } vector<int> construct_range(int M, int K) { int pot = 1; while(pot < M)pot *= 3; pot /= 3; vector <int> res = rek(pot); if(2*res.size() <= M) { vector <int> temp = res; for(auto p : temp)res.push_back(p); } return res; } long long count_triplesnd(vector<int> H) { int N = H.size(); ll ile = 0; for(int i = N-1 ; i >= 0 ; i--) { int k = i-H[i]; if(k < 0)continue; int j = k+H[k]; if(j < 0 || j >= N); else if(H[k]+H[j] == H[i] && (i-j) == H[j] && k < j && j < i)ile++; j = i-H[k]; if(k+H[k] == j)continue; if(j < 0 || j >= N); else if(H[k]+H[j] == H[i] && (j-k) == H[j] && k < j && j < i)ile++; } return ile; } long long count_triples(vector<int> H) { int N = H.size(); int B = 0; bool czynd = 1; for(int i = 0; i < N ; i++)B = max(B , H[i]); for(int i = 1; i < N ; i++) { if(H[i-1] > H[i])czynd = 0; } if(czynd)return count_triplesnd(H); ll ile = 0; for(int i = 0 ; i < N ; i++) { for(int j = i+1 ; j < min(N,i+B+1) ; j++) { int d = j-i; if(H[i] == d || H[j] == d) { int R = 0; if(H[i] == d)R = H[j]; else R = H[i]; int k = j+R; if(k >= 0 && k < N && k > j && H[k] == R+d)ile++; k = i+R; if(k >= 0 && k < N && k > j && R == H[k]+d)ile++; } else { int k = j+min(H[i] , H[j]); if(k >= 0 && k < N && H[k] == d && min(H[i],H[j])+d == max(H[i],H[j]))ile++; } } } return ile; }
#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...