Submission #1054001

# Submission time Handle Problem Language Result Execution time Memory
1054001 2024-08-12T03:36:57 Z awu Ancient Machine (JOI21_ancient_machine) C++17
97 / 100
41 ms 9500 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

// #define int long long
#define ll long long
// #define double long double
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(...) [&](decltype(__VA_ARGS__) _x){cerr << #__VA_ARGS__ << " = " << _x << endl; return _x;}(__VA_ARGS__)
using pii = pair<int, int>;
const ll inf = 1ll << 60;
// const int inf = 1 << 30;
const int MOD = 1e9 + 7;

template <typename T, typename U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  out << "(" << p.f << ", " << p.s << ")";
  return out;
}
template <typename T, typename = decltype(begin(declval<T>()))>
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& out, const T& a) {
  string dlm = "";
  out << "{";
  for(auto& i : a) {
    out << dlm << i;
    dlm = ", ";
  }
  return out << "}";
}
void my_assert(bool b) {
  if(!b) {
    cerr << "Assertion failed" << endl;
    *((volatile int*)0);
  }
}
#undef assert
#define assert my_assert

const int X = 2;

#include "Anna.h"
void Anna(int n, vector<char> s) {
  vector<int> b;
  b.push_back(1);
  int x = -1, z = -1;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'X' && x == -1) x = i;
    if(s[i] == 'Z') z = i;
  }
  if(x == -1 || z == -1 || x > z) return;
  for(int i = 0; i < n; i++) {
    if(i < x || i > z) b.push_back(0);
    else if(i == x || i == z) b.push_back(1);
    else if(i < n - 1 && s[i] == 'Y' && s[i + 1] == 'X') {
      b.push_back(1);
      i++;
    } else b.push_back(0);
  }
  while(b.back() == 0) b.pop_back();
  // debug(b);
  int j = 0;
  vector<int> c;
  while(j < b.size() - 1) {
    int cnt = -1;
    do {
      cnt++;
      j++;
    } while(b[j] != 1);
    c.push_back(cnt);
  }
  // debug(c);
  vector<int> best;
  for(int i = 1; i <= 1 << X; i++) {
    vector<int> a;
    for(int j = 0; j < X; j++) {
      a.push_back(((i - 1) >> j) & 1);
    }
    int m = (1 << i) - 1;
    auto append = [&](int v) {
      for(int j = 0; j < i; j++) {
        a.push_back((v >> j) & 1);
      }
    };
    for(auto j : c) {
      append(j % m);
      for(int k = 0; k < j / m; k++) {
        append(m);
      }
    }
    if(best.empty() || a.size() < best.size()) best = a;
  }
  for(auto i : best) {
    Send(i);
  }
}
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

// #define int long long
#define ll long long
// #define double long double
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(...) [&](decltype(__VA_ARGS__) _x){cerr << #__VA_ARGS__ << " = " << _x << endl; return _x;}(__VA_ARGS__)
using pii = pair<int, int>;
const ll inf = 1ll << 60;
// const int inf = 1 << 30;
const int MOD = 1e9 + 7;

template <typename T, typename U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  out << "(" << p.f << ", " << p.s << ")";
  return out;
}
template <typename T, typename = decltype(begin(declval<T>()))>
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& out, const T& a) {
  string dlm = "";
  out << "{";
  for(auto& i : a) {
    out << dlm << i;
    dlm = ", ";
  }
  return out << "}";
}
void my_assert(bool b) {
  if(!b) {
    cerr << "Assertion failed" << endl;
    *((volatile int*)0);
  }
}
#undef assert
#define assert my_assert

const int X = 2;

#include "Bruno.h"
void Bruno(int n, int l, vector<int> a) {
  if(l == 0) {
    for(int i = 0; i < n; i++) {
      Remove(i);
    }
    return;
  }
  // debug(a);
  int i = 0;
  for(int j = 0; j < X; j++) {
    i |= a[j] << j;
  }
  i++;
  int m = (1 << i) - 1;
  a = vector<int>(a.begin() + 2, a.end());
  vector<int> b;
  for(int j = 0; j < a.size(); j += i) {
    int v = 0;
    for(int k = 0; k < i; k++) {
      v |= a[j + k] << k;
    }
    if(v != m) {
      b.push_back(1);
    }
    for(int k = 0; k < v; k++) {
      b.push_back(0);
    }
  }
  vector<int> r;
  int oc = 0;
  int x = -1, z = -1;
  for(auto j : b) {
    if(j == 1) {
      if(oc == 1) {
        x = r.size();
        r.push_back(1);
      } else if(oc >= 2) {
        r.push_back(1);
        r.push_back(1);
      }
      oc++;
    } else {
      r.push_back(0);
    }
  }
  // debug(r);
  z = r.size();
  r.push_back(1);
  r.resize(n, 0);
  // debug(r);
  for(int i = 0; i < n; i++) {
    if(r[i] == 0) Remove(i);
  }
  for(int i = n - 1; i >= 0; i--) {
    if(i == x || i == z) continue;
    if(r[i] == 1) Remove(i);
  }
  // debug(x);
  // debug(z);
  Remove(x);
  Remove(z);
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:65:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   while(j < b.size() - 1) {
      |         ~~^~~~~~~~~~~~~~

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int j = 0; j < a.size(); j += i) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 792 KB Output is correct
2 Correct 0 ms 792 KB Output is correct
3 Correct 0 ms 788 KB Output is correct
4 Correct 0 ms 784 KB Output is correct
5 Correct 0 ms 792 KB Output is correct
6 Correct 0 ms 792 KB Output is correct
7 Correct 0 ms 792 KB Output is correct
8 Correct 1 ms 792 KB Output is correct
9 Correct 0 ms 796 KB Output is correct
10 Correct 0 ms 792 KB Output is correct
11 Correct 0 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 8996 KB Output is correct
2 Correct 34 ms 8972 KB Output is correct
3 Correct 33 ms 8672 KB Output is correct
4 Correct 32 ms 8928 KB Output is correct
5 Correct 33 ms 8984 KB Output is correct
6 Correct 34 ms 8988 KB Output is correct
7 Correct 33 ms 8712 KB Output is correct
8 Correct 32 ms 9004 KB Output is correct
9 Correct 33 ms 8988 KB Output is correct
10 Correct 33 ms 8896 KB Output is correct
11 Correct 32 ms 8744 KB Output is correct
12 Correct 32 ms 8988 KB Output is correct
13 Correct 32 ms 9364 KB Output is correct
14 Correct 31 ms 8468 KB Output is correct
15 Correct 33 ms 8444 KB Output is correct
16 Correct 28 ms 9500 KB Output is correct
17 Correct 24 ms 6752 KB Output is correct
18 Correct 27 ms 6988 KB Output is correct
19 Correct 27 ms 6808 KB Output is correct
20 Partially correct 41 ms 9280 KB Partially correct
21 Partially correct 32 ms 9412 KB Partially correct
22 Correct 31 ms 8924 KB Output is correct
23 Correct 34 ms 9212 KB Output is correct
24 Correct 32 ms 9152 KB Output is correct
25 Correct 26 ms 6996 KB Output is correct
26 Correct 26 ms 6792 KB Output is correct
27 Correct 24 ms 6876 KB Output is correct
28 Correct 26 ms 6852 KB Output is correct
29 Correct 24 ms 6892 KB Output is correct
30 Correct 26 ms 6908 KB Output is correct
31 Correct 26 ms 6984 KB Output is correct
32 Correct 36 ms 9160 KB Output is correct
33 Correct 38 ms 9376 KB Output is correct