Submission #883432

# Submission time Handle Problem Language Result Execution time Memory
883432 2023-12-05T09:20:50 Z marvinthang Chameleon's Love (JOI20_chameleon) C++17
20 / 100
24 ms 856 KB
/*************************************
*    author: marvinthang             *
*    created: 05.12.2023 15:10:01    *
*************************************/

#include "chameleon.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i-- > 0; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

void Solve(int n) {
	vector <vector <int>> adj(2 * n);
	vector <bool> used(2 * n);
	auto answer = [&] (int u, int v) {
		Answer(u + 1, v + 1);
		used[u] = used[v] = true;
	};
	auto query = [&] (vector <int> v) {
		for (int &x: v) ++x;
		return Query(v);
	};
	REP(i, n) {
		int last = n;
		REP(t, 3) {
			int l = last, r = 2 * n - 1;
			while (l <= r) {
				int m = l + r >> 1;
				vector <int> v {i};
				FORE(j, last, m) v.push_back(j);
				if (query(v) != v.size()) r = m - 1;
				else l = m + 1;
			}
			if (l == 2 * n) break;
			adj[i].push_back(l);
			adj[l].push_back(i);
			last = l + 1;
		}
	}
	REP(u, 2 * n) if (!used[u] && (int) adj[u].size() == 1) answer(u, adj[u][0]);
	vector <vector <bool>> dir(2 * n, vector<bool>(2 * n));
	REP(u, 2 * n) if (!used[u]) {
		REP(i, 3) {
			bool ok = false;
			REP(j, i) if (query({u, adj[u][i], adj[u][j]}) == 1) {
				swap(adj[u].back(), adj[u][3 - i - j]);
				ok = true;
				break;
			}
			if (ok) break;
		}
		dir[u][adj[u][2]] = true;
	}
	REP(u, 2 * n) if (!used[u]) {
		REP(i, 2) {
			int a = adj[u][i], b = adj[u][!i];
			if (dir[a][u] || used[a]) {
				answer(u, b);
				break;
			}
		}
	}
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |     int m = l + r >> 1;
      |             ~~^~~
chameleon.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     if (query(v) != v.size()) r = m - 1;
      |         ~~~~~~~~~^~~~~~~~~~~
# 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 Runtime error 18 ms 856 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer [6]
3 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 22 ms 532 KB Output is correct
4 Correct 22 ms 536 KB Output is correct
5 Correct 22 ms 592 KB Output is correct
6 Correct 23 ms 592 KB Output is correct
7 Correct 22 ms 716 KB Output is correct
8 Correct 24 ms 600 KB Output is correct
9 Correct 22 ms 600 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 Runtime error 18 ms 856 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -