QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359118#5071. Check Pattern is GoodDoqeCompile Error//C++203.0kb2024-03-20 13:16:432024-03-20 13:16:45

Judging History

你现在查看的是最新测评结果

  • [2024-03-20 13:16:45]
  • 评测
  • [2024-03-20 13:16:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace Flow
{
const int N=4e4+10,M=5e5+10;
int hd[N],to[M<<1],nx[M<<1],W[M<<1],tt=1,po;
void add(int u,int v,int w){to[++tt]=v,W[tt]=w,nx[tt]=hd[u],hd[u]=tt;}
void link(int u,int v,int w){add(u,v,w),add(v,u,0);po=max({po,u,v});}
int q[N],l,r,cur[N],dep[N],S,T,n,m;
bool bfs()
{
	memset(dep,0,sizeof(int)*(po+10));
	memcpy(cur,hd,sizeof(int)*(po+10));
	q[l=r=1]=S;dep[S]=1;
	while(l<=r)
	{
		int u=q[l++];
		for(int i=hd[u];i;i=nx[i])
		{
			int v=to[i];
			if(W[i]&&!dep[v])q[++r]=v,dep[v]=dep[u]+1;
		}
	}
	return dep[T];
}
int dfs(int u,int f)
{
	if(u==T)return f;
	int r=0,k;
	for(int&i=cur[u];i;i=nx[i])
	{
		int v=to[i];
		if(W[i]&&dep[v]==dep[u]+1)
		{
			k=dfs(v,min(W[i],f));
			f-=k,r+=k;W[i]-=k,W[i^1]+=k;if(!f)break;
		}
	}
	if(f)dep[u]=0;
	return r;
}
int Dinic()
{
//	cerr<<"FLOW: "<<po<<" "<<S<<" "<<T<<endl;
	int flow=0;
	while(bfs())flow+=dfs(S,0x3f3f3f3f);
	return flow;
}
void ini()
{
	memset(hd,0,sizeof(int)*(po+10));
	tt=1;po=0;
}
}
const int N=110;
int I[N][N],n,m;
char s[N][N],trans[128];
int main()
{
	int T;
	cin>>T;
	trans['W']='B';
	trans['B']='W';
	trans['?']='?';
	while(T--)
	{
		cin>>n>>m;Flow::ini();
		for(int i=1;i<=n;++i)cin>>s[i]+1;
		int cnt=1;Flow::S=1,Flow::T=2;Flow::po=2; 
		for(int i=1;i<=n;++i)
			for(int j=1;j<=m;++j)
				I[i][j]=(cnt+=2);
		cnt+=2;
//		for(int i=1;i<n;++i)
//			for(int j=1;j<n;++j)
//				A[i][j]=(cnt+=2);
		int X=0;
		for(int i=n;i;--i)
			for(int j=m;j;--j)
			{
				if(i+j&1)s[i][j]=trans[s[i][j]];
				if(s[i][j]=='?')
				{
					Flow::link(Flow::S,I[i][j],1);
					Flow::link(I[i][j],I[i][j]+1,100000);
					Flow::link(I[i][j]+1,Flow::T,1);++X;
				}
			}
//		for(int i=1;i<=n;++i)cerr<<s[i]+1<<"_\n";
		int Q=Flow::hd[Flow::S];
		for(int i=1;i<n;++i)
			for(int j=1;j<m;++j)
			{
//				cerr<<"CMP: "<<s[i][j]<<s[i+1][j]<<s[i][j+1]<<s[i+1][j+1]<<endl;
				if(	s[i][j]!='W'&&s[i+1][j]!='W'&&
					s[i][j+1]!='W'&&s[i+1][j+1]!='W')
					{
//						cerr<<"NEW: S"<<endl;
						Flow::link(Flow::S,++cnt,1);
						Flow::link(cnt,I[i][j],1);
						Flow::link(cnt,I[i][j+1],1);
						Flow::link(cnt,I[i+1][j],1);
						Flow::link(cnt,I[i+1][j+1],1);
						++X;
					}
				
				if(	s[i][j]!='B'&&s[i+1][j]!='B'&&
					s[i][j+1]!='B'&&s[i+1][j+1]!='B')
					{
//						cerr<<"NEW: T"<<endl;
						Flow::link(++cnt,Flow::T,1);
						Flow::link(I[i][j]+1,cnt,1);
						Flow::link(I[i][j+1]+1,cnt,1);
						Flow::link(I[i+1][j]+1,cnt,1);
						Flow::link(I[i+1][j+1]+1,cnt,1);
						++X;
					}
			}
//		cerr<<"DINIC_______________\n";
		int ans=Flow::Dinic();
//		cerr<<"ED\n";
//		cerr<<X<<" "<<ans<<endl; 
		cout<<X-ans<<endl;
		for(int i=1;i<=n;++i,cout<<"\n")
			for(int j=1;j<=m;++j)
			{
				char c;
				if(s[i][j]!='?')c=s[i][j];
				else
				{
					assert(Flow::to[Q]==I[i][j]);
					c=!Flow::W[Q]?'B':'W';
					Q=Flow::nx[Q];
				}
				if(i+j&1)c=trans[c];
				cout<<c;
			}
	}
	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:68:41: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘char*’)
   68 |                 for(int i=1;i<=n;++i)cin>>s[i]+1;
      |                                      ~~~^~~~~~~~
      |                                      |        |
      |                                      |        char*
      |                                      std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from answer.code:1:
/usr/include/c++/13/istream:325:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  325 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/13/istream:325:7: note:   conversion of argument 1 would be ill-formed:
answer.code:68:47: error: cannot bind non-const lvalue reference of type ‘void*&’ to an rvalue of type ‘void*’
   68 |                 for(int i=1;i<=n;++i)cin>>s[i]+1;
      |                                           ~~~~^~
/usr/include/c++/13/istream:201:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  201 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:201:7: note:   conversion of argument 1 would be ill-formed:
answer.code:68:47: error: invalid conversion from ‘char*’ to ‘long long unsigned int’ [-fpermissive]
   68 |                 for(int i=1;i<=n;++i)cin>>s[i]+1;
      |                                           ~~~~^~
      |                                               |
      |                                               char*
answer.code:68:47: error: cannot bind rvalue ‘(long long unsigned int)(((char*)(& s[i])) + 1)’ to ‘long long unsigned int&’
/usr/include/c++/13/istream:197:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  197 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:197:7: note:   conversion of argument 1 would be ill-formed:
answer.code:68:47: error: invalid conversion from ‘char*’ to ‘long long int’ [-fpermissive]
   68 |                 for(int i=1;i<=n;++i)cin>>s[i]+1;
      |                                           ~~~~^~
      |                                               |
      |                                               char*
answer.code:68:47: error: cannot bind rvalue ‘(long long int)(((char*)(& s[i])) + 1)’ to ‘long long int&’
/usr/include/c++/13/istream:192:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:192:7: note:   conversion of argument 1 would be ill-formed:
answer.code:68:47: error: invalid conversion from ‘char*’ to ‘long unsigned int’ [-fpermissive]
   68 |                 for(int i=1;i<=n;++i)cin>>s[i]+1;
      |                                           ~~~~^~
      |                                               |
      |                                               char*
answer.code:68:47: error: cannot bind rvalue ‘(long unsigned int)(((char*)(& s[i])) + 1)’ to ‘long unsigned int&’
/usr/include/c++/13/istream:188:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’ (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/13/istream:188:7: note:   conversion of argument 1 would be ill-formed:
answer.code:68:47: error: invalid conversion from ‘char*’ to ‘long int’ [-fpermissive]
   68 |                 for(int i=1;i<=n;++i)cin>>s[i]+1;
      |                                           ~~~~^~
      |                                               |
      |                                               char*
answer.code:68:47: error: cannot bind rvalue ‘(long int)(((char*)(& s[i])) + 1)’ to ‘long int&’
/usr/include/c++/13/istream:184:7: note: candidate: ‘std::basic_istream<_CharT, _Trait...