Submission #52817

# Submission time Handle Problem Language Result Execution time Memory
52817 2018-06-27T01:07:24 Z updown1 Board (CEOI13_board) C++17
50 / 100
5 ms 1660 KB
/*
structure looks like:
  _
 / \
/   \
and answer can't be more than slightly more than 200,000 (I'm using 300,000). Calculate from top to bottom
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, at1)
#define ffj For(j, 0, at2)
#define ffa ffi ffj
#define s <<" "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
#define int ll
const int MAXN=100001, INF=1000000000000000000;
///500,000,000
string str1, str2;
int loc1[MAXN], loc2[MAXN], at1, at2, curr, out = INF, rig;

void fix1(int i) {
    if (loc1[i] > 1) {
        loc1[i-1] += loc1[i]/2;
        loc1[i] %= 2;
    }
    if (loc1[i] < 0) {
        loc1[i-1] += (loc1[i]-1)/2;
        loc1[i] = (loc1[i]+INF)%2;
    }
}
void fix2(int i) {
    if (loc2[i] > 1) {
        loc2[i-1] += loc2[i]/2;
        loc2[i] %= 2;
    }
    if (loc2[i] < 0) {
        loc2[i-1] += (loc2[i]-1)/2;
        loc2[i] = (loc2[i]+INF)%2;
    }
}

main() {
    //ifstream cin("test.in");
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> str1 >> str2;
    loc1[0] = loc2[0] = 1;
    for (char i: str1) {
        if (i == '1') {at1++; loc1[at1] = 0;}
        if (i == '2') {at1++; loc1[at1] = 1;}
        if (i == 'L') {loc1[at1]--;}
        if (i == 'R') {loc1[at1]++;}
        if (i == 'U') {fix1(at1); at1--;}
    }
    for (int i=at1; i>=1; i--) fix1(i);
    assert(loc1[0] == 1);
    at1++;
    //ffi w<< loc1[i]; w<<e;
    for (char i: str2) {
        if (i == '1') {at2++; loc2[at2] = 0;}
        if (i == '2') {at2++; loc2[at2] = 1;}
        if (i == 'L') {loc2[at2]--;}
        if (i == 'R') {loc2[at2]++;}
        if (i == 'U') {fix2(at2); at2--;}
    }
    for (int i=at2; i>=1; i--) fix2(i);
    assert(loc1[0] == 1);
    at2++;
    //ffj w<< loc2[j]; w<<e;
    For (i, 0, min(at1, at2)) {
        if (rig == 0 && loc1[i] != loc2[i]) {
            if (loc1[i] < loc2[i]) rig = 2;
            else rig = 1;
        }
        curr *= 2;
        if (rig == 1) curr += loc1[i] - loc2[i];
        if (rig == 2) curr += loc2[i] - loc1[i];
        out = min(out, curr + at1 - i - 1 + at2 - i - 1);
        if (curr > 300,000) break;
    }
    w<< out<<e;
}

Compilation message

board.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
board.cpp: In function 'int main()':
board.cpp:85:18: warning: left operand of comma operator has no effect [-Wunused-value]
         if (curr > 300,000) break;
             ~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 452 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 692 KB Output is correct
2 Correct 2 ms 692 KB Output is correct
3 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 5 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 2 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 868 KB Output is correct
2 Correct 2 ms 868 KB Output is correct
3 Correct 2 ms 868 KB Output is correct
4 Correct 2 ms 868 KB Output is correct
5 Correct 2 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 1660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1660 KB Output isn't correct
2 Halted 0 ms 0 KB -