Submission #935295

# Submission time Handle Problem Language Result Execution time Memory
935295 2024-02-29T03:10:53 Z freedommo33 Chameleon's Love (JOI20_chameleon) C++17
64 / 100
29 ms 600 KB
#include <bits/stdc++.h>
#include "chameleon.h"
#include <vector>
#define query Query
#define answer Answer
constexpr long long M = 1005;
using namespace std;
vector<vector<long long>> sasiedzi(M);
vector<vector<long long>> g(M);
vector<vector<long long>> g2(M);
long long syn[M];
bool uzyte[M];
long long kolor[M];
vector<long long> spojna[2];

void dfs(int v, int k){
	kolor[v] = k;
	for(auto i:sasiedzi[v]) if(kolor[i]==0 || kolor[i]==k){
		if(k==1) dfs(i, 2);
		else	 dfs(i, 1);	
	}
}

int ilews(long long p, long long k, long long numer, long long koniec){
	vector<int> v;
	for(int i=p; i<=k; i++) v.push_back(spojna[numer][i-1]);
	if(koniec!=0) v.push_back(koniec);
	if(v.size()==0) return 0;
	return query(v);	
}
long long numero;
long long bs(long long koniec){
	long long temp2 = ilews(1, spojna[0].size(), 0, koniec);
	long long numer = 0;
	long long temp = spojna[0].size();
	if(temp < temp2){
		numer = 1;
		temp2 = ilews(1, spojna[1].size(), 1, koniec);
		temp = spojna[1].size();
		if(temp < temp2 && numer==1) return -1;
	}
	long long p = 1, k = spojna[numer].size(), mid;
	while(p<k){
		mid = (p+k)/2;
		//temp1 = ilews(p, mid, numer, 0);
		temp2 = ilews(p, mid, numer, koniec);
		if(mid-p+1 < temp2) p = mid + 1;
		else	k = mid;
	}
	numero = numer;
	return p-1;
}

void Solve(int n) {
	for(int i=1; i<=2*n; i++){
		long long aktKolor = 1;
		long long wyn = bs(i);
		vector<long long> doDodania;
		while(wyn!=-1){
			sasiedzi[i].push_back(spojna[numero][wyn]);
			sasiedzi[spojna[numero][wyn]].push_back(i);
			if(kolor[spojna[numero][wyn]] == 1) aktKolor=2;
			else if(kolor[spojna[numero][wyn]] == 2) aktKolor=1;
			doDodania.push_back(spojna[numero][wyn]);
			spojna[numero].erase(spojna[numero].begin() + wyn);
			wyn = bs(i);
		}
		for(auto j:doDodania){
			if(aktKolor==2 && (kolor[j]==2 || kolor[j]==0)) dfs(j, 1);
			else if(aktKolor==1 && (kolor[j]==1 || kolor[j]==0)) dfs(j, 2);
		}
		spojna[0].clear();
		spojna[1].clear();
		kolor[i] = aktKolor;
		for(int j=1; j<=2*n; j++){
			if(kolor[j]==1) spojna[0].push_back(j);
			if(kolor[j]==2) spojna[1].push_back(j);
		}
	}	
	for(int i=1; i<=n*2; i++){
		if(sasiedzi[i].size()!=1){
			if(query({i, sasiedzi[i][0], sasiedzi[i][1]})==1) syn[i] = sasiedzi[i][2];
			if(query({i, sasiedzi[i][0], sasiedzi[i][2]})==1) syn[i] = sasiedzi[i][1];
			if(query({i, sasiedzi[i][2], sasiedzi[i][1]})==1) syn[i] = sasiedzi[i][0];
		}
	}
	for(long long i=1; i<=n*2; i++){
		if(syn[i]!=0){
			g[i].push_back(syn[i]);
			g[syn[i]].push_back(i);
		}
	}
	for(long long i=1; i<=n*2; i++){
		sort(g[i].begin(), g[i].end());
		if(syn[i]==0){
			if(uzyte[min(i, sasiedzi[i][0])] == 0){
				uzyte[min(i, sasiedzi[i][0])] = 1;
				answer(i, sasiedzi[i][0]);
			}
		}
		else{
			if(g[i][0] == sasiedzi[i][0] && g[i][1] == sasiedzi[i][1]){
				if(uzyte[min(i, sasiedzi[i][2])] == 0){
					uzyte[min(i, sasiedzi[i][2])] = 1;
					answer(i, sasiedzi[i][2]);
				}
			}
			else if(g[i][0] == sasiedzi[i][0] && g[i][1] == sasiedzi[i][2]){
				if(uzyte[min(i, sasiedzi[i][1])] == 0){
					uzyte[min(i, sasiedzi[i][1])] = 1;
					answer(i, sasiedzi[i][1]);
				}
			}
			else if(g[i][0] == sasiedzi[i][1] && g[i][1] == sasiedzi[i][2]){
				if(uzyte[min(i, sasiedzi[i][0])] == 0){
					uzyte[min(i, sasiedzi[i][0])] = 1;
					answer(i, sasiedzi[i][0]);
				}
			}
		}
	}
}

Compilation message

chameleon.cpp: In function 'void Solve(int)':
chameleon.cpp:82:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   82 |    if(query({i, sasiedzi[i][0], sasiedzi[i][1]})==1) syn[i] = sasiedzi[i][2];
      |                                                ^
chameleon.cpp:82:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:82:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](1)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:82:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](1)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:83:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   83 |    if(query({i, sasiedzi[i][0], sasiedzi[i][2]})==1) syn[i] = sasiedzi[i][1];
      |                                                ^
chameleon.cpp:83:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:83:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](2)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:83:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](2)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:84:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](2)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
   84 |    if(query({i, sasiedzi[i][2], sasiedzi[i][1]})==1) syn[i] = sasiedzi[i][0];
      |                                                ^
chameleon.cpp:84:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](2)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:84:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](1)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
chameleon.cpp:84:48: warning: narrowing conversion of '(& sasiedzi.std::vector<std::vector<long long int> >::operator[](((std::vector<std::vector<long long int> >::size_type)i)))->std::vector<long long int>::operator[](1)' from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' [-Wnarrowing]
# 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 15 ms 344 KB Output is correct
4 Correct 15 ms 600 KB Output is correct
5 Correct 13 ms 344 KB Output is correct
6 Correct 12 ms 344 KB Output is correct
7 Correct 13 ms 548 KB Output is correct
8 Correct 12 ms 344 KB Output is correct
9 Correct 15 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 384 KB Output is correct
3 Correct 0 ms 596 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 0 ms 344 KB Output is correct
8 Correct 1 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 384 KB Output is correct
3 Correct 0 ms 596 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 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 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 344 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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 28 ms 552 KB Output is correct
4 Correct 28 ms 600 KB Output is correct
5 Correct 29 ms 600 KB Output is correct
6 Correct 28 ms 588 KB Output is correct
7 Correct 29 ms 600 KB Output is correct
8 Correct 28 ms 572 KB Output is correct
9 Correct 28 ms 592 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 15 ms 344 KB Output is correct
4 Correct 15 ms 600 KB Output is correct
5 Correct 13 ms 344 KB Output is correct
6 Correct 12 ms 344 KB Output is correct
7 Correct 13 ms 548 KB Output is correct
8 Correct 12 ms 344 KB Output is correct
9 Correct 15 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 596 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 28 ms 552 KB Output is correct
31 Correct 28 ms 600 KB Output is correct
32 Correct 29 ms 600 KB Output is correct
33 Correct 28 ms 588 KB Output is correct
34 Correct 29 ms 600 KB Output is correct
35 Correct 28 ms 572 KB Output is correct
36 Correct 28 ms 592 KB Output is correct
37 Incorrect 28 ms 592 KB Wrong Answer [7]
38 Halted 0 ms 0 KB -