답안 #935596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935596 2024-02-29T09:38:37 Z wii Ancient Machine (JOI21_ancient_machine) C++17
94 / 100
50 ms 8192 KB
#include <vector>
#include <iostream>
using namespace std;
 
typedef long long ll;
 
void Anna(int N, std::vector<char> S);
void Send(int a);
 
void Anna(int N, std::vector<char> S) {
    const int Lim = 11;
    const int LOG = 8;
 
    int cnt[3] = {0};
    for (char x: S) {
        if (x == 'X') ++cnt[0];
        if (x == 'Y') ++cnt[1];
        if (x == 'Z') ++cnt[2];
    }
 
    vector<int> a;
    a.assign(N, 0);
 
    int res = 0;
    for (int i = 0; i < N; ++i)
    if (S[i] == 'X') {
        res = i; break;
    }
 
    for (int i = 1; i <= 17; ++i)
        Send(res >> i - 1 & 1);
 
    for (int i = 0; i < N; ++i) if (i > res)
        a[i] = (S[i] == 'Z');
 
    for (int i = 1; i < N; ++i)
        if (a[i - 1] == 1 && a[i] == 1)
            a[i - 1] = 0;
 
    vector<ll> fibo(65);
    fibo[0] = 1; fibo[1] = 1;
    for (int i = 2; i <= 64; ++i)
        fibo[i] = fibo[i - 1] + fibo[i - 2];
 
    for (int i = 0; i < N; i += Lim) {
        ll hash_num = 0;
        for (int j = i; j < N && j < i + Lim; ++j)
            if (a[j] == 1)
                hash_num += fibo[j - i + 1];
 
        for (int u = 1; u <= LOG; ++u)
            Send(hash_num >> u - 1 & 1);
    }
}
#include <deque>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
typedef long long ll;
 
void Bruno(int N, int L, std::vector<int> A);
void Remove(int d);
 
// 11 XYZXZYXYXYZ
 
void Bruno(int N, int L, std::vector<int> A) {
    const int Lim = 11;
    const int LOG = 8;
 
    int ptr = 0;
 
    int first_x = 0;
    for (int i = 1; i <= 17; ++i) {
        if (A[ptr] == 1)
            first_x += 1LL << i - 1;
        ++ptr;
    }
 
    vector<int> pos_z;
    pos_z.push_back(first_x);
 
    vector<ll> fibo(65);
    fibo[0] = 1; fibo[1] = 1;
    for (int i = 2; i <= 64; ++i)
        fibo[i] = fibo[i - 1] + fibo[i - 2];
 
    int cur = 0;
    for (int i = ptr; i < A.size(); i += LOG) {
        ll hash_num = 0;
        for (int j = 1; j <= LOG && i + j - 1 < A.size(); ++j)
            if (A[i + j - 1] == 1)
                hash_num += 1LL << j - 1;
 
        for (int u = Lim ; u >= 1; --u) if (hash_num >= fibo[u]) {
            pos_z.push_back(cur + u - 1);
            hash_num -= fibo[u];
        } cur += Lim;
    } sort(pos_z.begin(), pos_z.end());
 
    for (int i = 1; i < pos_z.size(); ++i) {
        int l = pos_z[i - 1];
        int r = pos_z[i];
 
        // cout << l << " " << r << "\n";
 
        for (int u = r - 1; u > l; --u)
            Remove(u);
        Remove(r);
    }
 
    for (int i = pos_z.back() + 1; i < N; ++i)
        Remove(i);
 
    for (int i = 0; i <= pos_z[0]; ++i)
        Remove(i);
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:31:23: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   31 |         Send(res >> i - 1 & 1);
      |                     ~~^~~
Anna.cpp:52:32: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   52 |             Send(hash_num >> u - 1 & 1);
      |                              ~~^~~

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:23:33: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   23 |             first_x += 1LL << i - 1;
      |                               ~~^~~
Bruno.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = ptr; i < A.size(); i += LOG) {
      |                       ~~^~~~~~~~~~
Bruno.cpp:38:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for (int j = 1; j <= LOG && i + j - 1 < A.size(); ++j)
      |                                     ~~~~~~~~~~^~~~~~~~~~
Bruno.cpp:40:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   40 |                 hash_num += 1LL << j - 1;
      |                                    ~~^~~
Bruno.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 1; i < pos_z.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 776 KB Output is correct
2 Correct 2 ms 796 KB Output is correct
3 Correct 0 ms 792 KB Output is correct
4 Correct 0 ms 780 KB Output is correct
5 Correct 1 ms 780 KB Output is correct
6 Correct 0 ms 780 KB Output is correct
7 Correct 0 ms 780 KB Output is correct
8 Correct 1 ms 792 KB Output is correct
9 Correct 0 ms 788 KB Output is correct
10 Correct 1 ms 780 KB Output is correct
11 Correct 0 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 38 ms 7972 KB Partially correct
2 Partially correct 38 ms 7944 KB Partially correct
3 Partially correct 38 ms 8104 KB Partially correct
4 Partially correct 40 ms 7908 KB Partially correct
5 Partially correct 39 ms 7904 KB Partially correct
6 Partially correct 38 ms 7908 KB Partially correct
7 Partially correct 38 ms 8136 KB Partially correct
8 Partially correct 38 ms 7920 KB Partially correct
9 Partially correct 41 ms 7872 KB Partially correct
10 Partially correct 38 ms 7884 KB Partially correct
11 Partially correct 37 ms 7836 KB Partially correct
12 Partially correct 38 ms 7904 KB Partially correct
13 Partially correct 43 ms 8040 KB Partially correct
14 Partially correct 43 ms 7824 KB Partially correct
15 Partially correct 41 ms 7908 KB Partially correct
16 Partially correct 42 ms 7852 KB Partially correct
17 Partially correct 42 ms 7856 KB Partially correct
18 Partially correct 42 ms 8064 KB Partially correct
19 Partially correct 43 ms 7976 KB Partially correct
20 Partially correct 44 ms 7928 KB Partially correct
21 Partially correct 39 ms 7896 KB Partially correct
22 Partially correct 44 ms 7976 KB Partially correct
23 Partially correct 38 ms 7892 KB Partially correct
24 Partially correct 38 ms 7964 KB Partially correct
25 Partially correct 43 ms 8024 KB Partially correct
26 Partially correct 50 ms 7812 KB Partially correct
27 Partially correct 42 ms 7952 KB Partially correct
28 Partially correct 44 ms 8192 KB Partially correct
29 Partially correct 48 ms 8056 KB Partially correct
30 Partially correct 43 ms 7960 KB Partially correct
31 Partially correct 43 ms 7912 KB Partially correct
32 Partially correct 38 ms 7892 KB Partially correct
33 Partially correct 43 ms 7908 KB Partially correct