답안 #1054000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054000 2024-08-12T03:34:08 Z awu Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
37 ms 10080 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 = 0;
  for(int i = 0; i < n; i++) {
    if(s[i] == 'X' && x == -1) x = i;
    if(s[i] == 'Z') z = i;
  }
  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) {
  // 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:64:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   while(j < b.size() - 1) {
      |         ~~^~~~~~~~~~~~~~

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:54:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   for(int j = 0; j < a.size(); j += i) {
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 784 KB Output is correct
2 Correct 0 ms 784 KB Output is correct
3 Correct 0 ms 784 KB Output is correct
4 Correct 0 ms 784 KB Output is correct
5 Correct 0 ms 784 KB Output is correct
6 Correct 0 ms 792 KB Output is correct
7 Correct 0 ms 796 KB Output is correct
8 Incorrect 0 ms 796 KB Wrong Answer [3]
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 9300 KB Output is correct
2 Correct 33 ms 9204 KB Output is correct
3 Correct 33 ms 9416 KB Output is correct
4 Correct 32 ms 9420 KB Output is correct
5 Correct 32 ms 9216 KB Output is correct
6 Correct 33 ms 9100 KB Output is correct
7 Correct 31 ms 9428 KB Output is correct
8 Correct 32 ms 9456 KB Output is correct
9 Correct 33 ms 9120 KB Output is correct
10 Correct 32 ms 9420 KB Output is correct
11 Correct 32 ms 9432 KB Output is correct
12 Correct 33 ms 9284 KB Output is correct
13 Correct 33 ms 9836 KB Output is correct
14 Correct 31 ms 9088 KB Output is correct
15 Correct 32 ms 8808 KB Output is correct
16 Correct 28 ms 10080 KB Output is correct
17 Incorrect 22 ms 7384 KB Wrong Answer [3]
18 Halted 0 ms 0 KB -