#include <bits/stdc++.h>
#include "libmean.h"
using namespace std;
typedef pair <int, int> pii;
int A[111];
int n;
pii getidx(int i1, int i2, int i3, int i4, int i5, bool f)
{
pii ret(-1, -1);
int v1 = Meandian(i2, i3, i4, i5);
int v2 = Meandian(i1, i3, i4, i5);
int v3 = Meandian(i1, i2, i4, i5);
int v4 = Meandian(i1, i2, i3, i5);
int v5 = Meandian(i1, i2, i3, i4);
int v = (f? min({v1, v2, v3, v4, v5}) : max({v1, v2, v3, v4, v5}));
if(v == v1) (ret.first == -1? ret.first : ret.second) = i1;
if(v == v2) (ret.first == -1? ret.first : ret.second) = i2;
if(v == v3) (ret.first == -1? ret.first : ret.second) = i3;
if(v == v4) (ret.first == -1? ret.first : ret.second) = i4;
if(v == v5) (ret.first == -1? ret.first : ret.second) = i5;
return ret;
}
pii find(bool f)
{
vector <int> V;
int m1, m2, i;
m1 = 1; m2 = 2;
for(i=5; i<=n; i+=3){
tie(m1, m2) = getidx(m1, m2, i - 2, i - 1, i, f);
}
V.clear();
for(i=n; V.size() < 3; i--){
if(i != m1 && i != m2) V.push_back(i);
}
tie(m1, m2) = getidx(m1, m2, V[0], V[1], V[2], f);
return pii(m1, m2);
}
void findval(vector <int> &V, int m1, int m2, int m3, int m4)
{
int i;
int v1 = Meandian(m1, m2, m3, V[0]);
int v2 = Meandian(m1, m3, m4, V[0]);
int v3 = Meandian(m1, m2, m3, m4);
A[V[0] - 1] = v1 + v2 - v3;
for(i=1; i<V.size(); i++){
A[V[i] - 1] = Meandian(m1, m4, V[0], V[i]) * 2 - A[V[0] - 1];
}
}
int main()
{
vector <int> V;
int i, m1, m2, m3, m4;
n = Init();
for(i=1; i<=n; i++){
A[i - 1] = -1;
}
if(n <= 4){
Solution(A);
return 0;
}
tie(m1, m2) = find(0); tie(m3, m4) = find(1);
for(i=1; i<=n; i++){
if(i != m1 && i != m2 && i != m3 && i != m4){
V.push_back(i);
}
}
findval(V, m1, m2, m3, m4);
Solution(A);
return 0;
}
Compilation message
meandian.cpp: In function 'void findval(std::vector<int>&, int, int, int, int)':
meandian.cpp:60:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<V.size(); i++){
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
248 KB |
Output is correct |
5 |
Correct |
3 ms |
296 KB |
Output is correct |
6 |
Correct |
4 ms |
248 KB |
Output is correct |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Correct |
5 ms |
248 KB |
Output is correct |
9 |
Correct |
5 ms |
248 KB |
Output is correct |
10 |
Correct |
8 ms |
376 KB |
Output is correct |