답안 #126896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126896 2019-07-08T15:01:49 Z eriksuenderhauf 게임판 (CEOI13_board) C++11
100 / 100
108 ms 760 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e5 + 5;
const double eps = 1e-9;
ll bitx[MAXN / 62 + 1], bity[MAXN / 62 + 1];
ll pw[64];
char str[MAXN];

int process(ll *bit) {
	//bit[0] = 2305843009213693952ll;
	scanf("%s", str);
	int n = strlen(str);
	int ret = 1;
	for (int i = 0; i < n; i++) {
		if (str[i] == '1') // add a 0 to the end
			bit[ret / 62] &= 4611686018427387903ll ^ pw[ret % 62];
		if (str[i] == '2') // add a 1 to the end
			bit[ret / 62] |= pw[ret % 62];
		if (str[i] == '1' || str[i] == '2')
			ret++;
		if (str[i] == 'L') { // go left
			ret--;
			bit[ret / 62] -= pw[ret % 62];
			for (int i = ret / 62; bit[i] < 0; i--) {
				bit[i] += 4611686018427387904ll;
				bit[i-1]--;
			}
			ret++;
		}
		if (str[i] == 'R') { // go right
			ret--;
			bit[ret / 62] += pw[ret % 62];
			for (int i = ret / 62; bit[i] > 4611686018427387903ll; i--) {
				bit[i] -= 4611686018427387904ll;
				bit[i-1]++;
			}
			ret++;
		}
		if (str[i] == 'U')
			ret--;
	}
	return ret;
}

int main() {
	for (ll i = 0; i < 62; i++)
		pw[i] = (1ll << (61ll-i));
	int n = process(bitx);
	int m = process(bity);
	int cur = 0, ans = INF;
	for (int i = 0; i < min(n, m) && abs(cur) <= ans; i++) {
		cur = 2 * cur + ((bitx[i / 62] & pw[i % 62]) > 0) - ((bity[i / 62] & pw[i % 62]) > 0);
		ans = min(ans, abs(cur) + n + m - 2 * (i+1));
	}
	pri(ans);
    return 0;
}

Compilation message

board.cpp: In function 'int process(ll*)':
board.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", str);
  ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 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 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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 252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 6 ms 632 KB Output is correct
3 Correct 4 ms 632 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 44 ms 632 KB Output is correct
2 Correct 45 ms 680 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 632 KB Output is correct
2 Correct 44 ms 760 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 106 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 632 KB Output is correct
2 Correct 44 ms 632 KB Output is correct
3 Correct 24 ms 608 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 108 ms 672 KB Output is correct