/*
CEOI 2006
Competition Day #2
Task MEANDIAN
Sample library for C/C++
*/
/*
input file format:
N
a1 a2 ... aN
*/
#include <bits/stdc++.h>
#include "libmean.h"
using namespace std;
const int INF = 1e9;
const int MAXN = 100;
int sol[MAXN];
inline int get(vector <int> a) {
bool ok = 1;
int i;
for(i = 1; ok; i++) {
ok = 0;
for(auto it : a) {
if(it == i) {
ok = 1;
}
}
}
return i - 1;
}
int main() {
int n, i, j;
n = Init();
vector <int> a = {1, 2, 3, 4};
vector <int> b = a;
int mn = Meandian(a[0], a[1], a[2], a[3]);
int mx = mn;
for(i = 5; i <= n; i++) {
vector <int> aux = a;
for(j = 0; j < 4; j++) {
vector <int> cur;
for(int k = 0; k < 4; k++) {
cur.push_back((k != j ? a[k] : i));
}
int val = Meandian(cur[0], cur[1], cur[2], cur[3]);
if(val < mn) {
mn = val, aux = cur;
}
}
a = aux;
aux = b;
for(j = 0; j < 4; j++) {
vector <int> cur;
for(int k = 0; k < 4; k++) {
cur.push_back((k != j ? b[k] : i));
}
int val = Meandian(cur[0], cur[1], cur[2], cur[3]);
if(val > mx) {
mx = val, aux = cur;
}
}
b = aux;
}
memset(sol, -1, sizeof(sol));
if(n <= 6) { Solution(sol); return 0; }
vector <bool> vis(n + 1, 1);
for(auto it : a) {
vis[it] = 0;
}
for(auto it : b) {
vis[it] = 0;
}
int id_mn4, ga = get(a);
mn = INF;
for(i = 0; i < 4; i++) {
vector <int> cur;
for(j = 0; j < 4; j++) {
cur.push_back((i != j ? a[j] : ga));
}
int val = Meandian(cur[0], cur[1], cur[2], cur[3]);
if(val < mn) {
mn = val, id_mn4 = a[i];
}
}
vis[id_mn4] = 1;
vector <int> aux;
for(auto it : a) {
if(it != id_mn4) {
aux.push_back(it);
}
}
a = aux;
int id_mx4, gb = get(b);
mx = 0;
for(i = 0; i < 4; i++) {
vector <int> cur;
for(j = 0; j < 4; j++) {
cur.push_back((i != j ? b[j] : gb));
}
int val = Meandian(cur[0], cur[1], cur[2], cur[3]);
if(val > mx) {
mx = val, id_mx4 = b[i];
}
}
vis[id_mx4] = 1;
aux.clear();
for(auto it : b) {
if(it != id_mx4) {
aux.push_back(it);
}
}
b = aux;
int id_mn3; mn = INF;
for(i = 0; i < 3; i++) {
for(j = i + 1; j < 3; j++) {
int val = Meandian(a[i], a[j], ga, id_mn4);
if(val < mn) {
mn = val, id_mn3 = a[3 - i - j];
}
}
}
vis[id_mn3] = 1;
int id_mx3; mx = 0;
for(i = 0; i < 3; i++) {
for(j = i + 1; j < 3; j++) {
int val = Meandian(b[i], b[j], gb, id_mx4);
if(val > mx) {
mx = val, id_mx3 = b[3 - i - j];
}
}
}
vis[id_mx3] = 1;
int ida = (id_mn3 == a[0] ? a[1] : a[0]);
int idb = (id_mx3 == b[0] ? b[1] : b[0]);
vector <int> ids;
for(i = 1; i <= n; i++) {
if(vis[i]) ids.push_back(i);
}
int x = 2 * Meandian(ida, idb, ids[0], ids[1]);
int y = 2 * Meandian(ida, idb, ids[0], ids[2]);
int z = 2 * Meandian(ida, idb, ids[1], ids[2]);
sol[ids[0] - 1] = (x + y - z) / 2;
sol[ids[1] - 1] = (x + z - y) / 2;
sol[ids[2] - 1] = (y + z - x) / 2;
for(i = 3; i < ids.size(); i++) {
sol[ids[i] - 1] = 2 * Meandian(ida, idb, ids[i - 1], ids[i]) - sol[ids[i - 1] - 1];
}
Solution(sol);
return 0;
}
Compilation message
meandian.cpp: In function 'int main()':
meandian.cpp:163:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i = 3; i < ids.size(); i++) {
~~^~~~~~~~~~~~
meandian.cpp:147:15: warning: 'id_mx3' may be used uninitialized in this function [-Wmaybe-uninitialized]
vis[id_mx3] = 1;
^
meandian.cpp:149:31: warning: 'id_mn3' may be used uninitialized in this function [-Wmaybe-uninitialized]
int ida = (id_mn3 == a[0] ? a[1] : a[0]);
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
meandian.cpp:121:9: warning: 'id_mx4' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(it != id_mx4) {
^~
meandian.cpp:100:9: warning: 'id_mn4' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(it != id_mn4) {
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
296 KB |
number 2 is wrong (-1, should be 790) |
2 |
Incorrect |
4 ms |
376 KB |
number 2 is wrong (1482, should be -1) |
3 |
Correct |
4 ms |
248 KB |
Output is correct |
4 |
Correct |
7 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
248 KB |
Output is correct |
7 |
Correct |
10 ms |
376 KB |
Output is correct |
8 |
Correct |
12 ms |
376 KB |
Output is correct |
9 |
Correct |
13 ms |
248 KB |
Output is correct |
10 |
Correct |
12 ms |
248 KB |
Output is correct |