답안 #677219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677219 2023-01-02T15:04:16 Z amirhoseinfar1385 Tug of War (BOI15_tug) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
int n,k;
vector<pair<pair<int,int>,int>>all;
vector<vector<int>>fa,fb;
int res=0,now=0;
vector<int>vis;
vector<pair<int,int>>allp;
vector<int>bf;

void bfs(int z){
	if(bf.size()==0){
		return ;
	}
//	cout<<bf[0]<<" "<<z<<" "<<allp.size()<<endl;
	vis[bf[0]]=1;
	for(auto x:bf){
		if(z==1){
			res-=all[x].second;
		}
		else{
			res+=all[x].second;
		}
	}
	vector<int>fake;
	for(auto x:bf){
		if(z==1){
			int v;
			if(fb[all[x].first.second][0]==x){
				v=fb[all[x].first.second][1];
			}
			else{
				v=fb[all[x].first.second][0];
			}
			if(vis[v]==0){
				vis[v]=1;
				fake.push_back(v);
			}
		}
		else{
			int v;
			if(fa[all[x].first.first][0]==x){
				v=fa[all[x].first.first][1];
			}
			else{
				v=fa[all[x].first.first][0];
			}
			if(vis[v]==0){
				vis[v]=1;
				fake.push_back(v);
			}
		}
	}
	bf.swap(fake);
	bfs((z^1));
}
const int mid=20*30000+10;
void solve(){
	bitset<mid>bt;
	bt[0]=1;
	for(int i=0;i<(int)allp.size();i++){
		int x=allp[i];
		bitset<mid>fake,fakea;
		for(int i=x;i<mid;i++){
			fake[i]=bt[i-x];
		}
		for(int i=0;i<mid-x;i++){
			fakea[i]=bt[i+x];
		}
		for(int i=0;i<mid;i++){
			if(fake[i]==1||fakea[i]==1){
				bt[i]=1;
			}
			else{
				bt[i]=0;
			}
		}
	}
	for(int i=0;i<=k;i++){
		if(bt[i]==1){
			cout<<"YES\n";
			exit(0);
		}
	}
	cout<<"NO\n";
	exit(0);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	vis.resize(n*2+1);
	fa.resize(n+1),fb.resize(n+1);
	all.resize(n*2);
	for(int i=0;i<n*2;i++){
		cin>>all[i].first.first>>all[i].first.second>>all[i].second;
	}
	for(int i=0;i<2*n;i++){
		fa[all[i].first.first].push_back(i);
		fb[all[i].first.second].push_back(i);
	}
	for(int i=1;i<=n;i++){
		if((int)fa[i].size()>2||(int)fb[i].size()>2){
			cout<<"NO\n";
			return 0;
		}
	}
	for(int i=0;i<n*2;i++){
		if(vis[i]==0){
			bf.push_back(i);
			res=0;
			bfs(1);
			allp.push_back(abs(res));
		}
	}
	solve();
}

Compilation message

tug.cpp: In function 'void solve()':
tug.cpp:62:15: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} to 'int' in initialization
   62 |   int x=allp[i];
      |               ^
tug.cpp: In function 'int main()':
tug.cpp:115:27: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(int)'
  115 |    allp.push_back(abs(res));
      |                           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from tug.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'int' to 'const value_type&' {aka 'const std::pair<int, int>&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'int' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~