#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
// #define int long long
#define ll long long
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) [&](decltype(x) _x) {cerr << #x << " = " << _x << endl; return _x;}(x)
using pii = pair<int, int>;
const ll inf = 1ll << 60;
template <typename T, typename U>
ostream& operator<<(ostream& out, pair<T, U> p) {
return out << "(" << p.f << ", " << p.s << ")";
}
template <typename T, typename = decltype(begin(declval<T>()))>
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& out, T x) {
string dlm = "";
out << "{";
for(auto i : x) {
out << dlm << i;
dlm = ", ";
}
return out << "}";
}
#include "Anna.h"
void Anna(int n, vector<char> s) {
int x = 0;
for(int i = 0; i < n; i++) {
if(s[i] == 'X') {
x = i;
break;
}
}
int z = 0;
for(int i = 0; i < n; i++) {
if(s[i] == 'Z') {
z = i;
}
}
if(x > z) return;
vector<int> y;
set<int> xs, zs;
for(int i = x; i < z; i++) {
if(s[i] == 'X') xs.insert(i);
if(s[i] == 'Z') zs.insert(i);
if(s[i] == 'Y') y.push_back(i);
}
if(y.empty()) return;
int best = 0;
int val = 0;
for(int i = 0; i < y.size() - 1; i++) {
if(*zs.lower_bound(y[i]) < y[i + 1]) {
val++;
}
}
int bestsc = val;
for(int i = 1; i < n; i++) {
if(*zs.lower_bound(y[i - 1]) < y[i]) {
val--;
}
if(*xs.lower_bound(y[i - 1]) < y[i]) {
val++;
}
if(val > bestsc) {
best = i;
bestsc = val;
}
}
vector<int> ans(n);
ans[x] = 1;
ans[z] = 1;
for(int i = 1; i < y.size(); i++) {
auto& s = i <= best ? xs : zs;
int j = *s.lower_bound(y[i - 1]);
if(j < y[i]) {
ans[y[i - 1]] = 1;
ans[j] = 1;
}
}
ans[y.back()] = 1;
for(auto i : ans) {
Send(i);
}
debug(y[best]);
while(y[best]) {
Send(y[best] & 1);
y[best] >>= 1;
}
}
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
// #define int long long
#define ll long long
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) [&](decltype(x) _x) {cerr << #x << " = " << _x << endl; return _x;}(x)
using pii = pair<int, int>;
const ll inf = 1ll << 60;
template <typename T, typename U>
ostream& operator<<(ostream& out, pair<T, U> p) {
return out << "(" << p.f << ", " << p.s << ")";
}
template <typename T, typename = decltype(begin(declval<T>()))>
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& out, T x) {
string dlm = "";
out << "{";
for(auto i : x) {
out << dlm << i;
dlm = ", ";
}
return out << "}";
}
#include "Bruno.h"
void Bruno(int n, int l, vector<int> a) {
debug(a);
if(a.empty()) {
for(int i = 0; i < n; i++) {
Remove(i);
}
return;
}
for(int i = 0; i < n; i++) {
if(!a[i]) Remove(i);
}
int x = 0, z = 0;
for(int i = 0; i < n; i++) {
if(a[i]) {
x = i;
break;
}
}
for(int i = 0; i < n; i++) {
if(a[i]) {
z = i;
}
}
int mid = 0;
for(int i = a.size() - 1; i >= n; i--) {
mid <<= 1;
mid |= a[i];
}
debug(mid);
for(int i = mid; i < z; i++) {
if(a[i]) Remove(i);
}
for(int i = mid - 1; i > x; i--) {
if(a[i]) Remove(i);
}
Remove(x);
Remove(z);
}
Compilation message
Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:57:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int i = 0; i < y.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~
Anna.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int i = 1; i < y.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
788 KB |
Wrong Answer [6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
7384 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |