QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781631#8892. Power GridDaiRuiChen007Compile Error//C++174.8kb2024-11-25 16:43:072024-11-25 16:43:13

Judging History

This is the latest submission verdict.

  • [2024-11-25 16:43:13]
  • Judged
  • [2024-11-25 16:43:07]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1005;
int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
vector <int> G[MAXN*4];
int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
bool ins[MAXN*4];
void tarjan(int u) {
	low[u]=dfn[u]=++dcnt,stk[++tp]=u,ins[u]=true;
	for(int v:G[u]) {
		if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
		else if(ins[v]) low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]) {
		++scnt;
		while(ins[u]) bel[stk[tp]]=scnt,ins[stk[tp--]]=false;
	}
}
int x[MAXN],y[MAXN];
signed main() {
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cin>>a[i][j];
	int tot=0;
	for(int i=2;i<=n;++i) rid[i][0]=++tot;
	for(int i=2;i<=m;++i) cid[i][0]=++tot;
	for(int i=2;i<=n;++i) rid[i][1]=++tot;
	for(int i=2;i<=m;++i) cid[i][1]=++tot;
	for(int i=2;i<=n;++i) for(int j=2;j<=m;++j) {
		for(int tx:{1,-1}) for(int ty:{1,-1}) {
			if(abs(tx*a[i][1]+ty*a[1][j]-a[1][1])!=a[i][j]) {
				int u=(tx==1),v=(ty==1);
				G[rid[i][u]].push_back(cid[j][v^1]);
				G[cid[j][v]].push_back(rid[i][u^1]);
//				cerr<<"ban("<<i<<","<<j<<") = "<<tx<<" "<<ty<<"\n";
				//ban (x,y)
			}
		}
	}
	for(int i=1;i<=tot;++i) if(!dfn[i]) tarjan(i);
//	for(int i=1;i<=tot;++i) {
//		cerr<<"u = "<<i<<": ";
//		for(int j:G[i]) cerr<<j<<" ";
//		cerr<<"\n";
//	}
//	for(int i=1;i<=tot;++i) cerr<<bel[i]<<" \n"[i==tot];
	for(int i=2;i<=n;++i) {
		assert(bel[rid[i][0]]!=bel[rid[i][1]]);
		if(bel[rid[i][0]]<bel[rid[i][1]]) a[i][1]*=-1;
	}
	for(int i=2;i<=m;++i) {
		assert(bel[cid[i][0]]!=bel[cid[i][1]]);
		if(bel[cid[i][0]]<bel[cid[i][1]]) a[1][i]*=-1;
	}
	for(int i=2;i<=n;++i) for(int j=2;j<=m;++j) {
		a[i][j]=a[i][1]+a[1][j]-a[1][1];
	}
//	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cerr<<a[i][j]<<" \n"[j==m];
	x[1]=0;
	for(int j=1;j<=m;++j) y[j]=x[1]-a[1][j];
	for(int i=2;i<=n;++i) x[i]=y[1]+a[i][1];
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) assert(a[i][j]==x[i]-y[j]);
	ll sx=0,sy=0;
	for(int i=1;i<=n;++i) sx+=x[i];
	for(int j=1;j<=m;++j) sy+=y[j];
	if(n==m) assert(sx==sy);
	else assert((sx-sy)%(n-m)==0);
	if(n!=m) {
		ll k=(sx-sy)/(m-n);
		for(int i=1;i<=n;++i) x[i]+=k;
		for(int j=1;j<=m;++j) y[j]+=k;
	}
	sx=0,sy=0;
	for(int i=1;i<=n;++i) sx+=x[i];
	for(int j=1;j<=m;++j) sy+=y[j];
	assert(sx==sy);
	memset(a,0,sizeof(a));
	for(int i=2;i<=n;++i) a[i][1]=x[i];
	for(int j=2;j<=m;++j) a[1][j]=y[j];
	a[1][1]=x[1]+y[1]-sx;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cout<<a[i][j]<<" \n"[j==m];
	return 0;
}#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1005;
int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
vector <int> G[MAXN*4];
int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
bool ins[MAXN*4];
void tarjan(int u) {
	low[u]=dfn[u]=++dcnt,stk[++tp]=u,ins[u]=true;
	for(int v:G[u]) {
		if(!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
		else low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]) {
		++scnt;
		while(ins[u]) bel[stk[tp]]=scnt,ins[stk[tp--]]=false;
	}
}
int x[MAXN],y[MAXN];
signed main() {
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cin>>a[i][j];
	int tot=0;
	for(int i=2;i<=n;++i) rid[i][0]=++tot;
	for(int i=2;i<=m;++i) cid[i][0]=++tot;
	for(int i=2;i<=n;++i) rid[i][1]=++tot;
	for(int i=2;i<=m;++i) cid[i][1]=++tot;
	for(int i=2;i<=n;++i) for(int j=2;j<=m;++j) {
		for(int tx:{1,-1}) for(int ty:{1,-1}) {
			if(abs(tx*a[i][1]+ty*a[1][j]-a[1][1])!=a[i][j]) {
				int u=(tx==1),v=(ty==1);
				G[rid[i][u]].push_back(cid[j][v^1]);
				G[cid[j][v]].push_back(rid[i][u^1]);
				//ban (x,y)
			}
		}
	}
	for(int i=1;i<=tot;++i) if(!dfn[i]) tarjan(i);
	for(int i=2;i<=n;++i) {
		assert(bel[rid[i][0]]!=bel[rid[i][1]]);
		if(bel[rid[i][0]]<bel[rid[i][1]]) a[i][1]*=-1;
	}
	for(int i=2;i<=m;++i) {
		assert(bel[cid[i][0]]!=bel[cid[i][1]]);
		if(bel[cid[i][0]]<bel[cid[i][1]]) a[1][i]*=-1;
	}
	for(int i=2;i<=n;++i) for(int j=2;j<=m;++j) {
		a[i][j]=a[i][1]+a[1][j]-a[1][1];
	}
//	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cerr<<a[i][j]<<" \n"[j==m];
	x[1]=0;
	for(int j=1;j<=m;++j) y[j]=x[1]-a[1][j];
	for(int i=2;i<=n;++i) x[i]=y[1]+a[i][1];
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) assert(a[i][j]==x[i]-y[j]);
	ll sx=0,sy=0;
	for(int i=1;i<=n;++i) sx+=x[i];
	for(int j=1;j<=m;++j) sy+=y[j];
	if(n==m) assert(sx==sy);
	else assert((sx-sy)%(n-m)==0);
	if(n!=m) {
		ll k=(sx-sy)/(m-n);
		for(int i=1;i<=n;++i) x[i]+=k;
		for(int j=1;j<=m;++j) y[j]+=k;
	}
	sx=0,sy=0;
	for(int i=1;i<=n;++i) sx+=x[i];
	for(int j=1;j<=m;++j) sy+=y[j];
	assert(sx==sy);
	memset(a,0,sizeof(a));
	for(int i=2;i<=n;++i) a[i][1]=x[i];
	for(int j=2;j<=m;++j) a[1][j]=y[j];
	a[1][1]=x[1]+y[1]-sx;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cout<<a[i][j]<<" \n"[j==m];
	return 0;
}

詳細信息

answer.code:84:2: error: stray ‘#’ in program
   84 | }#include<bits/stdc++.h>
      |  ^
answer.code:84:3: error: ‘include’ does not name a type
   84 | }#include<bits/stdc++.h>
      |   ^~~~~~~
answer.code:87:11: error: redefinition of ‘const int MAXN’
   87 | const int MAXN=1005;
      |           ^~~~
answer.code:4:11: note: ‘const int MAXN’ previously defined here
    4 | const int MAXN=1005;
      |           ^~~~
answer.code:88:5: error: redefinition of ‘int n’
   88 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |     ^
answer.code:5:5: note: ‘int n’ previously declared here
    5 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |     ^
answer.code:88:7: error: redefinition of ‘int m’
   88 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |       ^
answer.code:5:7: note: ‘int m’ previously declared here
    5 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |       ^
answer.code:88:9: error: redefinition of ‘int a [1005][1005]’
   88 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |         ^
answer.code:5:9: note: ‘int a [1005][1005]’ previously declared here
    5 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |         ^
answer.code:88:23: error: redefinition of ‘int rid [1005][2]’
   88 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |                       ^~~
answer.code:5:23: note: ‘int rid [1005][2]’ previously declared here
    5 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |                       ^~~
answer.code:88:36: error: redefinition of ‘int cid [1005][2]’
   88 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |                                    ^~~
answer.code:5:36: note: ‘int cid [1005][2]’ previously declared here
    5 | int n,m,a[MAXN][MAXN],rid[MAXN][2],cid[MAXN][2];
      |                                    ^~~
answer.code:89:14: error: redefinition of ‘std::vector<int> G [4020]’
   89 | vector <int> G[MAXN*4];
      |              ^
answer.code:6:14: note: ‘std::vector<int> G [4020]’ previously declared here
    6 | vector <int> G[MAXN*4];
      |              ^
answer.code:90:5: error: redefinition of ‘int low [4020]’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |     ^~~
answer.code:7:5: note: ‘int low [4020]’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |     ^~~
answer.code:90:17: error: redefinition of ‘int dfn [4020]’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                 ^~~
answer.code:7:17: note: ‘int dfn [4020]’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                 ^~~
answer.code:90:29: error: redefinition of ‘int dcnt’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                             ^~~~
answer.code:7:29: note: ‘int dcnt’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                             ^~~~
answer.code:90:34: error: redefinition of ‘int stk [4020]’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                  ^~~
answer.code:7:34: note: ‘int stk [4020]’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                  ^~~
answer.code:90:46: error: redefinition of ‘int tp’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                              ^~
answer.code:7:46: note: ‘int tp’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                              ^~
answer.code:90:49: error: redefinition of ‘int bel [4020]’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                                 ^~~
answer.code:7:49: note: ‘int bel [4020]’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                                 ^~~
answer.code:90:61: error: redefinition of ‘int scnt’
   90 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                                             ^~~~
answer.code:7:61: note: ‘int scnt’ previously declared here
    7 | int low[MAXN*4],dfn[MAXN*4],dcnt,stk[MAXN*4],tp,bel[MAXN*4],scnt;
      |                                                             ^~~~
answer.code:91:6: error: redefinition of ‘bool ins [4020]’
   91 | bool ins[MAXN*4];
      |      ^~~
answer.code:8:6: note: ‘bool ins [4020]’ previously declared here
    8 | bool ins[MAXN*4];
      |      ^~~
answer.code:92:6: error: redefinition of ‘void tarjan(int)’
   92 | void tarjan(int u) {
      |      ^~~~~~
answer.code:9:6: note: ‘void tarjan(int)’ previously defined...