QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#183746#7398. Triangle TilingzhoukangyangWA 4ms26208kbC++113.3kb2023-09-19 19:55:062023-09-19 19:55:07

Judging History

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

  • [2023-09-19 19:55:07]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:26208kb
  • [2023-09-19 19:55:06]
  • 提交

answer

#include<bits/stdc++.h> 
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long 
#define vi vector < int > 
#define sz(a) (int) (a).size()
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
template < int N, int Ne >  struct flows { 
	using F = int; // flow type
	F inf = 1e9;
	int n, s, t; // Remember to assign n, s and t !
	int ehd[N], cur[N], ev[Ne << 1], enx[Ne << 1], eid = 1;
	void clear() {
		eid = 1;
		L(i, 1, n) ehd[i] = 0;
	}
	F ew[Ne << 1], dis[N];
	void Eadd(int u, int v, F w) {
		++eid, enx[eid] = ehd[u], ew[eid] = w, ev[eid] = v, ehd[u] = eid;
	}
	void add(int u, int v, F w) {
		Eadd(u, v, w), Eadd(v, u, 0);
	}
	bool bfs() {
		queue < int > q;
		L(i, 1, n) dis[i] = inf, cur[i] = ehd[i]; 
		q.push(s), dis[s] = 0;
		while(!q.empty()) {
			int u = q.front();
			q.pop();
			for(int i = ehd[u]; i; i = enx[i]) if(ew[i] && dis[ev[i]] == inf) {
				dis[ev[i]] = dis[u] + 1, q.push(ev[i]);
			}
		}
		return dis[t] < inf;
	}
	F dfs(int x, F now) {
		if(!now || x == t) return now;
		F res = 0, f;
		for(int i = cur[x]; i; i = enx[i]) {
			cur[x] = i;
			if(ew[i] && dis[ev[i]] == dis[x] + 1) {
				f = dfs(ev[i], min(now, ew[i])), ew[i] -= f, now -= f, ew[i ^ 1] += f, res += f;
				if(!now) break;
			}
		}
		return res;
	}
	F max_flow() {
		F res = 0;
		while(bfs()) res += dfs(s, inf);
		return res;
	}
} ; 

const int N = 5007;

flows < N * N, N * N * 3 / 2 > G;

int n;
char s[N][N];
int Pl[N][N], Pr[N][N];
bool win[N][N], gol[N][N];
short ans[N][N];

void Main() {
	G.clear();
	cin >> n;
	L(i, 1, n) {
		cin >> (s[i] + 1); 
	}
	G.n = 0;
	L(i, 1, n) {
		L(j, 1, i) {
			Pl[i][j] = ++G.n; 
			Pr[i][j] = ++G.n;
		}
	}
	G.s = ++G.n, G.t = ++G.n;
	L(i, 1, n) 
		Pr[i][0] = G.t;
	L(i, 1, n) 
		L(j, 1, i) 
			if(s[i][j] == '0') 
				G.add(G.s, Pr[i][j], 1);
	int cur = G.eid;
	L(i, 1, n) {
		L(j, 1, i) {
			G.add(Pr[i][j], Pl[i][j], 1);
			G.add(Pl[i][j], Pr[i][j - 1], 1);
			if(i > 1 && j > 1) G.add(Pl[i][j], Pr[i - 1][j - 1], 1);
		}
	} 
	if(G.max_flow() < n) {
		cout << "Impossible!\n";
		return ;
	}
	L(i, 1, n) {
		L(j, 1, i) {
			win[i][j] = 0;
			if(G.ew[cur + 2]) {
				win[i][j] = 1;
			} 
			cur += 2;
			if(win[i][j]) {
				if(G.ew[cur + 2]) {
					gol[i][j] = true;
				} else {
					gol[i][j] = false;
				}
			}
			cur += 2;
			if(i > 1 && j > 1) cur += 2;
		}
	}
	L(i, 1, n) {
		L(j, 1, i) {
			if(s[i][j] != '0') {
				ans[i][j] = 1;
			}
		}
	}
	L(i, 1, n) {
		L(j, 1, i) {
			if(s[i][j] == '0') {
				int x = i, y = j;
				while(y > 0) {
					if(gol[x][y]) {
						if(y > 1) ans[x][y - 1] = 3;
						--y;
					} else {
						int cy = y - 1;
						while(!win[x][cy]) {
//							cout << x << ' ' << y << " : " << x << " and " << cy << endl;
							if(!cy) {
								assert(false);
//								cout << "jinhya\n";
								continue;
							}
							ans[x][cy] = 3, --cy;
						}
						ans[x - 1][y - 1] = 2;
						--x, --y;
					}
				}
			}
		}
	}
	L(i, 1, n) {
		L(j, 1, i) {
			if(s[i][j] == '0') cout << "-";
			else cout << ans[i][j];
		}
		cout << '\n';
	}
}
int main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t; cin >> t; while(t--) Main();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 26112kb

input:

1
4
0
11
010
1101

output:

-
21
-3-
33-1

result:

ok ok

Test #2:

score: -100
Wrong Answer
time: 4ms
memory: 26208kb

input:

909
6
0
11
100
1111
11100
111110
7
0
11
011
1001
10111
100111
1111111
6
0
00
001
1111
11101
111111
8
1
01
111
1111
10111
101110
1101101
11111100
2
1
00
2
0
01
3
0
01
110
7
1
00
011
1010
11011
110111
1111111
8
1
11
111
1011
11010
011110
1101110
01111111
5
1
00
010
1111
10111
6
0
10
011
0101
01111
111...

output:

-
32
3--
3332
333--
33333-
Impossible!
Impossible!
Impossible!
2
--
-
-1
-
-1
33-
Impossible!
2
22
222
2-22
23-2-
-3323-
33-333-
-1111111
Impossible!
Impossible!
Impossible!
Impossible!
2
--
2
--
Impossible!
-
21
--1
-
-1
Impossible!
2
22
2--
-3-1
Impossible!
2
-2
-3-
2111
-2111
3233-1
3--1111
3333-...

result:

wrong answer duplicate tile