QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#597277#9132. Painting Fencesucup-team2432#WA 0ms3864kbC++202.3kb2024-09-28 17:27:182024-09-28 17:27:21

Judging History

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

  • [2024-09-28 17:27:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3864kb
  • [2024-09-28 17:27:18]
  • 提交

answer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(),vec.end()
#define umap __gnu_pbds::gp_hash_table
#define vi vector<int>
#define eb emplace_back
using ll = long long;
using db = double;
using i128 = __int128;
#define Emu Smile
using namespace std;

void chmax(auto &a, auto b) { if (a < b) a = b; }
void chmin(auto &a, auto b) { if (a > b) a = b; }
inline int lbt(int x) { return x & (-x); }

const ll inf = 1e16;

void solve() {
	int n,m; cin >> n >> m;
	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	vector<int> c(m);
	auto build = [&](const vector<int> &nd) {
		const int n = sz(nd);
		//	std::sort(all(nd)); 	若k值递增则不需要排序
		std::vector<std::pair<int,int>> ret(n, std::pair(-1, -1));
		std::vector<int> stack;
		for (int i = 0; i < n; ++i) {
			int lst = -1;
			while (!stack.empty()) {
				if (nd[stack.back()] > nd[i]) {
					lst = stack.back();
					stack.pop_back();
				} else {
					ret[stack.back()].second = i;
					break;
				}
			}
			ret[i].first = lst;
			stack.emplace_back(i);
		}
		return pair(stack[0] , ret);
	};
	auto get = [&](auto &&self,int l,int r,int x) -> int {
		if (l > r) {
			swap(l,r);
		}
		if (l+x <= r) {
			return self(self,l,r-x,x*2)+1;
		}
		else {
			if (!l) {
				if (!r) {
					return 0;
				}
				return 1;
			}
			int k = max(l-x,0);
			return self(self,k,r,x+l-k)+1;
		}
	};
	ll ret = inf;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			if (s[i][j] == '1') {
				c[j] ++;
			} else {
				c[j] = 0;
			}
		}
		auto [rt, eg] = build(c);
		auto dfs = [&](auto &self,int l,int r,int u) -> void {
			if (c[u] && (r - l)) {
				ll t = get(get,i+1-c[u],n-1-i,c[u]) + get(get,l,m-r,r-l);
				chmin(ret, t);
			}
			auto [x,y] = eg[u];
			if (x != -1) {
				self(self,l,u,x);
			}
			if (y != -1) {
				self(self,u+1,r,y);
			}
		};
		dfs(dfs,0,m,rt);
	}
	cout << ret << '\n';
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);

//	init();

	cout << fixed << setprecision(10);

	int OuO = 1;
//	cin >> OuO;
	for (int piastic = 0; piastic < OuO; ++piastic) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4
1001
0100
0110
0110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3816kb

input:

3 3
000
111
111

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4 3
011
011
001
110

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

4 4
0011
1111
1111
1111

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

4 4
0000
0010
0100
1000

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

2 5
00010
00111

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

5 5
11111
11111
11111
01111
11111

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

5 5
00101
00000
00001
00000
00100

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 0ms
memory: 3852kb

input:

5 5
00000
00000
00001
10000
00000

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

10 10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

10 10
0001000000
0000000000
0000000000
0000000001
0000000001
0000000001
0000000000
0000000000
0000000000
0000000001

output:

6

result:

ok 1 number(s): "6"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3788kb

input:

10 10
1111111110
1111111110
1111111110
1111111110
1111111110
1111100110
1111100010
1111101110
1111101100
1111100000

output:

1

result:

ok 1 number(s): "1"

Test #13:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

10 10
0000000000
0000001000
0000000000
0000000000
0000000000
0100000000
0000000000
0000000100
0000000000
0000000000

output:

8

result:

ok 1 number(s): "8"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

30 31
0000000000000000000000000000000
0000000000000000000000000000000
1111111111111110000000000000011
1111111111111110000000000000011
1111111111111110000000000000011
1111111111111111111111111111111
1111111111111111111111111111111
1111111111111111111111111111100
1111111111111111111111111111100
111111...

output:

3

result:

ok 1 number(s): "3"

Test #15:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

30 31
0000000000000000000000000000000
0000000000000000000000000000000
0000000001000000000000000000000
0000000000000000000000100000000
0000000000000000000100000000000
0000000000000000001000000000000
0000000000000010000000000000000
0000000000000000000000000000000
0000000000000000000000000100110
000000...

output:

10

result:

ok 1 number(s): "10"

Test #16:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

30 31
0000000000000000000000000000000
0000000011111111111111000000000
0000000011111111111111000000000
1111111111111111111111000000000
1111111111111111111111000000000
1111111111111111111111000000000
1111111111111111111111000111100
1111111111111111111111000111100
1111111111111111111111000111100
111111...

output:

3

result:

ok 1 number(s): "3"

Test #17:

score: -100
Wrong Answer
time: 0ms
memory: 3864kb

input:

30 31
0000001010000000000000000000000
0000000000000000000000000000000
0000000000000000001000000000000
0000010000000000000000000000000
0000000000000000000000000000000
0000000000000000000000000000000
0000001000010000000000000000000
0000100000010010000000000000000
0000000001000001000000010000000
000000...

output:

10

result:

wrong answer 1st numbers differ - expected: '9', found: '10'