QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#107411#6185. Best ProblemzhoukangyangWA 2ms3412kbC++171.7kb2023-05-21 11:21:082023-05-21 11:21:10

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-21 11:21:10]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3412kb
  • [2023-05-21 11:21:08]
  • 提交

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];
void slv(vi a) {
	while(sz(a) && !a[0]) a.erase(a.begin());
	if(!sz(a)) return ;
	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]);
			}
			slv(A), slv(B);
			return ;
		}
	}
	for(auto u : a) 
		cout << u << ' ';
	cout << endl;
}
int main() {
	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];
//	slv(T);
//	L(i, 0, cur) {
//		cout << a[i] << ' ';
//	}
//	cout << endl;
	int ans = 0;
	while(true) {
		int ok = 0;
		R(j, cur - 1, 1) {
			if(a[j - 1] > 0 && a[j] == 1 && a[j + 1] != 1) {
				ok = 1;
				--a[j - 1];
				++a[j + 1];
				break;
			}
		}
		if(!ok) {
			R(j, cur - 1, 1) {
				if(a[j - 1] > 0 && a[j] == 1) {
					ok = 1;
					--a[j - 1];
					++a[j + 1];
					break;
				}
			}	
		}
		if(!ok) break;
		++ans;
	}
	cout << ans << '\n';
	return 0;
}
/*
0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010
*/

详细

Test #1:

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

input:

10100010011001011111

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3412kb

input:

0000010101100110101101010110000110100111000010010111111100101101110101000111101111010101010010101010

output:

55

result:

wrong answer 1st numbers differ - expected: '58', found: '55'