QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104943#6309. AqrejeffqiWA 15ms5780kbC++232.0kb2023-05-12 16:08:132023-05-12 16:08:14

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:08:14]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5780kb
  • [2023-05-12 16:08:13]
  • 提交

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,fir = 0;
			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]) {
				fir = dsu.find(id[i][j]); break;
			}
			rep(i,1,n) rep(j,1,m) if (a[i][j]) {
				flg &= dsu.find(id[i][j]) == fir;
			}
			if (flg) 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: 100
Accepted
time: 2ms
memory: 5604kb

input:

3
2 2
3 4
3 8

output:

4
11
11
9
1011
1110
0111
18
10111011
11101110
01110111

result:

ok ok (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 15ms
memory: 5780kb

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
5
101
111
6
1011
1110
8
10111
11101
9
101110
111011
11
1011101
1110111
12
10111011
11101110
14
101110111
111011101
15
1011101110
1110111011
17
10111011101
11101110111
18
101110111011
111011101110
20
1011101110111
1110111011101
21
10111011101110
11101110111011
23
101110111011101
1110111011101...

result:

wrong answer ans finds a larger answer (test case 2)