Submission #1051895

#TimeUsernameProblemLanguageResultExecution timeMemory
1051895awuAncient Machine (JOI21_ancient_machine)C++17
45 / 100
288 ms10016 KiB
#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) {
  char last = ' ';
  vector<int> ans(n);
  int z = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'Z') z = i;
  }
  for(int i = 0; i < z; i++) {
    if(last == ' ' && s[i] == 'X') {
      ans[i] = 2;
      last = 'X';
    } else if(last == 'Y' && s[i] == 'X') {
      ans[i] = 2;
      last = 'X';
    } else if(last == 'Y' && s[i] == 'Z') {
      ans[i] = 3;
      last = 'X';
    } else if(last == 'X' && s[i] == 'Y') {
      ans[i] = 1;
      last = 'Y';
    }
  }
  if(last == ' ') return;
  if(last == 'X') {
    for(int i = z; i >= 0; i--) {
      if(ans[i]) {
        ans[i] = 0;
        break;
      }
    }
  }
  ans[z] = 3;
  for(auto i : ans) {
    if(i >= 2) {
      Send(1);
      Send(i & 1);
    } else {
      Send(i);
    }
  }
}
#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;
  }
  string s;
  int i = 0;
  char last = 'Y';
  while(i < a.size()) {
    if(a[i]) {
      if(last == 'Y') {
        s.push_back(a[i + 1] ? 'Z' : 'X');
        i += 2;
        last = 'X';
      } else {
        s.push_back('Y');
        i++;
        last = 'Y';
      }
    } else {
      s.push_back('.');
      i++;
    }
  }
  int z = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'Z') z = i;
  }
  for(int i = 0; i < n; i++) {
    if(s[i] == '.') Remove(i);
  }
  int prv = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == '.') continue;
    if(s[i] == 'Z' && i != z) {
      Remove(prv);
      Remove(i);
      s[prv] = s[i] = '.';
    }
    prv = i;
  }
  prv = n - 1;
  for(int i = n - 1; i >= 0; i--) {
    if(s[i] == '.') continue;
    if(s[i] == 'X') {
      Remove(prv);
      Remove(i);
      s[prv] = s[i] = '.';
    }
    prv = i;
  }
  Remove(z);
}

Compilation message (stderr)

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:43:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   while(i < a.size()) {
      |         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...