QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104950#6309. AqrejeffqiTL 353ms5728kbC++233.3kb2023-05-12 16:36:502023-05-12 16:36:52

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:36:52]
  • 评测
  • 测评结果:TL
  • 用时:353ms
  • 内存:5728kb
  • [2023-05-12 16:36:50]
  • 提交

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;}
	pair<int,vi> dfs0(vi& p) {
		pair<int,vi> ans = mp(0,vi());
		if (sz(p) == 4) {
			int cnt = 0,flg = 1,fir = 0;
			rep(i,1,n) rep(j,1,m) {
				cnt += a[i][j] = p[i%4] != j%4;
			}
			dsu.init(n*m);
			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 (valid(i+3,j)) flg &= !(a[i][j] == a[i+1][j] && a[i][j] == a[i+2][j] && a[i][j] == a[i+3][j]);
				if (valid(i,j+3)) flg &= !(a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2] && a[i][j] == a[i][j+3]);
			}
			rep(i,1,n) rep(j,1,m) if (a[i][j]) {
				if (!fir) fir = dsu.find(id[i][j]);
				else flg &= fir == dsu.find(id[i][j]);
			}
			if (flg) ans = mp(cnt,p);
		}
		else {
			rep(i,0,3) {
				p.eb(i);
				ans = max(ans,dfs0(p));
				p.pop_back();
			}
		}
		return ans;
	}
	pair<int,vi> dfs1(vi& p) {
		pair<int,vi> ans = mp(0,vi());
		if (sz(p) == 4) {
			int cnt = 0,flg = 1,fir = 0;
			rep(i,1,n) rep(j,1,m) {
				cnt += a[i][j] = p[j%4] != i%4;
			}
			dsu.init(n*m);
			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 (valid(i+3,j)) flg &= !(a[i][j] == a[i+1][j] && a[i][j] == a[i+2][j] && a[i][j] == a[i+3][j]);
				if (valid(i,j+3)) flg &= !(a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2] && a[i][j] == a[i][j+3]);
			}
			rep(i,1,n) rep(j,1,m) if (a[i][j]) {
				if (!fir) fir = dsu.find(id[i][j]);
				else flg &= fir == dsu.find(id[i][j]);
			}
			if (flg) ans = mp(cnt,p);
		}
		else {
			rep(i,0,3) {
				p.eb(i);
				ans = max(ans,dfs1(p));
				p.pop_back();
			}
		}
		return ans;
	}
	void main() {
		n = read(); m = read(); cnt = 0;
		rep(i,1,n) rep(j,1,m) id[i][j] = ++cnt;
		vi p; pair<int,vi> ans0 = dfs0(p),ans1 = dfs1(p);
		if (ans0.fi > ans1.fi) {
			printf("%d\n",ans0.fi);
			rep(i,1,n) {
				rep(j,1,m) {
					printf("%d",ans0.se[i%4] != j%4);
				}
				puts("");
			}
		}
		else {
			printf("%d\n",ans1.fi);
			rep(i,1,n) {
				rep(j,1,m) {
					printf("%d",ans1.se[j%4] != i%4);
				}
				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: 100
Accepted
time: 3ms
memory: 5684kb

input:

3
2 2
3 4
3 8

output:

4
11
11
9
1101
0111
1110
18
11011101
01110111
11101110

result:

ok ok (3 test cases)

Test #2:

score: 0
Accepted
time: 353ms
memory: 5728kb

input:

361
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
2 20
3 2
3 3
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
3 14
3 15
3 16
3 17
3 18
3 19
3 20
4 2
4 3
4 4
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
4 19
4 20
5 2
5 3
5 4
5 5
5 6
5 7
5 8
5 9
5 1...

output:

4
11
11
6
111
111
6
1101
0111
8
10111
11101
9
110111
011101
11
1011101
1110111
12
11011101
01110111
14
101110111
111011101
15
1101110111
0111011101
17
10111011101
11101110111
18
110111011101
011101110111
20
1011101110111
1110111011101
21
11011101110111
01110111011101
23
101110111011101
1110111011101...

result:

ok ok (361 test cases)

Test #3:

score: -100
Time Limit Exceeded

input:

100
91 91
91 92
91 93
91 94
91 95
91 96
91 97
91 98
91 99
91 100
92 91
92 92
92 93
92 94
92 95
92 96
92 97
92 98
92 99
92 100
93 91
93 92
93 93
93 94
93 95
93 96
93 97
93 98
93 99
93 100
94 91
94 92
94 93
94 94
94 95
94 96
94 97
94 98
94 99
94 100
95 91
95 92
95 93
95 94
95 95
95 96
95 97
95 98
95 9...

output:

6211
1101110111011101110111011101110111011101110111011101110111011101110111011101110111011101110
0111011101110111011101110111011101110111011101110111011101110111011101110111011101110111011
1110111011101110111011101110111011101110111011101110111011101110111011101110111011101110111
1011101110111011101...

result: