답안 #935643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935643 2024-02-29T10:10:33 Z Boycl07 Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
46 ms 8884 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define FORD(i, n) for(int i = n - 1; i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "skycrapers"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

void Anna(int N, std::vector<char> S);

void Send(int a);

const int Lim = 83;
const int LOG = 57;
ll f[Lim];

void precalc()
{
    f[0] = 1;
    f[1] = 2;
    for(int i = 2; i < Lim; ++i)
        f[i] = f[i - 1] + f[i - 2];
}

void Send_num(ll x)
{
    for(int i = 0; i <= LOG; ++i)
        if(x >> i & 1) Send(1);
    else Send(0);
}


void Anna(int n, vector<char> S)
{

    precalc();
    vector<int> res;
    int idx = 0;
    while(idx < n && S[idx] != 'X') res.pb(0), ++idx;
    int pos = 0;
    if(idx != n)
    {
        pos = idx;
        res.pb(0), ++idx;

    }
    int flag = 0;
    while(idx < n)
    {
        if(S[idx] != 'Z') res.pb(0), ++idx;
        else
        {

            int j = idx;
            while(j < n && S[j] == 'Z') ++j;
            --j;
            forn(k, idx, j - 1) res.pb(0);
            res.pb(1);
            idx = j + 1;
        }
    }
    //for(int x : res) cout << x; cout << endl;
    for(int i = 0; i < n; i += Lim)
    {

        ll cur = 0;
        forn(j, i, i + Lim)
            if(j < n) if(res[j]) cur += f[j - i];
        Send_num(cur);
    }
    //cout << "FIRST_X: " << pos << endl;

    for(int i = 0; i <= 16; ++i) if(pos >> i & 1) Send(1);
    else Send(0);



}



#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define FORD(i, n) for(int i = n - 1; i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "skycrapers"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)


void Bruno(int N, int L, std::vector<int> A);

void Remove(int d);

const int Lim_ = 83;
ll f_[Lim_];

void precalc_()
{
    f_[0] = 1;
    f_[1] = 2;
    for(int i = 2; i < Lim_; ++i)
        f_[i] = f_[i - 1] + f_[i - 2];
}



void decode(vector<int> &A)
{
    vector<int> res;
    int j = 0, pos = 0;
    for(int i = 0; i < sz(A); i += 58)
    {
        if(i + 57 < sz(A))
        {
            ll cur = 0;
            forn(j, 0, 57)
                if(A[i + j] == 1)
                    cur |= 1ll << j;
            vector<int> tmp;
            ford(j, 82, 0)
                if(cur >= f_[j]) tmp.pb(1), cur -= f_[j];
                else tmp.pb(0);
            reverse(all(tmp));
            for(int x : tmp) res.pb(x);
        }
        else
        {
            forn(j, 0, 16)
                if(A[i + j] == 1)
                    pos |= 1 << j;
        }
    }


    A = move(res);
    A[pos] = 1;
}

void Bruno(int n, int Len, vector<int> A)
{
    precalc_();

    int pos = 0;
    decode(A); while(sz(A) > n) A.pop_back();
    int first = 0;
    while(first < n && A[first] != 1)
        Remove(first++);
    if(first == n) return;
    for(int i = first + 1; i < n; ++i)
    {
        int j = i;
        while(j < n && A[j] != 1) ++j;
        ford(k, j - 1, i) Remove(k);
        if(j != n) Remove(j);
        i = j;
    }

    Remove(first);
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:61:9: warning: unused variable 'flag' [-Wunused-variable]
   61 |     int flag = 0;
      |         ^~~~

Bruno.cpp: In function 'void decode(std::vector<int>&)':
Bruno.cpp:45:9: warning: unused variable 'j' [-Wunused-variable]
   45 |     int j = 0, pos = 0;
      |         ^
Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:78:9: warning: unused variable 'pos' [-Wunused-variable]
   78 |     int pos = 0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 788 KB Output is correct
2 Correct 0 ms 780 KB Output is correct
3 Correct 1 ms 780 KB Output is correct
4 Correct 1 ms 940 KB Output is correct
5 Correct 1 ms 788 KB Output is correct
6 Correct 0 ms 776 KB Output is correct
7 Correct 0 ms 780 KB Output is correct
8 Correct 0 ms 780 KB Output is correct
9 Correct 0 ms 776 KB Output is correct
10 Correct 0 ms 788 KB Output is correct
11 Correct 1 ms 780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 8176 KB Output is correct
2 Correct 46 ms 8056 KB Output is correct
3 Correct 38 ms 8188 KB Output is correct
4 Correct 38 ms 8600 KB Output is correct
5 Correct 37 ms 8100 KB Output is correct
6 Correct 39 ms 8148 KB Output is correct
7 Correct 37 ms 8096 KB Output is correct
8 Correct 42 ms 8260 KB Output is correct
9 Correct 38 ms 8184 KB Output is correct
10 Correct 37 ms 7988 KB Output is correct
11 Correct 38 ms 8060 KB Output is correct
12 Correct 39 ms 8216 KB Output is correct
13 Correct 44 ms 8196 KB Output is correct
14 Correct 42 ms 8088 KB Output is correct
15 Correct 39 ms 8112 KB Output is correct
16 Correct 38 ms 8088 KB Output is correct
17 Correct 42 ms 8192 KB Output is correct
18 Correct 43 ms 8884 KB Output is correct
19 Correct 42 ms 8100 KB Output is correct
20 Correct 37 ms 8128 KB Output is correct
21 Correct 40 ms 8108 KB Output is correct
22 Correct 41 ms 8120 KB Output is correct
23 Correct 41 ms 8200 KB Output is correct
24 Correct 40 ms 8084 KB Output is correct
25 Correct 44 ms 8100 KB Output is correct
26 Correct 42 ms 8112 KB Output is correct
27 Correct 42 ms 8108 KB Output is correct
28 Correct 44 ms 8348 KB Output is correct
29 Correct 41 ms 8212 KB Output is correct
30 Correct 46 ms 8112 KB Output is correct
31 Correct 42 ms 8212 KB Output is correct
32 Correct 38 ms 8188 KB Output is correct
33 Correct 37 ms 8184 KB Output is correct