#include <bits/stdc++.h>
#include "libmean.h"
using namespace std;
int A[111];
int n;
int getidx(int i1, int i2, int i3, int i4, int i5, bool f)
{
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? max({v1, v2, v3, v4, v5}) : min({v1, v2, v3, v4, v5}));
if(v == v1) return i1;
if(v == v2) return i2;
if(v == v3) return i3;
if(v == v4) return i4;
if(v == v5) return i5;
}
int find(bool f)
{
vector <int> V;
int m, i;
m = 1;
for(i=5; i<=n; i+=4){
m = getidx(m, i - 3, i - 2, i - 1, i, f);
}
V.clear();
for(i=n; V.size() < 4; i--){
if(i != m) V.push_back(i);
}
m = getidx(m, V[0], V[1], V[2], V[3], f);
return m;
}
void findval(vector <int> &V, int m1, int m2)
{
int i, v;
int v1 = Meandian(m1, m2, V[1], V[2]);
int v2 = Meandian(m1, m2, V[0], V[2]);
int v3 = Meandian(m1, m2, V[0], V[1]);
int s = v1 + v2 + v3;
A[V[0] - 1] = s - v1 * 2;
A[V[1] - 1] = s - v2 * 2;
A[V[2] - 1] = s - v3 * 2;
for(i=3; i<V.size(); i++){
A[V[i] - 1] = Meandian(m1, m2, V[0], V[i]) * 2 - A[V[0] - 1];
}
}
int main()
{
vector <int> V;
int i, m1, m2;
n = Init();
for(i=1; i<=n; i++){
A[i - 1] = -1;
}
if(n <= 4){
Solution(A);
return 0;
}
m1 = find(0); m2 = find(1);
for(i=1; i<=n; i++){
if(i != m1 && i != m2){
V.push_back(i);
}
}
findval(V, m1, m2);
int m = 1e9, x;
for(i=0; i<n; i++){
if(A[i] == -1) continue;
if(A[i] < m) m = A[i], x = i;
}
A[x] = -1;
m = -1e9;
for(i=0; i<n; i++){
if(A[i] == -1) continue;
if(A[i] > m) m = A[i], x = i;
}
A[x] = -1;
Solution(A);
return 0;
}
Compilation message
meandian.cpp: In function 'void findval(std::vector<int>&, int, int)':
meandian.cpp:59:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=3; i<V.size(); i++){
~^~~~~~~~~
meandian.cpp:49:9: warning: unused variable 'v' [-Wunused-variable]
int i, v;
^
meandian.cpp: In function 'int getidx(int, int, int, int, int, bool)':
meandian.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
meandian.cpp: In function 'int main()':
meandian.cpp:97:7: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
A[x] = -1;
~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Incorrect |
3 ms |
252 KB |
number 1 is wrong (-1, should be 340) |
4 |
Incorrect |
3 ms |
248 KB |
number 2 is wrong (-1, should be 1688) |
5 |
Correct |
2 ms |
248 KB |
Output is correct |
6 |
Incorrect |
3 ms |
376 KB |
number 4 is wrong (-1, should be 322) |
7 |
Correct |
4 ms |
248 KB |
Output is correct |
8 |
Incorrect |
6 ms |
376 KB |
number 1 is wrong (-1, should be 1832) |
9 |
Incorrect |
6 ms |
376 KB |
number 8 is wrong (-1, should be 130) |
10 |
Incorrect |
7 ms |
200 KB |
number 1 is wrong (-1, should be 1990) |