Submission #1050070

# Submission time Handle Problem Language Result Execution time Memory
1050070 2024-08-09T07:11:05 Z 우민규(#11047) Chameleon's Love (JOI20_chameleon) C++17
40 / 100
12 ms 476 KB
#include "chameleon.h"
#include <bits/stdc++.h>
using namespace std;

namespace {

int ask(vector<int> b) {
  for (auto& e : b) e += 1;
  int res = Query(b);
  return res;
}
int ask_ref(vector<int>& b) {
  for (auto& e : b) e += 1;
  int res = Query(b);
  for (auto& e : b) e -= 1;
  return res;
}

int same_col(int a, vector<int> b) {
  if (b.size() == 1) return b.front();
  vector<int> bl, br;
  for (int i = 0; i < b.size(); ++i) {
    (i % 2 ? bl : br).push_back(b[i]);
  }
  int bl_c = ask_ref(bl);
  bl.push_back(a);
  int bla_c = ask_ref(bl);
  bl.pop_back();
  if (bla_c == bl_c) return same_col(a, bl);
  return same_col(a, br);
}

}  // namespace

void Solve(int n) {
    vector<int> b(2 * n, 0);
    iota(b.begin(), b.end(), 0);
    vector<vector<int>> adj(2 * n);
    for (int i = 0; i < 2 * n; ++i) {
        for (int j = 0; j < 2 * n; ++j) {
            if (j == i) continue;
            if (ask({i, j}) == 1) {
                adj[i].push_back(j);
            }
        }
        // at most 3 elements in adj[i]:
        // one with the same color
        // one s.t. it loves this
        // one s.t. this loves it

        // OR a single element with the same color as this. 
        assert(adj[i].size() == 1 || adj[i].size() == 3);

        if (adj[i].size() == 3) {
            int a = adj[i][0];
            int b = adj[i][1];
            int c = adj[i][2];
            // Query{this, loving this, same color} = 1, otherwise it's two
            // So, we can erase this thing's lover
            if (ask({i, a, b}) == 1) {
                adj[i].erase(adj[i].begin() + 2);
            } else if (ask({i, b, c}) == 1) {
                adj[i].erase(adj[i].begin());
            } else {
                adj[i].erase(adj[i].begin() + 1);
            }
        }
    }
    
    // Any double edges mean that they are the same color
    set<pair<int, int>> saw;
    for (int i = 0; i < 2 * n; ++i) {
        for (auto j : adj[i]) {
            if (saw.count({i, j}) || saw.count({j, i})) {
                Answer(i + 1, j + 1);
            } else {
                saw.insert({i, j});
            }
        }
    }
}

#ifndef EVAL
#include "grader.cpp"
#endif

Compilation message

chameleon.cpp: In function 'int {anonymous}::same_col(int, std::vector<int>)':
chameleon.cpp:22:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for (int i = 0; i < b.size(); ++i) {
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 12 ms 472 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 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 2 ms 344 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 452 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Incorrect 12 ms 476 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 12 ms 472 KB Wrong Answer [3]
4 Halted 0 ms 0 KB -