QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104940#6309. AqrejeffqiWA 2ms5600kbC++231.8kb2023-05-12 16:01:362023-05-12 16:01:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-12 16:01:40]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5600kb
  • [2023-05-12 16:01:36]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define mp make_pair
#define vi vector<int>
#define eb emplace_back
#define all(v) v.begin(),v.end()
#define sz(v) ((int)v.size())
using namespace std;
LL read() {
	LL x = 0,y = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') y = -y; ch = getchar();}
	while (isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();} return x*y;
}
const int tst = 0,rd = 1; int getflg = 0;
namespace qiqi {
	const int N = 1e3+5; int n,m,cnt,id[N][N],a[N][N];
	struct DSU {
		vi fa; void init(int n) {fa.assign(n+1,0); iota(all(fa),0);}
		int find(int x) {return x == fa[x] ? x : fa[x] = find(fa[x]);}
		void merge(int x,int y) {
			x = find(x); y = find(y);
			if (x == y) return;
			fa[y] = x;
		}
	} dsu;
	bool valid(int x,int y) {return x >= 1 && x <= n && y >= 1 && y <= m;}
	void main() {
		n = read(); m = read(); cnt = 0;
		rep(i,1,n) rep(j,1,m) id[i][j] = ++cnt;
		vi p(4); pair<int,vi> ans = mp(0,vi());
		iota(all(p),0);
		do {
			int cur = 0,flg = 1;
			rep(i,1,n) rep(j,1,m) {
				cur += a[i][j] = p[i%4] != j%4;
			}
			dsu.init(cnt);
			rep(i,1,n) rep(j,1,m) if (a[i][j]) {
				if (valid(i+1,j) && a[i+1][j]) dsu.merge(id[i][j],id[i+1][j]);
				if (valid(i,j+1) && a[i][j+1]) dsu.merge(id[i][j],id[i][j+1]);
			}
			rep(i,1,n) rep(j,1,m) if (a[i][j]) flg &= dsu.find(id[i][j]) == dsu.find(1);
			ans = max(ans,mp(cur,p));
		} while (next_permutation(all(p)));
		p = ans.se;
		rep(i,1,n) rep(j,1,m) {
			a[i][j] = p[i%4] != j%4;
		}
		printf("%d\n",ans.fi);
		rep(i,1,n) {
			rep(j,1,m) printf("%d",a[i][j]); puts("");
		}
	}
}
int main() {
	int T = read(); while (T--) qiqi::main(); return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5600kb

input:

3
2 2
3 4
3 8

output:

4
11
11
9
1011
0111
1110
18
10111011
01110111
11101110

result:

wrong answer 1s are not connected. (test case 2)