Submission #1051837

# Submission time Handle Problem Language Result Execution time Memory
1051837 2024-08-10T10:07:00 Z awu Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
41 ms 11796 KB
#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 + 1; 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);
  }
  xs.insert(n);
  zs.insert(n);
  if(y.empty()) return;
  int best = 0;
  int val = 1;
  for(int i = 1; i < y.size(); i++) {
    if(*zs.lower_bound(y[i - 1]) < y[i]) {
      val++;
    }
  }
  int bestsc = val;
  for(int i = 1; i < y.size(); i++) {
    if(*zs.lower_bound(y[i - 1]) < y[i]) {
      val--;
    }
    if(*xs.lower_bound(y[i - 1]) < y[i]) {
      val++;
    }
  }
  vector<int> ans(n);
  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;
      ans[j] = 1;
    }
  }
  ans[y[0]] = 1;
  ans[x] = 1;
  ans[z] = 1;
  // debug(ans);
  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:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i = 1; i < y.size(); i++) {
      |                  ~~^~~~~~~~~~
Anna.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i = 1; i < y.size(); i++) {
      |                  ~~^~~~~~~~~~
Anna.cpp:74:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |   for(int i = 1; i < y.size(); i++) {
      |                  ~~^~~~~~~~~~
Anna.cpp:64:7: warning: unused variable 'bestsc' [-Wunused-variable]
   64 |   int bestsc = val;
      |       ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 796 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 0 ms 792 KB Output is correct
4 Correct 0 ms 780 KB Output is correct
5 Incorrect 0 ms 788 KB Wrong Answer [6]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 11796 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -