QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89811#1283. Paper-cuttingAFewSunsCompile Error//C++143.9kb2023-03-21 14:42:432023-03-21 14:42:47

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-21 14:42:47]
  • 评测
  • [2023-03-21 14:42:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<ll> a[1000010],ck[1000010];
ll T,n,m,cnt=0,f[2000020],ans=inf;
char s[1000010],t[2000020];
bl ckl[1000010],ckr[1000010],cku[1000010],ckd[1000010];
struct node{
	ll l,r,d,u;
}p[1000010];
void init(ll N){
	ll len=2*N+2;
	t[0]='*';
	t[len]='&';
	fr(i,1,len-1){
		if(i%2==0) t[i]=s[i/2];
		else t[i]='%';
	}
	ll maxx=0,mid=0;
	fr(i,1,len){
		if(i<maxx) f[i]=min(f[2*mid-i],maxx-i);
		else f[i]=1;
		while(t[i-f[i]]==t[i+f[i]]) f[i]++;
		if(maxx<i+f[i]){
			mid=i;
			maxx=i+f[i];
		}
	}
}
void dfs(ll x,ll y){
	ck[x][y]=1;
	p[cnt].l=min(p[cnt].l,y);
	p[cnt].r=max(p[cnt].r,y);
	p[cnt].u=min(p[cnt].u,x);
	p[cnt].d=max(p[cnt].d,x);
	if(x>1&&!a[x-1][y]&&!ck[x-1][y]) dfs(x-1,y);
	if(x<n&&!a[x+1][y]&&!ck[x+1][y]) dfs(x+1,y);
	if(y>1&&!a[x][y-1]&&!ck[x][y-1]) dfs(x,y-1);
	if(y<m&&!a[x][y+1]&&!ck[x][y+1]) dfs(x,y+1);
}
void solve(ll dx,ll dy){
	fr(i,1,n) fr(j,1,m) ck[i][j]=0;
	fr(i,1,cnt){
		ck[p[i].u][p[i].l]++;
		ck[p[i].d+1-dx][p[i].l]--;
		ck[p[i].u][p[i].r+1-dy]--;
		ck[p[i].d+1-dx][p[i].r+1-dy]++;
	}
	fr(i,1,n) fr(j,1,m) ck[i][j]+=ck[i][j-1]+ck[i-1][j]-ck[i-1][j-1];
	fr(i,1,n) fr(j,1,m) ck[i][j]+=ck[i][j-1]+ck[i-1][j]-ck[i-1][j-1];
	ll d=0,r=0;
	fr(u,1,n){
		if(!cku[u]) continue;
		if(d<u) d=u;
		while(d<n&&!ckd[d]) d++;
		if(!ckd[d]) break;
		r=0;
		fr(l,1,m){
			if(!ckl[l]) continue;
			if(r<l) r=l;
			while(r<m&&!ckr[r]) r++;
			if(!ckr[r]) break;
			if(a[u][l]==inf) a[u][l]=0;
			if(dx^dy) a[u][l]-=ck[d-dx][r-dy]-ck[u-1][r-dy]-ck[d-dx][l-1]+ck[u-1][l-1];
			else a[u][l]+=ck[d-dx][r-dy]-ck[u-1][r-dy]-ck[d-dx][l-1]+ck[u-1][l-1];
		}
	}
}
void clr(){
	fr(i,1,m) ckl[i]=ckr[i]=0;
	fr(i,1,n) cku[i]=ckd[i]=0;
	fr(i,0,n+1) a[i].clear();
	fr(i,0,n+1) ck[i].clear();
	ans=inf;
	cnt=0;
}
int main(){
	T=read();
	fr(_,1,T){
		n=read();
		m=read();
		fr(i,0,n+1) a[i].resize(m+2);
		fr(i,0,n+1) ck[i].resize(m+2);
		fr(i,1,n) cku[i]=ckd[i]=1;
		fr(i,1,m) ckl[i]=ckr[i]=1;
		fr(i,1,n){
			scanf("%s",s+1);
			if(_==37){
				fr(j,1,m) cout<<s[j];
				enter;
			}
			fr(j,1,m) a[i][j]=s[j]-'0';
			init(m);
			fr(j,1,m) ckl[j]&=((f[2*j-1]-1)/2==(j-1));
			fr(j,1,m) ckr[j]&=((f[2*j+1]-1)/2==(m-j));
		}
		fr(j,1,m){
			fr(i,1,n) s[i]=a[i][j]+'0';
			init(n);
			fr(i,1,n) cku[i]&=((f[2*i-1]-1)/2==(i-1));
			fr(i,1,n) ckd[i]&=((f[2*i+1]-1)/2==(n-i));
		}
		fr(i,1,n){
			fr(j,1,m){
				if(!ck[i][j]&&!a[i][j]){
					p[++cnt]=(node){j,j,i,i};
					dfs(i,j);
				}
			}
		}
		fr(i,1,n) fr(j,1,m) a[i][j]=inf;
		solve(0,0);
		solve(1,0);
		solve(0,1);
		solve(1,1);
		fr(i,1,n) fr(j,1,m){
			ans=min(ans,a[i][j]);
		}
		if(t==3) writeln(ans);
		clr();
	}
}

详细

answer.code: In function ‘int main()’:
answer.code:187:21: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
  187 |                 if(t==3) writeln(ans);
      |                    ~^~~
answer.code:155:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  155 |                         scanf("%s",s+1);
      |                         ~~~~~^~~~~~~~~~