답안 #144245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144245 2019-08-16T11:37:51 Z Milki 게임판 (CEOI13_board) C++14
100 / 100
5 ms 1204 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

vector <int> a, b;
string sa, sb;

const int off = 1 << 17;

void update(string &s, vector <int> &v){
  for(auto it : s){
    if(it == '1')
      v.pb(0);
    else if(it == '2')
      v.pb(1);
    else if(it == 'L')
      v.back() --;
    else if(it == 'R')
      v.back() ++;
    else{
      int x = v.back();
      v.pop_back();

      if(x >= 0){
        v.back() += x / 2;
      }
      else{
        v.back() += x / 2;
        x -= x / 2 * 2;
        if(x < 0){
          v.back() --;
        }
      }
    }
  }
}

void prop(vector <int> &v){
  for(int i = sz(v) - 1; i > 0; --i){
    int x = v[i];
    if(x >= 0){
      v[i - 1] += v[i] / 2;
      v[i] %= 2;
    }
    else{
      v[i - 1] += v[i] / 2;
      v[i] -= v[i] / 2 * 2;
      if(v[i] < 0){
        v[i - 1] --;
        v[i] += 2;
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);

  cin >> sa >> sb;
  update(sa, a);
  update(sb, b);
  prop(a); prop(b);

  ll tmp = sz(a) + sz(b), dist = 0;
  ll sol = tmp;

  REP(i, min(sz(a), sz(b))){
    dist <<= 1;
    dist += a[i] - b[i];

    tmp -= 2;
    sol = min(sol, tmp + abs(dist));

    if(dist > 1e13)
      break;
  }
  cout << sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 252 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1140 KB Output is correct
2 Correct 4 ms 1140 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1140 KB Output is correct
2 Correct 4 ms 1204 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 4 ms 1204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1140 KB Output is correct
2 Correct 4 ms 1204 KB Output is correct
3 Correct 4 ms 1140 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 4 ms 1204 KB Output is correct