답안 #307826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
307826 2020-09-29T11:14:56 Z AlexLuchianov 카멜레온의 사랑 (JOI20_chameleon) C++14
44 / 100
81 ms 504 KB
#include "chameleon.h"
#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;
    while(Query(reunion(a, {node})) < a.size() + 1){
      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);
    }
    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++)  {
    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);
        break;
      }
    }
    for(int j = 0; j < sets; j++) 
      if(find(independent_set[j].begin(), independent_set[j].end(), i) == independent_set[j].end()) {
        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;
      }

      if(query({i, g[i][0], g[i][2]}) == 1) {
        connect[i] -= g[i][1];
        connect[g[i][1]] -= i;
      }

      if(query({i, g[i][2], g[i][1]}) == 1) {
        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:16:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i = 0; i < b.size(); i++)
      |                    ~~^~~~~~~~~~
chameleon.cpp: In function 'std::vector<int> {anonymous}::pref(std::vector<int>, int)':
chameleon.cpp:24:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |     if(a.size() <= k)
      |        ~~~~~~~~~^~~~
chameleon.cpp: In function 'std::vector<std::pair<int, int> > {anonymous}::get_all_edges(std::vector<int>, int)':
chameleon.cpp:36:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     while(Query(reunion(a, {node})) < a.size() + 1){
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
chameleon.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(x + jump <= a.size() && query(reunion(pref(a, x + jump), {node})) == x + jump + 1)
      |            ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:57:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |       if(query(reunion(independent_set[j], {i})) == independent_set[j].size() + 1) {
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chameleon.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int h = 0; h < edges.size(); h++)
      |                        ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 36 ms 384 KB Output is correct
4 Correct 35 ms 384 KB Output is correct
5 Correct 35 ms 384 KB Output is correct
6 Correct 36 ms 384 KB Output is correct
7 Correct 35 ms 384 KB Output is correct
8 Correct 36 ms 384 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 416 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 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 364 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 416 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 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 364 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 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 1 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 0 ms 384 KB Output is correct
3 Incorrect 81 ms 504 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 36 ms 384 KB Output is correct
4 Correct 35 ms 384 KB Output is correct
5 Correct 35 ms 384 KB Output is correct
6 Correct 36 ms 384 KB Output is correct
7 Correct 35 ms 384 KB Output is correct
8 Correct 36 ms 384 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 416 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 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 364 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 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 1 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 0 ms 384 KB Output is correct
30 Incorrect 81 ms 504 KB Wrong Answer [3]
31 Halted 0 ms 0 KB -