답안 #212240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212240 2020-03-22T15:37:50 Z abacaba 카멜레온의 사랑 (JOI20_chameleon) C++14
컴파일 오류
0 ms 0 KB
#include "chameleon.h"
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

namespace {

int variable_example = 1;

}  // namespace

int n, cl[N_MAX << 1];

vector <int> g[N_MAX << 1];
vector <int> s[2];

void dfs(int v) {
	for(int to : g[v])
		if(!cl[to]) {
			cl[to] = 3 - cl[v];
			dfs(to);
		}
}


inline bool bad(vector <int> x, int r) {
	x.pb(r);
	return Query(x) != x.size();
}

int same_color[N_MAX << 1];

inline pii gt(int a, int b) {
	return mp(min(a, b), max(a, b));
}

set <pii> is;

int loves[N_MAX << 1];

inline void Solve(int N) {
	n = N;
	for(int i = 1; i <= 2 * n; ++i) {
		for(int j = 0; j < 2; ++j)
			s[j].clear();
		for(int j = 1; j < i; ++j)
			cl[j] = 0;
		for(int j = 1; j < i; ++j) {
			if(!cl[j]) {
				cl[j] = 1;
				dfs(j);
			}
			s[cl[j] - 1].pb(j);
		}
		for(int j = 0; j < 2; ++j) {
			vector <int> cur = s[j];
			while(bad(cur, i)) {
				int l = 0, r = (int)cur.size() - 1, res = -1;
				while(l <= r) {
					int mid = l + r >> 1;
					if(bad(vector <int> (cur.begin() + mid, cur.end()), i))
						l = mid + 1, res = mid;
					else
						r = mid - 1;
				}
				assert(res != -1);
				g[cur[res]].pb(i), g[i].pb(cur[res]);
				cur = vector <int> (cur.begin(), cur.begin() + res);
			}
		}
	}
	for(int i = 1; i <= 2 * n; ++i) {
		assert(g[i].size() == 1 || g[i].size() == 3);
		if(g[i].size() == 1)
			same_color[i] = g[i][0];
		else {
			for(int mask = 0; mask < 8; ++mask) {
				if(cntbit(mask) != 2)
					continue;
				vector <int> now = {i};
				for(int j = 0; j < 3; ++j)
					if(1 << j & mask)
						now.pb(g[i][j]);
				if(Query(now) == 1) {
					for(int j = 0; j < 3; ++j)
						if(!(1 << j & mask))
							loves[i] = g[i][j];
				}
			}
		}
	}
	for(int i = 1; i <= 2 * n; ++i) {
		if(g[i].size() == 1)
			is.insert(gt(i, same_color[i]));
		else {
			for(int j = 0; j < 3; ++j) {
				if(g[i][j] != loves[i] && loves[g[i][j]] != i) {
					same_color[g[i][j]] = i;
					same_color[i] = g[i][j];
				}
			}
		}
		is.insert(gt(same_color[i], i));
	}
	for(pii e : is)
		Answer(e.f, e.se);
}

Compilation message

chameleon.cpp:46:11: error: 'N_MAX' was not declared in this scope
 int n, cl[N_MAX << 1];
           ^~~~~
chameleon.cpp:46:11: note: suggested alternative: 'INT8_MAX'
 int n, cl[N_MAX << 1];
           ^~~~~
           INT8_MAX
chameleon.cpp:48:16: error: 'N_MAX' was not declared in this scope
 vector <int> g[N_MAX << 1];
                ^~~~~
chameleon.cpp:48:16: note: suggested alternative: 'INT8_MAX'
 vector <int> g[N_MAX << 1];
                ^~~~~
                INT8_MAX
chameleon.cpp: In function 'void dfs(int)':
chameleon.cpp:52:15: error: 'g' was not declared in this scope
  for(int to : g[v])
               ^
chameleon.cpp:53:7: error: 'cl' was not declared in this scope
   if(!cl[to]) {
       ^~
chameleon.cpp:53:7: note: suggested alternative: 'll'
   if(!cl[to]) {
       ^~
       ll
chameleon.cpp: In function 'bool bad(std::vector<int>, int)':
chameleon.cpp:62:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return Query(x) != x.size();
         ~~~~~~~~~^~~~~~~~~~~
chameleon.cpp: At global scope:
chameleon.cpp:65:16: error: 'N_MAX' was not declared in this scope
 int same_color[N_MAX << 1];
                ^~~~~
chameleon.cpp:65:16: note: suggested alternative: 'INT8_MAX'
 int same_color[N_MAX << 1];
                ^~~~~
                INT8_MAX
chameleon.cpp:73:11: error: 'N_MAX' was not declared in this scope
 int loves[N_MAX << 1];
           ^~~~~
chameleon.cpp:73:11: note: suggested alternative: 'INT8_MAX'
 int loves[N_MAX << 1];
           ^~~~~
           INT8_MAX
chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:81:4: error: 'cl' was not declared in this scope
    cl[j] = 0;
    ^~
chameleon.cpp:81:4: note: suggested alternative: 'll'
    cl[j] = 0;
    ^~
    ll
chameleon.cpp:83:8: error: 'cl' was not declared in this scope
    if(!cl[j]) {
        ^~
chameleon.cpp:83:8: note: suggested alternative: 'll'
    if(!cl[j]) {
        ^~
        ll
chameleon.cpp:87:6: error: 'cl' was not declared in this scope
    s[cl[j] - 1].pb(j);
      ^~
chameleon.cpp:87:6: note: suggested alternative: 'll'
    s[cl[j] - 1].pb(j);
      ^~
      ll
chameleon.cpp:94:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
      int mid = l + r >> 1;
                ~~^~~
chameleon.cpp:101:5: error: 'g' was not declared in this scope
     g[cur[res]].pb(i), g[i].pb(cur[res]);
     ^
In file included from /usr/include/c++/7/cassert:44:0,
                 from chameleon.cpp:20:
chameleon.cpp:107:10: error: 'g' was not declared in this scope
   assert(g[i].size() == 1 || g[i].size() == 3);
          ^
chameleon.cpp:109:4: error: 'same_color' was not declared in this scope
    same_color[i] = g[i][0];
    ^~~~~~~~~~
chameleon.cpp:121:8: error: 'loves' was not declared in this scope
        loves[i] = g[i][j];
        ^~~~~
chameleon.cpp:127:6: error: 'g' was not declared in this scope
   if(g[i].size() == 1)
      ^
chameleon.cpp:128:20: error: 'same_color' was not declared in this scope
    is.insert(gt(i, same_color[i]));
                    ^~~~~~~~~~
chameleon.cpp:131:19: error: 'loves' was not declared in this scope
     if(g[i][j] != loves[i] && loves[g[i][j]] != i) {
                   ^~~~~
chameleon.cpp:132:6: error: 'same_color' was not declared in this scope
      same_color[g[i][j]] = i;
      ^~~~~~~~~~
chameleon.cpp:137:16: error: 'same_color' was not declared in this scope
   is.insert(gt(same_color[i], i));
                ^~~~~~~~~~
chameleon.cpp: At global scope:
chameleon.cpp:42:5: warning: '{anonymous}::variable_example' defined but not used [-Wunused-variable]
 int variable_example = 1;
     ^~~~~~~~~~~~~~~~