답안 #320831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320831 2020-11-10T04:33:58 Z monus1042 게임판 (CEOI13_board) C++17
100 / 100
5 ms 1772 KB
// NK
#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int,int> ii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define psf push_front
#define pof pop_front
#define mkp make_pair
#define mkt make_tuple
#define all(x) x.begin(), x.end()
#define Bolivia_is_nice ios::sync_with_stdio(false), cin.tie(nullptr)

//typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ord_set;

const int MAXS = 1e5 + 10;
deque<int> Abin(MAXS), Bbin(MAXS);

void helper(deque<int> & ops, int pos){
	ops[pos - 1] += ops[pos] / 2;
	if (ops[pos] < 0 && ops[pos]%2 != 0){
		ops[pos - 1]--;
	}
	ops[pos] = abs(ops[pos]) % 2;
}

void traverse(string s, deque<int> & ops){
	int iter;
	ops[0] = iter = 1;
	for (int i=0; i<s.size(); i++){
		if (s[i] == '1'){
			ops[iter] = 0;
			iter++;
		}else if (s[i] == '2'){
			ops[iter] = 1;
			iter++;
		}else if (s[i] == 'L'){
			ops[iter - 1]--;
		}else if (s[i] == 'R'){
			ops[iter - 1]++;
		}else{ // U
			helper(ops, iter - 1);
			iter--;
		}
	}
	for (int i=iter-1; i>=1; i--){
		helper(ops, i);
	}
	while(ops.size() > iter) ops.pob();
	while(ops.front() == 0) ops.pof();
}

void solve(){
	string a,b; cin>>a>>b;
	traverse(a, Abin);
	traverse(b, Bbin);

	if (Abin.size() < Bbin.size()) swap(Abin, Bbin);
	int ans, UB;
	ans = UB = MAXS * 2;
	int diff = Abin.size() - Bbin.size();
	while(Abin.size() > Bbin.size()) Abin.pob();

	int HOR = 0;
    for (int i=0; i<Abin.size(); i++){
		HOR = HOR * 2 + Abin[i] - Bbin[i];
		int current = diff + abs(HOR) + 2 * (int)(Abin.size() - i - 1);
		if (current >= UB) break;
		ans = min(ans, current);
	}
	cout<<ans<<'\n';
}

int main(){
	Bolivia_is_nice;
	int t = 1; //cin>>t;
	while(t--)
	solve();
	
	return 0;
}
/*
  ~/.emacs
*/

Compilation message

board.cpp: In function 'void traverse(std::string, std::deque<int>&)':
board.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i=0; i<s.size(); i++){
      |                ~^~~~~~~~~
board.cpp:60:19: warning: comparison of integer expressions of different signedness: 'std::deque<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |  while(ops.size() > iter) ops.pob();
      |        ~~~~~~~~~~~^~~~~~
board.cpp: In function 'void solve()':
board.cpp:76:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |     for (int i=0; i<Abin.size(); i++){
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1516 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Correct 4 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1260 KB Output is correct
2 Correct 4 ms 1644 KB Output is correct
3 Correct 3 ms 1516 KB Output is correct
4 Correct 2 ms 1280 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1164 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1260 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1260 KB Output is correct
2 Correct 5 ms 1644 KB Output is correct
3 Correct 4 ms 1516 KB Output is correct
4 Correct 2 ms 1152 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1772 KB Output is correct
2 Correct 5 ms 1644 KB Output is correct
3 Correct 2 ms 1260 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1772 KB Output is correct
2 Correct 5 ms 1772 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 5 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1644 KB Output is correct
2 Correct 5 ms 1644 KB Output is correct
3 Correct 4 ms 1644 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1260 KB Output is correct
6 Correct 5 ms 1644 KB Output is correct