# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
659956 | RambaXGorilla | Board (CEOI13_board) | C++17 | 15 ms | 736 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
string pos[2] = {"0", "0"};
string sub[2] = {"0", "0"};
void inc(string &a){
for(int i = a.size() - 1;i > -1;i--){
if(a[i] - '0'){
a[i] = '0';
}
else{
a[i] = '1';
break;
}
}
}
int main(){
for(int i = 0;i < 2;i++){
while(true){
char a;
scanf("%c",&a);
if(a == '1'){
pos[i].push_back('0');
sub[i].push_back('0');
}
else if (a == '2'){
pos[i].push_back('1');
sub[i].push_back('0');
}
else if (a == 'U'){
bool check = false;
if(pos[i].back() < sub[i].back()){
check = true;
}
pos[i].pop_back();
sub[i].pop_back();
if(check){
inc(sub[i]);
}
}
else if(a == 'L'){
inc(sub[i]);
}
else if(a == 'R'){
inc(pos[i]);
}
else{
break;
}
}
}
for(int i = 0;i < 2;i++){
bool borr = false;
for(int j = pos[i].size() - 1;j > -1;j--){
if(pos[i][j] > sub[i][j]){
pos[i][j] -= borr;
borr = false;
}
else if(pos[i][j] < sub[i][j]){
pos[i][j] += 1 - borr;
borr = true;
}
else{
pos[i][j] = borr + '0';
}
}
}
sort(pos, pos + 2);
int len = min(pos[0].size(), pos[1].size());
int last = len;
int add = 0;
for(int i = 0;i < len;i++){
if(pos[0][i] < pos[1][i]){
last = i + 1;
add = 1;
break;
}
}
for(int i = last;i < len;i++){
last = i + 1;
if(pos[0][i] == pos[1][i]){
add = 2;
if(last < len && pos[0][last] > pos[1][last]){
last++;
add = 3;
}
break;
}
else if(pos[0][i] < pos[1][i]){
add = 3;
break;
}
}
printf("%d",pos[0].size() + pos[1].size() - last * 2 + add);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |