답안 #1057236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057236 2024-08-13T15:42:07 Z huutuan 카멜레온의 사랑 (JOI20_chameleon) C++14
100 / 100
27 ms 548 KB
#include "chameleon.h"

#include <bits/stdc++.h>

using namespace std;

namespace solver{
   int fake_query(vector<int> v){
      for (int &i:v) ++i;
      return Query(v);
   }
   void fake_answer(int a, int b){
      if (a<b) Answer(a+1, b+1);
   }
   void solve(int n){
      vector<vector<int>> g(n*2);
      vector<int> v(n*2);
      iota(v.begin(), v.end(), 0);
      for (int _=0; _<3; ++_){
         vector<int> v1, v2;
         for (auto &i:v){
            v1.push_back(i);
            if (fake_query(v1)!=(int)v1.size()){
               v1.pop_back();
               v2.push_back(i);
            }
         }
         auto query=[&](int i, int l, int r){
            vector<int> tmp(v1.begin()+l, v1.begin()+r+1);
            tmp.push_back(i);
            return fake_query(tmp)!=(int)tmp.size();
         };
         v.clear();
         for (int i:v2){
            int st=0;
            while ((int)g[i].size()<3){
               if (st && !query(i, st, (int)v1.size()-1)) break;
               int l=st, r=(int)v1.size()-2;
               while (l<=r){
                  int mid=(l+r)>>1;
                  if (query(i, st, mid)) r=mid-1;
                  else l=mid+1;
               }
               g[i].push_back(v1[l]);
               g[v1[l]].push_back(i);
               st=l+1;
            }
            if ((int)g[i].size()<3) v.push_back(i);
         }
      }
      for (int i=0; i<n*2; ++i){
         if ((int)g[i].size()==1) fake_answer(i, g[i][0]);
      }
      vector<int> L(n*2, -1);
      for (int i=0; i<n*2; ++i){
         if ((int)g[i].size()==3){
            if (fake_query({i, g[i][0], g[i][1]})==1) L[i]=g[i][2];
            else if (fake_query({i, g[i][1], g[i][2]})==1) L[i]=g[i][0];
            else L[i]=g[i][1];
         }
      }
      for (int i=0; i<n*2; ++i) if ((int)g[i].size()==3){
         if (L[i]==g[i][0] || L[g[i][0]]==i){
            if (L[i]==g[i][1] || L[g[i][1]]==i) fake_answer(i, g[i][2]);
            else fake_answer(i, g[i][1]);
         }else fake_answer(i, g[i][0]);
      }
   }
}

void Solve(int N) {
   solver::solve(N);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 12 ms 344 KB Output is correct
5 Correct 12 ms 344 KB Output is correct
6 Correct 11 ms 548 KB Output is correct
7 Correct 10 ms 536 KB Output is correct
8 Correct 11 ms 344 KB Output is correct
9 Correct 14 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 18 ms 548 KB Output is correct
4 Correct 19 ms 344 KB Output is correct
5 Correct 20 ms 344 KB Output is correct
6 Correct 18 ms 548 KB Output is correct
7 Correct 27 ms 344 KB Output is correct
8 Correct 19 ms 340 KB Output is correct
9 Correct 19 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 10 ms 344 KB Output is correct
4 Correct 12 ms 344 KB Output is correct
5 Correct 12 ms 344 KB Output is correct
6 Correct 11 ms 548 KB Output is correct
7 Correct 10 ms 536 KB Output is correct
8 Correct 11 ms 344 KB Output is correct
9 Correct 14 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 18 ms 548 KB Output is correct
31 Correct 19 ms 344 KB Output is correct
32 Correct 20 ms 344 KB Output is correct
33 Correct 18 ms 548 KB Output is correct
34 Correct 27 ms 344 KB Output is correct
35 Correct 19 ms 340 KB Output is correct
36 Correct 19 ms 344 KB Output is correct
37 Correct 19 ms 344 KB Output is correct
38 Correct 10 ms 548 KB Output is correct
39 Correct 21 ms 340 KB Output is correct
40 Correct 21 ms 344 KB Output is correct
41 Correct 19 ms 540 KB Output is correct
42 Correct 11 ms 340 KB Output is correct
43 Correct 18 ms 344 KB Output is correct
44 Correct 19 ms 344 KB Output is correct
45 Correct 19 ms 344 KB Output is correct