Submission #853360

# Submission time Handle Problem Language Result Execution time Memory
853360 2023-09-24T08:38:13 Z willychan Dango Maker (JOI18_dango_maker) C++14
0 / 100
1 ms 348 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds

struct DINIC{
	struct edge{
		int to;
		ll cap;
		int rev;
	};
	vector<vector<edge> > side;
	vector<int> level;
	vector<int> next;
	int n;
	void init(int s){
		n = s;
		side.resize(n);
		level.resize(n,0);
		next.resize(n,0);
		for(int i=0;i<n;i++) side[i].clear();
	}
	
	void add_edge(int a,int b,ll c){
//		cout<<a<<"->"<<b<<"\n";
		side[a].push_back({b,c,(int)(side[b].size())});
		side[b].push_back({a,0,(int)(side[a].size()-1)});
	}
	
	bool bfs(int s,int t){
		fill(level.begin(),level.end(),-1);
		queue<int> q;
		level[s]=0;
		q.push(s);
		while(q.size()){
			int cur = q.front();
			q.pop();
			for(auto e : side[cur]){
				if(e.cap<=0) continue;
				if(level[e.to]<0){
					level[e.to] = level[cur]+1;
					q.push(e.to);
				}
			}
		}
		return (level[t]!=-1);
	}
	
	ll dfs(int v,int t,ll flow){
		if(v==t) return flow;	
		for(;next[v]<side[v].size();next[v]++){
			auto& e = side[v][next[v]];
			if(e.cap<=0 || level[v]+1!=level[e.to]) continue;	
			ll ans = dfs(e.to,t,min(flow,e.cap));
			if(ans>0){
				e.cap-=ans;
				side[e.to][e.rev].cap+=ans;
				return ans;
			}
		}
		return 0;
	}


	ll flow(int s,int t){
		ll ans= 0;
		while(bfs(s,t)){
			fill(next.begin(),next.end(),0);
			ll f = 0;
			while((f=dfs(s,t,1e18))>0){
				ans+=f;
			}
		}
		return ans;
	}
} graph;



int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,m;cin>>n>>m;	
	vector<vector<char>> grid(n,vector<char>(m));
	vector<vector<int> > taken(n,vector<int>(m,0));
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			grid[i][j] = getchar();
		}
		getchar();
	}
	int cnt = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j+2<m;j++){
			if(grid[i][j]=='R' && grid[i][j+1]=='G' && grid[i][j+2]=='W'){
				cnt++;
				taken[i][j]=cnt;
				taken[i][j+1]=cnt;
				taken[i][j+2]=cnt;
			}
		}
	}
	//cout<<cnt<<" ";
	int total = cnt;
	for(int j=0;j<m;j++){
		for(int i=0;i+2<m;i++){
			total+=(grid[i][j]=='R' && grid[i+1][j]=='G' && grid[i+2][j]=='W');
		}
	}
	//cout<<total<<"\n";
	graph.init(total+2)	;
	int ton = cnt;
	for(int j=0;j<m;j++){
		for(int i=0;i+2<m;i++){
			if(grid[i][j]=='R' && grid[i+1][j]=='G' && grid[i+2][j]=='W'){
				ton++;
				if(taken[i][j]) graph.add_edge(taken[i][j],ton,1);
				if(taken[i+1][j]) graph.add_edge(taken[i+1][j],ton,1);
				if(taken[i+2][j]) graph.add_edge(taken[i+2][j],ton,1);
			}
		}
	}	
	for(int i=1;i<=cnt;i++){
		graph.add_edge(0,i,1);
	}
	for(int i=cnt+1;i<=total;i++){
		graph.add_edge(i,total+1,1);
	}
	ll ans = graph.flow(0,total+1);
	cout<<total-ans<<"\n";
	return 0;
}

Compilation message

dango_maker.cpp: In member function 'll DINIC::dfs(int, int, ll)':
dango_maker.cpp:52:15: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<DINIC::edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(;next[v]<side[v].size();next[v]++){
# 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 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 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -