답안 #1056568

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056568 2024-08-13T10:05:55 Z juicy Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
37 ms 8992 KB
#include "Anna.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
namespace {
  template<class T>
  ostream &operator << (ostream &os, vector<T> v) {
    int D = v.size();
    os << "{";
    for (int i = 0; i < D; ++i) {
      os << (i ? ", " : "") << v[i];
    }
    return os << "}";
  }
 
  void __print() {
    cerr << "]\n";
  }
 
  template<class T, class... V>
  void __print(T t, V... v) {
    cerr << t;
    if (sizeof...(v)) {
      cerr << ", ";
    }
    __print(v...);
  }
 
  #define debug(x...) cerr << "[" << #x << "] = ["; __print(x);
}
 
void Anna(int N, std::vector<char> S) {
  int B = 63, K = 44;
  vector<long long> fib(B);
  fib[0] = 1, fib[1] = 2;
  for (int i = 2; i < B; ++i) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
  auto encode = [&](vector<int> msg) {
    long long res = 0;
    for (int i = B - 1; i >= 0; --i) {
      res += msg[B - i - 1] * fib[i];
    }
    return res;
  };
  int p = 0;
  vector<int> msg;
  while (p < N && S[p] != 'X') {
    ++p;
    msg.push_back(0);
  }
  if (p < N) {
    msg.push_back(1);
    msg.push_back(0);
    ++p;
  }
  for (; p < N; ++p) {
    if (S[p] == 'Z' && (p + 1 == N || S[p + 1] != S[p])) {
      msg.push_back(1);
    } else {
      msg.push_back(0);
    }
  }
  while (msg.size() % B) {
    msg.push_back(0);
  }
  for (int i = 0; i < msg.size(); i += B) {
    auto x = encode(vector(msg.begin() + i, msg.begin() + i + B));
    for (int j = 0; j < K; ++j) {
      Send(x >> j & 1);
    }
  }
}
#include "Bruno.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
namespace {
  void __print() {
    cerr << "]\n";
  }
 
  template<class T, class... V>
  void __print(T t, V... v) {
    cerr << t;
    if (sizeof...(v)) {
      cerr << ", ";
    }
    __print(v...);
  }
 
  #define debug(x...) cerr << "[" << #x << "] = ["; __print(x);
}
 
void Bruno(int N, int L, std::vector<int> A) {
  int B = 63, K = 44;
  vector<long long> fib(B);
  fib[0] = 1, fib[1] = 2;
  for (int i = 2; i < B; ++i) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }
  auto decode = [&](long long x) {
    string msg;
    for (int i = B - 1; i >= 0; --i) {
      if (x >= fib[i]) {
        msg += '1';
        x -= fib[i];
      } else {
        msg += '0';
      }
    }
    return msg;
  };
  string S;
  for (int i = 0; i < L; i += K) {
    long long x = 0;
    for (int j = 0; j < K; ++j) {
      if (A[i + j]) {
        x += 1LL << j;
      }
    }
    S += decode(x);
  } 
  int p = 0;
  while (p < N && S[p] == '0') {
    Remove(p++);
  }
  if (p == N) {
    return;
  }
  int i = p + 2, lst = i;
  for (; i <= N; ++i) {
    if (S[i] == '1') {
      for (int j = i - 1; j >= lst; --j) {
        Remove(j - 1);
      }
      Remove(i - 1);
      lst = i + 1;
    }
  }
  for (i = N; i >= lst; --i) {
    Remove(i - 1);
  }
  Remove(p);
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for (int i = 0; i < msg.size(); i += B) {
      |                   ~~^~~~~~~~~~~~
Anna.cpp: At global scope:
Anna.cpp:18:8: warning: 'void {anonymous}::__print()' defined but not used [-Wunused-function]
   18 |   void __print() {
      |        ^~~~~~~

Bruno.cpp:8:8: warning: 'void {anonymous}::__print()' defined but not used [-Wunused-function]
    8 |   void __print() {
      |        ^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 780 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 780 KB Output is correct
5 Correct 0 ms 796 KB Output is correct
6 Correct 0 ms 796 KB Output is correct
7 Correct 0 ms 796 KB Output is correct
8 Correct 0 ms 796 KB Output is correct
9 Correct 1 ms 796 KB Output is correct
10 Correct 0 ms 796 KB Output is correct
11 Correct 0 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 8312 KB Output is correct
2 Correct 28 ms 8524 KB Output is correct
3 Correct 32 ms 8752 KB Output is correct
4 Correct 35 ms 8760 KB Output is correct
5 Correct 29 ms 8768 KB Output is correct
6 Correct 32 ms 8520 KB Output is correct
7 Correct 27 ms 8548 KB Output is correct
8 Correct 27 ms 8628 KB Output is correct
9 Correct 27 ms 8864 KB Output is correct
10 Correct 27 ms 8628 KB Output is correct
11 Correct 27 ms 8764 KB Output is correct
12 Correct 26 ms 8520 KB Output is correct
13 Correct 35 ms 8736 KB Output is correct
14 Correct 32 ms 8488 KB Output is correct
15 Correct 31 ms 8516 KB Output is correct
16 Correct 31 ms 8556 KB Output is correct
17 Correct 33 ms 8520 KB Output is correct
18 Correct 34 ms 8500 KB Output is correct
19 Correct 33 ms 8832 KB Output is correct
20 Correct 30 ms 8776 KB Output is correct
21 Correct 27 ms 8724 KB Output is correct
22 Correct 33 ms 8724 KB Output is correct
23 Correct 26 ms 8768 KB Output is correct
24 Correct 26 ms 8788 KB Output is correct
25 Correct 37 ms 8772 KB Output is correct
26 Correct 31 ms 8460 KB Output is correct
27 Correct 33 ms 8724 KB Output is correct
28 Correct 31 ms 8776 KB Output is correct
29 Correct 33 ms 8752 KB Output is correct
30 Correct 33 ms 8352 KB Output is correct
31 Correct 32 ms 8796 KB Output is correct
32 Correct 27 ms 8532 KB Output is correct
33 Correct 27 ms 8992 KB Output is correct