답안 #307830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307830 2020-09-29T11:20:38 Z AlexLuchianov 카멜레온의 사랑 (JOI20_chameleon) C++14
44 / 100
85 ms 448 KB
#include "chameleon.h"
#include <vector>
#include <algorithm>
#include <cassert>
#include <iostream>

namespace {
  int const sets = 4;
  std::vector<std::vector<int>> g;
  void add_edge(int x, int y) {
    g[x].push_back(y);
    g[y].push_back(x);
  }
  std::vector<int> reunion(std::vector<int> a, std::vector<int> b) {
    for(int i = 0; i < b.size(); i++)
      a.push_back(b[i]);
    return a;
  }
  int query(std::vector<int> a) {
    return Query(a);
  }
  std::vector<int> pref(std::vector<int> a, int k) {
    if(a.size() <= k)
      return a;
    else {
      std::vector<int> result;
      for(int i = 0; i < k; i++)
        result.push_back(a[i]);
      return result;
    }
  }

  std::vector<std::pair<int,int>> get_all_edges(std::vector<int> a, int node) {
    std::vector<std::pair<int,int>> edges;
    do {
      int x = 0;
      for(int jump = (1 << 10); 0 < jump; jump /= 2) {
        if(x + jump < a.size() && query(reunion(pref(a, x + jump), {node})) == x + jump + 1)
          x += jump;
      }
      edges.push_back({a[x], node});
      a.erase(a.begin() + x);
    } while(query(reunion(a, {node})) < a.size() + 1);

    return edges;
  }
}



void Solve(int n) {
  std::vector<std::vector<int>> independent_set(sets);
  g.resize(1 + 2 * n);
  
  for(int i = 1; i <= 2 * n; i++)  {
    int ptr = 0;
    for(int j = 0; j < sets; j++) {
      if(query(reunion(independent_set[j], {i})) == independent_set[j].size() + 1) {
        independent_set[j].push_back(i);
        ptr = j;
        break;
      }
    }
    for(int j = 0; j < sets; j++) 
      if(find(independent_set[j].begin(), independent_set[j].end(), i) == independent_set[j].end()) {
        if(j < ptr) {
          std::vector<std::pair<int,int>> edges = get_all_edges(independent_set[j], i);
          for(int h = 0; h < edges.size(); h++) 
            add_edge(edges[h].first, edges[h].second);
        } else if(query(reunion(independent_set[j], {i})) < independent_set[j].size() + 1) {
          std::vector<std::pair<int,int>> edges = get_all_edges(independent_set[j], i);
          for(int h = 0; h < edges.size(); h++) 
            add_edge(edges[h].first, edges[h].second);
        }
      }
  }
  
  std::vector<int> connect(2 * n + 1);
  
  for(int i = 1; i <= 2 * n; i++) {
    assert(g[i].size() == 1 || g[i].size() == 3);
    if(g[i].size() == 3) {
      connect[i] += g[i][0] + g[i][1] + g[i][2];
      if(query({i, g[i][0], g[i][1]}) == 1) {
        connect[i] -= g[i][2];
        connect[g[i][2]] -= i;
      } else if (query({i, g[i][0], g[i][2]}) == 1) {
        connect[i] -= g[i][1];
        connect[g[i][1]] -= i;
      } else {
        connect[i] -= g[i][0];
        connect[g[i][0]] -= i;
      }
    } else
      connect[i] += g[i][0];
  }

  for (int i = 1; i <= 2 * n; i++)
    if(i < connect[i])
      Answer(i, connect[i]);
}

Compilation message

chameleon.cpp: In function 'std::vector<int> {anonymous}::reunion(std::vector<int>, std::vector<int>)':
chameleon.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < b.size(); i++)
      |                    ~~^~~~~~~~~~
chameleon.cpp: In function 'std::vector<int> {anonymous}::pref(std::vector<int>, int)':
chameleon.cpp:23:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     if(a.size() <= k)
      |        ~~~~~~~~~^~~~
chameleon.cpp: In function 'std::vector<std::pair<int, int> > {anonymous}::get_all_edges(std::vector<int>, int)':
chameleon.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if(x + jump < a.size() && query(reunion(pref(a, x + jump), {node})) == x + jump + 1)
      |            ~~~~~~~~~^~~~~~~~~~
chameleon.cpp:43:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     } while(query(reunion(a, {node})) < a.size() + 1);
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:58:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |       if(query(reunion(independent_set[j], {i})) == independent_set[j].size() + 1) {
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:68:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |           for(int h = 0; h < edges.size(); h++)
      |                          ~~^~~~~~~~~~~~~~
chameleon.cpp:70:59: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         } else if(query(reunion(independent_set[j], {i})) < independent_set[j].size() + 1) {
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:72:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |           for(int h = 0; h < edges.size(); h++)
      |                          ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 36 ms 440 KB Output is correct
4 Correct 39 ms 384 KB Output is correct
5 Correct 37 ms 384 KB Output is correct
6 Correct 36 ms 384 KB Output is correct
7 Correct 37 ms 384 KB Output is correct
8 Correct 37 ms 448 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 85 ms 384 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 36 ms 440 KB Output is correct
4 Correct 39 ms 384 KB Output is correct
5 Correct 37 ms 384 KB Output is correct
6 Correct 36 ms 384 KB Output is correct
7 Correct 37 ms 384 KB Output is correct
8 Correct 37 ms 448 KB Output is correct
9 Correct 36 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 0 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Incorrect 85 ms 384 KB Wrong Answer [3]
31 Halted 0 ms 0 KB -