답안 #710544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710544 2023-03-15T10:37:28 Z tanprodium Ancient Machine (JOI21_ancient_machine) C++17
30 / 100
72 ms 9716 KB
#include "Anna.h"
#include<bits/stdc++.h>

using namespace std;

int cnt = 0;

/*void Send(int a) {
    ++cnt;
    cout << a << ' ';
}*/

void Anna(int N, vector<char> S) {
    string s = "";

    for (int i = 0; i < N; i++) s += S[i];

    if (N == 1) {
        Send(1);
        return;
    }

    int sz = N;

    int u = 0, v = sz - 1;

    for (int i = 0; i < N; i++)
    if (s[i] == 'X') {
        u = i;
        break;
    }

    for (int i = sz - 1; i >= 0; i--)
    if (s[i] == 'Z') {
        v = i;
        break;
    }

    for (int i = 0; i < u; i++) Send(0);
    Send(1);

    for (int i = u + 1; i < v; i++)
        if (s[i] == 'Z') Send(1);
        else Send(0);
    Send(1);

    for (int i = v + 1; i < sz; i++) Send(0);
}

/*void solve() {
    int n;
    string s;
    vector<char> vs;
    cin >> n >> s;

    for (int i = 0; i < n; i++)
        vs.push_back(s[i]);

    Anna(n, vs);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    solve();
    return 0;
}*/
#include "Bruno.h"
#include<bits/stdc++.h>

using namespace std;

template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (y > x) {
            x = y;
            return (true);
        } else return (false);
    }

const int oo = 1e9;
const int LOG = 17;

/*void Remove(int d) {
    cout << d << ' ';
}*/

// sub1

/*void Bruno(int N, int L, vector<int> A) {
    string s = "";

    for (int i = 0; i < L; i += 2) {
        if (A[i] == 0) {
            if (A[i + 1] == 0)
                s += 'X';
            else s += 'Y';
        } else s += 'Z';
    }

    int sz = N;
    int all = (1 << sz);
    vector<int> dp(all + 5, -oo), rem(all + 5, 0);
    dp[0] = 0;

    for (int mask = 0; mask < all; mask++) {
        vector<int> pos;

        for (int i = 0; i < sz; i++)
            if (!(mask >> i & 1))
                pos.push_back(i);

        int spos = (int)pos.size();

        for (int i = 0; i < spos; i++) {
            bool good = false;
            int cur = pos[i];

            if (i > 0 && i < spos - 1) {
                int pre = pos[i - 1];
                int suf = pos[i + 1];

                if (s[pre] == 'X' && s[cur] == 'Y' && s[suf] == 'Z')
                    good = true;
            }

            int nmask = mask | (1 << cur);

            if (maximize(dp[nmask], dp[mask] + good))
                rem[nmask] = cur;
        }
    }

    vector<int> ans;

    int mask = all - 1;
    while (mask) {
        int bit = rem[mask];
        ans.push_back(bit);
        mask ^= (1 << bit);
    }

    reverse(ans.begin(), ans.end());

    for (int x : ans) Remove(x);
}*/

// sub2

void Remseg(int l, int r) {
    if (l > r) return;
    for (int i = l; i <= r; i++) Remove(i);
}

void Bruno(int N, int L, vector<int> A) {
    int sz = N;

    int u, v;

    for (int i = 0; i < sz; i++)
    if (A[i] == 1) {
        u = i;
        break;
    }

    for (int i = sz - 1; i >= 0; i--)
    if (A[i] == 1) {
        v = i;
        break;
    }

    Remseg(0, u - 1);
    Remseg(v + 1, sz - 1);

    int pre = u;

    for (int i = u + 1; i <= v; i++)
    if (A[i] == 1) {
        for (int j = i - 1; j > pre; j--)
            Remove(j);

        Remove(i);

        pre = i;
    }

    Remove(u);
}

/*void solve() {
    int n;
    int l;
    vector<int> a;

    cin >> n >> l;

    for (int i = 1; i <= l; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }

    Bruno(n, l, a);
}

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0); cout.tie(0);
    solve();
    return 0;
}*/

Compilation message

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:110:14: warning: 'u' may be used uninitialized in this function [-Wmaybe-uninitialized]
  110 |     for (int i = u + 1; i <= v; i++)
      |              ^
Bruno.cpp:110:27: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
  110 |     for (int i = u + 1; i <= v; i++)
      |                         ~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 520 KB Output is correct
3 Correct 1 ms 608 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 516 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 60 ms 8260 KB Partially correct
2 Partially correct 58 ms 8132 KB Partially correct
3 Partially correct 56 ms 8256 KB Partially correct
4 Partially correct 69 ms 8212 KB Partially correct
5 Partially correct 57 ms 8148 KB Partially correct
6 Partially correct 54 ms 8172 KB Partially correct
7 Partially correct 55 ms 8228 KB Partially correct
8 Partially correct 59 ms 8224 KB Partially correct
9 Partially correct 55 ms 8236 KB Partially correct
10 Partially correct 52 ms 8200 KB Partially correct
11 Partially correct 54 ms 8288 KB Partially correct
12 Partially correct 67 ms 8312 KB Partially correct
13 Partially correct 65 ms 8200 KB Partially correct
14 Partially correct 61 ms 8264 KB Partially correct
15 Partially correct 62 ms 8228 KB Partially correct
16 Partially correct 58 ms 8236 KB Partially correct
17 Partially correct 61 ms 8168 KB Partially correct
18 Partially correct 61 ms 8216 KB Partially correct
19 Partially correct 71 ms 8212 KB Partially correct
20 Partially correct 54 ms 8168 KB Partially correct
21 Partially correct 49 ms 8236 KB Partially correct
22 Partially correct 60 ms 8188 KB Partially correct
23 Partially correct 57 ms 8168 KB Partially correct
24 Partially correct 63 ms 8232 KB Partially correct
25 Partially correct 60 ms 8200 KB Partially correct
26 Partially correct 62 ms 8232 KB Partially correct
27 Partially correct 72 ms 9716 KB Partially correct
28 Partially correct 66 ms 8184 KB Partially correct
29 Partially correct 63 ms 8220 KB Partially correct
30 Partially correct 57 ms 8172 KB Partially correct
31 Partially correct 61 ms 8272 KB Partially correct
32 Partially correct 58 ms 8288 KB Partially correct
33 Partially correct 66 ms 8180 KB Partially correct