QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108592#6185. Best ProblemzhoukangyangML 2ms5452kbC++171.4kb2023-05-25 17:26:592023-05-25 17:27:01

Judging History

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

  • [2024-04-05 16:19:14]
  • hack成功,自动添加数据
  • (/hack/587)
  • [2024-04-05 16:05:44]
  • hack成功,自动添加数据
  • (/hack/586)
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-25 17:27:01]
  • 评测
  • 测评结果:ML
  • 用时:2ms
  • 内存:5452kb
  • [2023-05-25 17:26:59]
  • 提交

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 ll long long 
#define ull unsigned long long
#define me(a, x) memset(a, x, sizeof(a)) 
#define eb emplace_back
#define uint unsigned int 
using namespace std;
const int N = 1e6 + 7;
char s[N];
int n, a[N];
map < vi, int > MP;
int slv(vi a) {
	while(sz(a) && !a[0]) a.erase(a.begin());
	if(!sz(a)) return 0;
	int n = sz(a) - 1;
	a[n] = 0;
	L(i, 1, n - 1) 
		if(a[i] > 1 && a[i + 1] == 0) {
			vi A, B; 
			L(j, 0, i) {
				A.emplace_back(a[j]);
			}
			L(j, i + 1, n) {
				B.emplace_back(a[j]);
			}
			return slv(A) + slv(B);
		}
	if(MP.count(a)) return MP[a];
	int ans = 0;
	vi b = a;
	R(i, n - 1, 1) 
		if(b[i - 1] > 0 && b[i] == 1) {
			if(b[i - 1] == 1 && i > 1 && b[i - 2] > 1) b[i] = 1e9, ans = slv(b);
			b = a, --b[i - 1], ++b[i + 1];
			ans = max(ans, slv(b) + 1);
			return MP[a] = ans;
		}
	return MP[a] = 0;
}

int main() {
//	freopen("input.txt","r",stdin);
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> (s + 1);
	n = strlen(s + 1);
	int cur = 0;
	L(i, 1, n) {
		if(s[i] == '1') {
			++cur;
		} else {
			a[cur] += 1;
		}
	}
	vi T(cur + 1);
	L(i, 0, cur) T[i] = a[i];
	cout << slv(T) << '\n';
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5452kb

input:

10100010011001011111

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3372kb

input:

0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010

output:

58

result:

ok 1 number(s): "58"

Test #3:

score: -100
Memory Limit Exceeded

input:

100011000011001011010100111110011001000110111101101001100000110101101001101111100101110001101101000001001011011111001100111010101111001110000110001100101100101001001110000111100001100110000101111110001010101100100110010001110011101011110011101111000111010111100110100011110000011111110000111110111110...

output:


result: