답안 #384270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384270 2021-04-01T04:52:42 Z ijxjdjd 게임판 (CEOI13_board) C++17
70 / 100
200 ms 1260 KB
#include <bits/stdc++.h>
#define FR(i, N) for (int i = 0; i < int(N); i++)
#define all(x) begin(x), end(x)

using namespace std;

using ll = long long;

vector<int> parse(string s) {
    vector<int> res;
    res.push_back(1);
    for (char c : s) {
        if (c == '1') {
            res.push_back(0);
        }
        else if (c == '2') {
            res.push_back(1);
        }
        else if (c == 'U') {
            res.pop_back();
        }
        else if (c == 'L') {
            for (int j = res.size()-1; j >= 0; j--) {
                if (res[j] != 0) {
                    res[j] = 0;
                    for (int k = j+1; k < res.size(); k++) {
                        res[k] = 1;
                    }
                    break;
                }
            }
        }
        else if (c == 'R') {
            for (int j = res.size()-1; j >= 0; j--) {
                if (res[j] == 0) {
                    res[j] = 1;
                    for (int k = j+1; k < res.size(); k++) {
                        res[k] = 0;
                    }
                    break;
                }
            }
        }
    }
    return res;
}
int main() {
	cin.tie(0);
	cin.sync_with_stdio(0);
	string A;
	string B;
	cin >> A >> B;
	vector<int> sA = parse(A);
	vector<int> sB = parse(B);
	if (sA.size() < sB.size()) {
        swap(sA, sB);
	}
	int d = 0;
	while (sA.size() > sB.size()) {
        sA.pop_back();
        d++;
	}
	if (sA > sB) {
        swap(sA, sB);
	}
	int res = (int)(1e9);
	int diff = 0;
	for (int k = 0; k < sA.size(); k++) {
        diff *= 2;
        diff += sB[k]-sA[k];
        if (diff >= 100) {
            break;
        }
        res = min((int(sA.size())-k-1)*2+d+diff, res);
	}

	cout << res << '\n';
	return 0;
}

Compilation message

board.cpp: In function 'std::vector<int> parse(std::string)':
board.cpp:26:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |                     for (int k = j+1; k < res.size(); k++) {
      |                                       ~~^~~~~~~~~~~~
board.cpp:37:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                     for (int k = j+1; k < res.size(); k++) {
      |                                       ~~^~~~~~~~~~~~
board.cpp: In function 'int main()':
board.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int k = 0; k < sA.size(); k++) {
      |                  ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 5 ms 748 KB Output is correct
3 Correct 3 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 492 KB Output is correct
2 Correct 4 ms 876 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 1060 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1098 ms 1132 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 1260 KB Time limit exceeded
2 Halted 0 ms 0 KB -