답안 #658610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
658610 2022-11-13T18:45:42 Z Dec0Dedd Meandian (CEOI06_meandian) C++14
30 / 100
7 ms 208 KB
#include <bits/stdc++.h>
#include "libmean.h"

using namespace std;

#define pii pair<int, int>

int n;

int ask(int *a) {
   return Meandian(a[0], a[1], a[2], a[3]);
}

bool bad(int c, int *a) {
   int i=-1, j=-1, x=-1, y=-1;
   for (int p=0; p<3; ++p) {
      if (a[p] == c) continue;
      if (i == -1) i=a[p];
      else j=a[p];
   }

   for (int p=1; p<=n; ++p) {
      if (p == i || p == c || p == j) continue;
      if (x == -1) x=p;
      else y=p;
   }
   
   int b[4]={i, j, x, y};
   int tmp=ask(b), iv, jv;
   b[0]=c; jv=ask(b);
   b[1]=i; iv=ask(b);

   if (tmp == iv || tmp == jv) return false;
   return true;
}

pair<int, int> findEx(bool mv) {
   int a[4] = {1, 2, 3, 4}, mn=ask(a);
   for (int i=5; i<=n; ++i) {
      int rm=-1;

      for (int j=0; j<4; ++j) {
         int tmp=a[j]; a[j]=i;
         int x=ask(a);
         a[j]=tmp;

         if (mv && x < mn) rm=j, mn=x;
         else if (!mv && x > mn) rm=j, mn=x;
      }

      if (rm != -1) a[rm]=i;
   } mn=ask(a);

   int x=-1;
   for (int i=1; i<=n; ++i) {
      bool ok=true;
      for (int j=0; j<4; ++j) {
         if (i == a[j]) {
            ok=false;
            break;
         }
      }

      if (!ok) continue;
      x=i;
   }

   // remove most external element
   for (int i=0; i<4; ++i) {
      int tmp[4]={};
      for (int j=0; j<4; ++j) {
         if (i == j) continue;
         tmp[j]=a[j];
      } tmp[i]=x;

      if (mn == ask(tmp)) {
         a[i]=-1;
         break;
      }
   }

   vector<int> v;
   for (int i=0; i<4; ++i) {
      if (a[i] == -1) continue;
      v.push_back(a[i]);
   } assert((int)v.size() == 3);

   int b[3];
   for (int i=0; i<3; ++i) b[i]=v[i];
   for (int i=0; i<3; ++i) {
      if (bad(b[i], b)) {
         if (i == 0) return {b[1], b[2]};
         else if (i == 1) return {b[0], b[2]};
         return {b[0], b[2]};
      }
   } assert(false);

   return {-1, -1};
}

int main() {
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   cout.tie(NULL);

   n=Init();
   pii mn=findEx(true);
   pii mx=findEx(false);

   int ans[n]={}, idx=-1, val=-1;

   for (int i=1; i<=n; ++i) {
      if (i == mn.first || i == mn.second) continue;
      if (i == mx.first || i == mx.second) continue;
      idx=i;
      break;
   }

   int a[4]={mn.first, mn.second, idx, mx.first};
   int lf=ask(a)*2, rf, wth;
   a[0]=mx.second; rf=ask(a)*2;
   a[2]=mn.first; wth=ask(a)*2;
   val=(lf+rf-wth)/2; assert((lf+rf-wth)%2 == 0);
   ans[idx-1]=val;

   assert(idx != -1);
   for (int i=1; i<=n; ++i) {
      if (i == mn.first || i == mn.second || i == mx.first || i == mx.second) {
         ans[i-1]=-1;
         continue;
      }

      if (i == idx) continue;
      int a[4]={mn.first, idx, i, mx.first};
      int p=ask(a)*2; ans[i-1]=p-val;
   }
   Solution(ans);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB number 3 is wrong (-1, should be 1678)
2 Incorrect 1 ms 208 KB number 2 is wrong (1482, should be -1)
3 Incorrect 2 ms 208 KB number 2 is wrong (1846, should be -1)
4 Incorrect 2 ms 208 KB number 3 is wrong (-1, should be 112)
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Incorrect 5 ms 208 KB number 39 is wrong (38, should be -1)
8 Incorrect 5 ms 208 KB number 48 is wrong (-1, should be 1870)
9 Incorrect 6 ms 208 KB number 23 is wrong (80, should be -1)
10 Correct 7 ms 208 KB Output is correct