Submission #210500

# Submission time Handle Problem Language Result Execution time Memory
210500 2020-03-17T14:17:51 Z kshitij_sodani Snake Escaping (JOI18_snake_escaping) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long int llo;
#define a first
#define  b second
#define endl "\n"
llo aa=7;
vector<llo> aac[1000001];

vector<llo> pre[130];
llo sl3[21];
llo sl[22];
llo l;
llo dp[1600000];
llo last[1600000];
llo ans[1000000];
llo it[1200000];
llo num[1200000];
llo ok;
void find(llo ind,llo tot,llo ind2){//pre_sub
	if(ind==aa){
		pre[tot].pb(ind2);
	//	cout<<tot<<" "<<ind2<<endl;
	}
	else{
		if(aac[ind2][ind]%2==0){
			find(ind+1,tot,ind2);
		}
		if(aac[ind2][ind]>0){
			find(ind+1,tot+sl[aa-ind-1],ind2);
		}
	}
}
void find2(llo ind,llo ind2,llo tot=0){//
	if(ind==l-aa){
		last[tot]=ind2;
//		cout<<tot<<","<<ind2<<endl;
		return;
	}
	if(ind==ind2){
		find2(ind+1,ind2,tot+2*sl3[(l-aa)-ind-1]);
	}
	else{
		find2(ind+1,ind2,tot);
		find2(ind+1,ind2,tot+sl3[(l-aa)-ind-1]);
	}
	if(ind<ind2){
		find2(ind+1,ind2,tot+2*sl3[(l-aa)-ind-1]);
	}
}
llo find3(llo ind){//dp
	if(dp[ind]>-1){
		return dp[ind];
	}
	if(last[ind]==-1){
		dp[ind]=it[ind+ok*(sl[l-aa])];
		return dp[ind];
	}
	dp[ind]=find3(ind-sl3[l-aa-last[ind]-1])+find3(ind-2*sl3[l-aa-last[ind]-1]);
	return dp[ind];

}
//void(llo)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	memset(last,-1,sizeof(last));
	memset(num,0,sizeof(num));
	sl[0]=1;
	for(llo i=1;i<22;i++){
		sl[i]=2*sl[i-1];
	}
	sl3[0]=1;
	for(llo i=1;i<14;i++){
		sl3[i]=3*sl3[i-1];
	}

	llo q;
	cin>>l>>q;
	aa=min(7,l-1);
	llo n=1<<l;
	
	char ss;
	for(llo i=0;i<n;i++){
		cin>>ss;
		it[i]=ss-'0';
	}
	

	for(llo ii=0;ii<q;ii++){
		for(llo i=0;i<l;i++){
			cin>>ss;
			if(ss=='0'){
				aac[ii].pb(0);
				if(l==1){
					cout<<it[0]<<endl;
				}
				
			}
			else if(ss=='1'){
				aac[ii].pb(1);
				if(l==1){
					cout<<it[1]<<endl;
				}
				else{
					if(i>=aa){
						num[ii]+=sl3[l-i-1];
					}
				} 
			}
			else{
				aac[ii].pb(2);
				if(l==1){
					cout<<it[0]+it[1]<<endl;
				}
				else{
					if(i>=aa){
						num[ii]+=2*sl3[l-i-1];
					}
				}
			}
		}
	}
	/*for(llo i=0;i<q;i++){
		cout<<num[i]<<" ";
	}
	cout<<endl;*/
	if(l==1){
		return 0;
	}
	for(llo i=0;i<q;i++){
		find(0,0,i);
	}
	memset(ans,0,sizeof(ans));
	for(llo i=0;i<l-aa;i++){
		find2(0,i,0);
	}
	for(llo i=0;i<130;i++){
		if(pre[i].size()==0){
			continue;
		}
	}
	for(llo i=0;i<130;i++){
		ok=i;
		if(pre[i].size()){

			memset(dp,-1,sizeof(dp));
			for(llo j=0;j<1600000;j++){
				find3(j);
			}
			for(auto j:pre[i]){
				ans[j]+=dp[num[j]];
			//	cout<<i<<":"<<j<<":"<<dp[num[j]]<<endl;

			}
		}

		

	}
	for(llo i=0;i<q;i++){
		cout<<ans[i]<<endl;
	}









	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:83:14: error: no matching function for call to 'min(int, llo)'
  aa=min(7,l-1);
              ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from snake_escaping.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:83:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'llo {aka long long int}')
  aa=min(7,l-1);
              ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from snake_escaping.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:83:14: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'llo {aka long long int}')
  aa=min(7,l-1);
              ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from snake_escaping.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:83:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  aa=min(7,l-1);
              ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from snake_escaping.cpp:2:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
snake_escaping.cpp:83:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  aa=min(7,l-1);
              ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from snake_escaping.cpp:2:
/usr/include/c++/7/bits/stl_algo.h: In instantiation of '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const long long int>]':
/usr/include/c++/7/bits/stl_algo.h:3907:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = long long int]'
snake_escaping.cpp:135:13:   required from here
/usr/include/c++/7/bits/stl_algo.h:162:34: error: no matching function for call to '__iterator_category(int&)'
          std::__iterator_category(__first));
          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/7/bits/stl_algobase.h:65:0,
                 from /usr/include/c++/7/bits/char_traits.h:39,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from snake_escaping.cpp:1:
/usr/include/c++/7/bits/stl_iterator_base_types.h:205:5: note: candidate: template<class _Iter> constexpr typename std::iterator_traits<_Iterator>::iterator_category std::__iterator_category(const _Iter&)
     __iterator_category(const _Iter&)
     ^~~~~~~~~~~~~~~~~~~
/usr/include/c++/7/bits/stl_iterator_base_types.h:205:5: note:   template argument deduction/substitution failed:
/usr/include/c++/7/bits/stl_iterator_base_types.h: In substitution of 'template<class _Iter> constexpr typename std::iterator_traits<_Iterator>::iterator_category std::__iterator_category(const _Iter&) [with _Iter = int]':
/usr/include/c++/7/bits/stl_algo.h:162:34:   required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = int; _Predicate = __gnu_cxx::__ops::_Iter_equals_val<const long long int>]'
/usr/include/c++/7/bits/stl_algo.h:3907:28:   required from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = int; _Tp = long long int]'
snake_escaping.cpp:135:13:   required from here
/usr/include/c++/7/bits/stl_iterator_base_types.h:205:5: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>'