답안 #479910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479910 2021-10-13T21:58:38 Z hidden1 게임판 (CEOI13_board) C++14
80 / 100
101 ms 636 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) { out << x.first << " " << x.second; return out;}
template<class T, class T2> inline istream &operator >>(istream &in, pair<T, T2> &x) { in >> x.first >> x.second; return in;}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
#define debug(...) cout << "Line: " << __LINE__ << endl; \
    printDebug(", "#__VA_ARGS__, __VA_ARGS__)
template <typename T>
void printDebug(const char* name, T&& arg1) { cout << (name + 2) << " = " << arg1 << endl; }
template <typename T, typename... T2>
void printDebug(const char* names, T&& arg1, T2&&... args) {
    const char* end = strchr(names + 1, ',');
    cout.write(names + 2, end - names - 2) << " = " << arg1 << endl;
    printDebug(end, args...);
}

const ll MAX_N = 2e5 + 10;;
//const ll MAX_N = 60;
const ll WORD_SIZE = 60; 
const ll WORD_COUNT = MAX_N / WORD_SIZE + 1;

struct myBitset {
    ll nmb[WORD_COUNT];

    myBitset() {
        for(int i = 0; i < WORD_COUNT; i ++) {
            nmb[i] = 0;
        }
    }

    void add(int pos) {
        ll word = pos / WORD_SIZE;
        nmb[word] += 1ll << (WORD_SIZE - 1ll - (pos % WORD_SIZE));

        int carry = 0;

        do {
            nmb[word] += carry;
            if(nmb[word] >= (1ll << WORD_SIZE)) {
                nmb[word] -= (1ll << WORD_SIZE);
                carry = 1;
            }
            word --;
        } while(word >= 0 && carry);
    }

    void sub(int pos) {
        ll word = pos / WORD_SIZE;
        nmb[word] -= 1ll << (WORD_SIZE - 1ll - (pos % WORD_SIZE));

        int carry = 0;

        do {
            nmb[word] -= carry;
            if(nmb[word] < 0) {
                nmb[word] += (1ll << WORD_SIZE);
                carry = 1;
            }
            word --;
        } while(word >= 0 && carry);
    }

    void unset(int pos) {
        ll word = pos / WORD_SIZE;
        nmb[word] &= ~(1ll << (WORD_SIZE - 1ll - (pos % WORD_SIZE)));
    }

    bool get(int pos) {
        ll word = pos / WORD_SIZE;
        return nmb[word] & (1ll << (WORD_SIZE - 1ll - (pos % WORD_SIZE)));
    }

    void print() {
        for(int i = 0; i < MAX_N; i ++) {
            cout << get(i);
        }
        cout << endl;
    }
};

void swap(myBitset &a, myBitset &b) {
    for(int i = 0; i < WORD_COUNT; i ++) {
        swap(a.nmb[i], b.nmb[i]);
    }
}

myBitset sum[2];

signed main() {
    // ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string a, b;
    cin >> a >> b;
    sum[0].add(0);
    sum[1].add(0);
    ll levela = 0;
    for(auto it : a) {
        if(it == '1') {
            levela ++;
        } else if(it == '2') {
            levela ++;
            sum[0].add(levela);
        } else if(it == 'L') {
            sum[0].sub(levela);
        } else if(it == 'R') {
            sum[0].add(levela);
        } else if(it == 'U') {
            sum[0].unset(levela);
            levela --;
        }
    }
    ll levelb = 0;
    for(auto it : b) {
        if(it == '1') {
            levelb ++;
        } else if(it == '2') {
            levelb ++;
            sum[1].add(levelb);
        } else if(it == 'L') {
            sum[1].sub(levelb);
        } else if(it == 'R') {
            sum[1].add(levelb);                
        } else if(it == 'U') {
            sum[1].unset(levelb);
            levelb --;
        }
    }

    for(ll i = 0; i < MAX_N; i ++) {
        if(sum[0].get(i) != sum[1].get(i)) {
            if(sum[0].get(i)) {
                swap(sum[0], sum[1]);
            }
            break;
        }
    }

    ll dp = 0;
    ll best = 4 * MAX_N;

    for(ll i = 0; i <= min(levela, levelb); i ++) {
        dp = (dp * 2ll);
        if(sum[0].get(i) != sum[1].get(i)) {
            if(sum[0].get(i)) {
                dp --;
            } else {
                dp ++;
            }
        }
        if(dp > 2 * best) {
            break;            
        }
        chkmin(best, dp + levela + levelb - 2 * i);
    }

    cout << best << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 592 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 5 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 7 ms 588 KB Output is correct
3 Correct 4 ms 560 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 7 ms 588 KB Output is correct
3 Incorrect 4 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 588 KB Output is correct
2 Correct 47 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 588 KB Output is correct
2 Correct 45 ms 588 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 101 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 628 KB Output is correct
2 Correct 46 ms 588 KB Output is correct
3 Incorrect 23 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -